From 87c933a67034b46f2686f0368cdb59484e1e5ee5 Mon Sep 17 00:00:00 2001 From: Navendu Pottekkat Date: Sun, 7 Jan 2024 11:26:06 +0530 Subject: [PATCH] better error messages for failed tests Signed-off-by: Navendu Pottekkat --- pkg/i2gw/providers/apisix/apisix.go | 2 +- pkg/i2gw/providers/apisix/http_to_https_test.go | 8 ++++---- pkg/i2gw/providers/apisix/resource_reader.go | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/i2gw/providers/apisix/apisix.go b/pkg/i2gw/providers/apisix/apisix.go index 9422b735..82c562f5 100644 --- a/pkg/i2gw/providers/apisix/apisix.go +++ b/pkg/i2gw/providers/apisix/apisix.go @@ -65,7 +65,7 @@ func (p *Provider) ReadResourcesFromCluster(ctx context.Context) error { } func (p *Provider) ReadResourcesFromFile(ctx context.Context, filename string) error { - storage, err := p.resourceReader.readResourcesFromFile(ctx, filename) + storage, err := p.resourceReader.readResourcesFromFile(filename) if err != nil { return fmt.Errorf("failed to read resources from file: %w", err) } diff --git a/pkg/i2gw/providers/apisix/http_to_https_test.go b/pkg/i2gw/providers/apisix/http_to_https_test.go index 5e27e201..72c877c4 100644 --- a/pkg/i2gw/providers/apisix/http_to_https_test.go +++ b/pkg/i2gw/providers/apisix/http_to_https_test.go @@ -31,7 +31,7 @@ import ( gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" ) -func Test_httpToHttps(t *testing.T) { +func Test_httpToHttpsFeature(t *testing.T) { testCases := []struct { name string ingress networkingv1.Ingress @@ -269,18 +269,18 @@ func Test_httpToHttps(t *testing.T) { errs := httpToHttpsFeature(ingressResources, gatewayResources) if len(errs) != len(tc.expectedError) { - t.Fatalf("expected %d errors, got %d", len(tc.expectedError), len(errs)) + t.Errorf("expected %d errors, got %d", len(tc.expectedError), len(errs)) } key := types.NamespacedName{Namespace: tc.ingress.Namespace, Name: common.RouteName(tc.ingress.Name, tc.ingress.Spec.Rules[0].Host)} actualHTTPRoute, ok := gatewayResources.HTTPRoutes[key] if !ok { - t.Fatalf("HTTPRoute not found: %v", key) + t.Errorf("HTTPRoute not found: %v", key) } if diff := cmp.Diff(*tc.expectedHTTPRoute, actualHTTPRoute); diff != "" { - t.Fatalf("mismatch (-want +got):\n%s", diff) + t.Errorf("Unexpected HTTPRoute resource found, \n want: %+v\n got: %+v\n diff (-want +got):\n%s", *tc.expectedHTTPRoute, actualHTTPRoute, diff) } }) } diff --git a/pkg/i2gw/providers/apisix/resource_reader.go b/pkg/i2gw/providers/apisix/resource_reader.go index b6f77c37..24bd51fa 100644 --- a/pkg/i2gw/providers/apisix/resource_reader.go +++ b/pkg/i2gw/providers/apisix/resource_reader.go @@ -47,7 +47,7 @@ func (r *resourceReader) readResourcesFromCluster(ctx context.Context) (*storage return storage, nil } -func (r *resourceReader) readResourcesFromFile(_ context.Context, filename string) (*storage, error) { +func (r *resourceReader) readResourcesFromFile(filename string) (*storage, error) { // read apisix related resources from file. storage := newResourcesStorage()