diff --git a/cmd/observe/agent_events_test.go b/cmd/observe/agent_events_test.go index 2fd31a294..dbbcee233 100644 --- a/cmd/observe/agent_events_test.go +++ b/cmd/observe/agent_events_test.go @@ -40,16 +40,16 @@ func Test_getAgentEventsRequest(t *testing.T) { selectorOpts.since = "" selectorOpts.until = "" req, err := getAgentEventsRequest() - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, &observerpb.GetAgentEventsRequest{Number: defaults.EventsPrintCount}, req) selectorOpts.since = "2021-04-26T00:00:00Z" selectorOpts.until = "2021-04-26T00:01:00Z" req, err = getAgentEventsRequest() - assert.NoError(t, err) + require.NoError(t, err) since, err := time.Parse(time.RFC3339, selectorOpts.since) - assert.NoError(t, err) + require.NoError(t, err) until, err := time.Parse(time.RFC3339, selectorOpts.until) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, &observerpb.GetAgentEventsRequest{ Number: defaults.EventsPrintCount, Since: timestamppb.New(since), @@ -61,14 +61,13 @@ func Test_getAgentEventsRequestWithoutSince(t *testing.T) { selectorOpts.since = "" selectorOpts.until = "" req, err := getAgentEventsRequest() - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, &observerpb.GetAgentEventsRequest{Number: defaults.EventsPrintCount}, req) selectorOpts.until = "2021-04-26T00:01:00Z" req, err = getAgentEventsRequest() - assert.NoError(t, err) - assert.NoError(t, err) + require.NoError(t, err) until, err := time.Parse(time.RFC3339, selectorOpts.until) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, &observerpb.GetAgentEventsRequest{ Number: defaults.EventsPrintCount, Until: timestamppb.New(until), diff --git a/cmd/observe/debug_events_test.go b/cmd/observe/debug_events_test.go index 649e01007..72e212a23 100644 --- a/cmd/observe/debug_events_test.go +++ b/cmd/observe/debug_events_test.go @@ -10,6 +10,7 @@ import ( observerpb "github.com/cilium/cilium/api/v1/observer" "github.com/cilium/hubble/pkg/defaults" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "google.golang.org/protobuf/types/known/timestamppb" ) @@ -17,16 +18,16 @@ func Test_getDebugEventsRequest(t *testing.T) { selectorOpts.since = "" selectorOpts.until = "" req, err := getDebugEventsRequest() - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, &observerpb.GetDebugEventsRequest{Number: defaults.EventsPrintCount}, req) selectorOpts.since = "2021-04-26T01:00:00Z" selectorOpts.until = "2021-04-26T01:01:00Z" req, err = getDebugEventsRequest() - assert.NoError(t, err) + require.NoError(t, err) since, err := time.Parse(time.RFC3339, selectorOpts.since) - assert.NoError(t, err) + require.NoError(t, err) until, err := time.Parse(time.RFC3339, selectorOpts.until) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, &observerpb.GetDebugEventsRequest{ Number: defaults.EventsPrintCount, Since: timestamppb.New(since), @@ -38,13 +39,13 @@ func Test_getDebugEventsRequestWithoutSince(t *testing.T) { selectorOpts.since = "" selectorOpts.until = "" req, err := getDebugEventsRequest() - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, &observerpb.GetDebugEventsRequest{Number: defaults.EventsPrintCount}, req) selectorOpts.until = "2021-04-26T01:01:00Z" req, err = getDebugEventsRequest() - assert.NoError(t, err) + require.NoError(t, err) until, err := time.Parse(time.RFC3339, selectorOpts.until) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, &observerpb.GetDebugEventsRequest{ Number: defaults.EventsPrintCount, Until: timestamppb.New(until), diff --git a/cmd/observe/flows_filter_test.go b/cmd/observe/flows_filter_test.go index 6955eea6c..818067810 100644 --- a/cmd/observe/flows_filter_test.go +++ b/cmd/observe/flows_filter_test.go @@ -567,9 +567,9 @@ func TestTrafficDirection(t *testing.T) { t.Errorf("mismatch (-want +got):\n%s", diff) } if tc.err != "" { - assert.Errorf(t, err, tc.err) + require.Errorf(t, err, tc.err) } else { - assert.NoError(t, err) + require.NoError(t, err) } assert.Nil(t, f.blacklist) }) diff --git a/cmd/observe/flows_test.go b/cmd/observe/flows_test.go index 9becf37bb..aada85508 100644 --- a/cmd/observe/flows_test.go +++ b/cmd/observe/flows_test.go @@ -45,16 +45,16 @@ func Test_getFlowsRequest(t *testing.T) { selectorOpts.until = "" filter := newFlowFilter() req, err := getFlowsRequest(filter, nil, nil) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, &observerpb.GetFlowsRequest{Number: defaults.FlowPrintCount}, req) selectorOpts.since = "2021-03-23T00:00:00Z" selectorOpts.until = "2021-03-24T00:00:00Z" req, err = getFlowsRequest(filter, nil, nil) - assert.NoError(t, err) + require.NoError(t, err) since, err := time.Parse(time.RFC3339, selectorOpts.since) - assert.NoError(t, err) + require.NoError(t, err) until, err := time.Parse(time.RFC3339, selectorOpts.until) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, &observerpb.GetFlowsRequest{ Number: defaults.FlowPrintCount, Since: timestamppb.New(since), @@ -67,13 +67,13 @@ func Test_getFlowsRequestWithoutSince(t *testing.T) { selectorOpts.until = "" filter := newFlowFilter() req, err := getFlowsRequest(filter, nil, nil) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, &observerpb.GetFlowsRequest{Number: defaults.FlowPrintCount}, req) selectorOpts.until = "2021-03-24T00:00:00Z" req, err = getFlowsRequest(filter, nil, nil) - assert.NoError(t, err) + require.NoError(t, err) until, err := time.Parse(time.RFC3339, selectorOpts.until) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, &observerpb.GetFlowsRequest{ Number: defaults.FlowPrintCount, Until: timestamppb.New(until), @@ -90,16 +90,16 @@ func Test_getFlowsRequestWithRawFilters(t *testing.T) { `{"destination_label":["k8s:k8s-app=kube-dns"]}`, } req, err := getFlowsRequest(newFlowFilter(), allowlist, denylist) - assert.NoError(t, err) + require.NoError(t, err) // convert filters in the request back to JSON and check if it matches the original allowlist/denylist. var b strings.Builder err = json.NewEncoder(&b).Encode(req.GetWhitelist()) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, fmt.Sprintf("[%s]\n", strings.Join(allowlist, ",")), b.String()) b.Reset() err = json.NewEncoder(&b).Encode(req.GetBlacklist()) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, fmt.Sprintf("[%s]\n", strings.Join(denylist, ",")), b.String()) } @@ -124,7 +124,7 @@ func Test_getFlowFiltersYAML(t *testing.T) { denylist: - '{"source_port":["80"]}' ` - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, expected, out) } @@ -133,7 +133,7 @@ func Test_getFlowsRequest_ExperimentalFieldMask_valid(t *testing.T) { experimentalOpts.fieldMask = []string{"time", "verdict"} filter := newFlowFilter() req, err := getFlowsRequest(filter, nil, nil) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, &observerpb.GetFlowsRequest{ Number: 20, Experimental: &observerpb.GetFlowsRequest_Experimental{ @@ -146,7 +146,7 @@ func Test_getFlowsRequest_ExperimentalFieldMask_invalid(t *testing.T) { experimentalOpts.fieldMask = []string{"time", "verdict", "invalid-field"} filter := newFlowFilter() _, err := getFlowsRequest(filter, nil, nil) - assert.ErrorContains(t, err, "invalid-field") + require.ErrorContains(t, err, "invalid-field") } func Test_getFlowsRequest_ExperimentalUseDefaultFieldMask(t *testing.T) { @@ -157,7 +157,7 @@ func Test_getFlowsRequest_ExperimentalUseDefaultFieldMask(t *testing.T) { filter := newFlowFilter() require.NoError(t, handleFlowArgs(os.Stdout, filter, false)) req, err := getFlowsRequest(filter, nil, nil) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, &observerpb.GetFlowsRequest{ Number: 20, Experimental: &observerpb.GetFlowsRequest_Experimental{ @@ -172,7 +172,7 @@ func Test_getFlowsRequest_ExperimentalFieldMask_non_json_output(t *testing.T) { experimentalOpts.fieldMask = []string{"time", "verdict"} filter := newFlowFilter() err := handleFlowArgs(os.Stdout, filter, false) - assert.ErrorContains(t, err, "not compatible") + require.ErrorContains(t, err, "not compatible") } func Test_getFlowsRequestWithInputFile(t *testing.T) { @@ -180,12 +180,12 @@ func Test_getFlowsRequestWithInputFile(t *testing.T) { selectorOpts.last = 0 otherOpts.inputFile = "myfile" req, err := getFlowsRequest(newFlowFilter(), nil, nil) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, uint64(0), req.GetNumber()) // .. but you can explicitly specify --last flag selectorOpts.last = 42 req, err = getFlowsRequest(newFlowFilter(), nil, nil) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, uint64(42), req.GetNumber()) } diff --git a/cmd/observe/io_reader_observer_test.go b/cmd/observe/io_reader_observer_test.go index f78af928b..f85a35f78 100644 --- a/cmd/observe/io_reader_observer_test.go +++ b/cmd/observe/io_reader_observer_test.go @@ -23,16 +23,16 @@ func Test_getFlowsBasic(t *testing.T) { var flowStrings []string for _, f := range flows { b, err := f.MarshalJSON() - assert.NoError(t, err) + require.NoError(t, err) flowStrings = append(flowStrings, string(b)) } server := NewIOReaderObserver(strings.NewReader(strings.Join(flowStrings, "\n") + "\n")) req := observerpb.GetFlowsRequest{} client, err := server.GetFlows(context.Background(), &req) - assert.NoError(t, err) + require.NoError(t, err) for i := 0; i < len(flows); i++ { _, err = client.Recv() - assert.NoError(t, err) + require.NoError(t, err) } _, err = client.Recv() assert.Equal(t, io.EOF, err) @@ -56,7 +56,7 @@ func Test_getFlowsTimeRange(t *testing.T) { var flowStrings []string for _, f := range flows { b, err := f.MarshalJSON() - assert.NoError(t, err) + require.NoError(t, err) flowStrings = append(flowStrings, string(b)) } server := NewIOReaderObserver(strings.NewReader(strings.Join(flowStrings, "\n") + "\n")) @@ -65,9 +65,9 @@ func Test_getFlowsTimeRange(t *testing.T) { Until: ×tamppb.Timestamp{Seconds: 150}, } client, err := server.GetFlows(context.Background(), &req) - assert.NoError(t, err) + require.NoError(t, err) res, err := client.Recv() - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, flows[1], res) _, err = client.Recv() assert.Equal(t, io.EOF, err) @@ -91,7 +91,7 @@ func Test_getFlowsLast(t *testing.T) { var flowStrings []string for _, f := range flows { b, err := f.MarshalJSON() - assert.NoError(t, err) + require.NoError(t, err) flowStrings = append(flowStrings, string(b)) } server := NewIOReaderObserver(strings.NewReader(strings.Join(flowStrings, "\n") + "\n")) @@ -100,12 +100,12 @@ func Test_getFlowsLast(t *testing.T) { First: false, } client, err := server.GetFlows(context.Background(), &req) - assert.NoError(t, err) + require.NoError(t, err) res, err := client.Recv() - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, flows[1], res) res, err = client.Recv() - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, flows[2], res) _, err = client.Recv() assert.Equal(t, io.EOF, err) @@ -129,7 +129,7 @@ func Test_getFlowsFirst(t *testing.T) { var flowStrings []string for _, f := range flows { b, err := f.MarshalJSON() - assert.NoError(t, err) + require.NoError(t, err) flowStrings = append(flowStrings, string(b)) } server := NewIOReaderObserver(strings.NewReader(strings.Join(flowStrings, "\n") + "\n")) @@ -138,12 +138,12 @@ func Test_getFlowsFirst(t *testing.T) { First: true, } client, err := server.GetFlows(context.Background(), &req) - assert.NoError(t, err) + require.NoError(t, err) res, err := client.Recv() - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, flows[0], res) res, err = client.Recv() - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, flows[1], res) _, err = client.Recv() assert.Equal(t, io.EOF, err) @@ -167,7 +167,7 @@ func Test_getFlowsFilter(t *testing.T) { var flowStrings []string for _, f := range flows { b, err := f.MarshalJSON() - assert.NoError(t, err) + require.NoError(t, err) flowStrings = append(flowStrings, string(b)) } server := NewIOReaderObserver(strings.NewReader(strings.Join(flowStrings, "\n") + "\n")) @@ -179,12 +179,12 @@ func Test_getFlowsFilter(t *testing.T) { }, } client, err := server.GetFlows(context.Background(), &req) - assert.NoError(t, err) + require.NoError(t, err) res, err := client.Recv() - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, flows[0], res) res, err = client.Recv() - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, flows[2], res) _, err = client.Recv() assert.Equal(t, io.EOF, err) diff --git a/pkg/printer/printer_test.go b/pkg/printer/printer_test.go index d00d2c893..fe29ffa04 100644 --- a/pkg/printer/printer_test.go +++ b/pkg/printer/printer_test.go @@ -799,7 +799,7 @@ func TestHostname(t *testing.T) { func TestPrinter_AgentEventDetails(t *testing.T) { startTS := timestamppb.New(time.Now()) - assert.NoError(t, startTS.CheckValid()) + require.NoError(t, startTS.CheckValid()) tests := []struct { name string