From a549323dd50dcf6e7cb6d47d277b64a9168fd808 Mon Sep 17 00:00:00 2001 From: tanyamadaan Date: Fri, 28 Mar 2025 17:01:47 +0530 Subject: [PATCH] yaml format changes --- .../implementation/router/cmd/plugin_test.go | 48 +++++-------------- .../router/testData/bap_caller.yaml | 20 ++++---- .../router/testData/bap_receiver.yaml | 16 +++---- .../router/testData/bpp_caller.yaml | 12 ++--- .../router/testData/bpp_receiver.yaml | 24 +++++----- 5 files changed, 49 insertions(+), 71 deletions(-) diff --git a/pkg/plugin/implementation/router/cmd/plugin_test.go b/pkg/plugin/implementation/router/cmd/plugin_test.go index 08c9bd7..c5ffe8e 100644 --- a/pkg/plugin/implementation/router/cmd/plugin_test.go +++ b/pkg/plugin/implementation/router/cmd/plugin_test.go @@ -32,44 +32,21 @@ func setupTestConfig(t *testing.T) string { return tempPath } -// TestRouterProviderSuccess tests the RouterProvider implementation for success cases. +// TestRouterProviderSuccess tests successful router creation. func TestRouterProviderSuccess(t *testing.T) { rulesFilePath := setupTestConfig(t) defer os.RemoveAll(filepath.Dir(rulesFilePath)) - // Define test cases - tests := []struct { - name string - ctx context.Context - config map[string]string - wantErr bool - }{ - { - name: "Valid configuration", - ctx: context.Background(), - config: map[string]string{ - "routingConfig": rulesFilePath, - }, - wantErr: false, - }, + provider := RouterProvider{} + router, _, err := provider.New(context.Background(), map[string]string{ + "routingConfig": rulesFilePath, + }) + + if err != nil { + t.Fatalf("New() unexpected error: %v", err) } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - provider := RouterProvider{} - router, _, err := provider.New(tt.ctx, tt.config) - - // Ensure no error occurred - if (err != nil) != tt.wantErr { - t.Errorf("New(%v, %v) error = %v, wantErr %v", tt.ctx, tt.config, err, tt.wantErr) - return - } - - // Ensure the router and close function are not nil - if router == nil { - t.Errorf("New(%v, %v) = nil router, want non-nil", tt.ctx, tt.config) - } - }) + if router == nil { + t.Error("New() returned nil router, want non-nil") } } @@ -114,8 +91,9 @@ func TestRouterProviderFailure(t *testing.T) { // Check for expected error if err == nil { - t.Errorf("New(%v, %v) = nil error, want error containing %q", tt.ctx, tt.config, tt.wantErr) - } else if !strings.Contains(err.Error(), tt.wantErr) { + t.Fatalf("New(%v, %v) = nil error, want error containing %q", tt.ctx, tt.config, tt.wantErr) + } + if !strings.Contains(err.Error(), tt.wantErr) { t.Errorf("New(%v, %v) = %v, want error containing %q", tt.ctx, tt.config, err, tt.wantErr) } }) diff --git a/pkg/plugin/implementation/router/testData/bap_caller.yaml b/pkg/plugin/implementation/router/testData/bap_caller.yaml index 0c595a6..6a40a0f 100644 --- a/pkg/plugin/implementation/router/testData/bap_caller.yaml +++ b/pkg/plugin/implementation/router/testData/bap_caller.yaml @@ -1,23 +1,23 @@ routingRules: - - domain: "ONDC:TRV10" - version: "2.0.0" - targetType: "bpp" + - domain: ONDC:TRV10 + version: 2.0.0 + targetType: bpp target: - url: "https://gateway.example.com" + url: https://gateway.example.com endpoints: - search - - domain: "ONDC:TRV10" - version: "2.0.0" - targetType: "bpp" + - domain: ONDC:TRV10 + version: 2.0.0 + targetType: bpp endpoints: - select - init - confirm - status - cancel - - domain: "ONDC:TRV12" - version: "2.0.0" - targetType: "bpp" + - domain: ONDC:TRV12 + version: 2.0.0 + targetType: bpp endpoints: - select - init diff --git a/pkg/plugin/implementation/router/testData/bap_receiver.yaml b/pkg/plugin/implementation/router/testData/bap_receiver.yaml index af98401..17432db 100644 --- a/pkg/plugin/implementation/router/testData/bap_receiver.yaml +++ b/pkg/plugin/implementation/router/testData/bap_receiver.yaml @@ -1,9 +1,9 @@ routingRules: - - domain: "ONDC:TRV10" - version: "2.0.0" - targetType: "url" + - domain: ONDC:TRV10 + version: 2.0.0 + targetType: url target: - url: "https://services-backend/trv/v1" + url: https://services-backend/trv/v1 endpoints: - on_select - on_init @@ -11,10 +11,10 @@ routingRules: - on_status - on_update - on_cancel - - domain: "ONDC:TRV10" - version: "2.0.0" - targetType: "publisher" + - domain: ONDC:TRV10 + version: 2.0.0 + targetType: publisher target: - publisherId: "trv_topic_id1" + publisherId: trv_topic_id1 endpoints: - on_search \ No newline at end of file diff --git a/pkg/plugin/implementation/router/testData/bpp_caller.yaml b/pkg/plugin/implementation/router/testData/bpp_caller.yaml index 8d0c212..339b92d 100644 --- a/pkg/plugin/implementation/router/testData/bpp_caller.yaml +++ b/pkg/plugin/implementation/router/testData/bpp_caller.yaml @@ -1,7 +1,7 @@ routingRules: - - domain: "ONDC:TRV10" - version: "2.0.0" - targetType: "bap" + - domain: ONDC:TRV10 + version: 2.0.0 + targetType: bap endpoints: - on_search - on_select @@ -10,9 +10,9 @@ routingRules: - on_status - on_update - on_cancel - - domain: "ONDC:TRV11" - version: "2.0.0" - targetType: "bap" + - domain: ONDC:TRV11 + version: 2.0.0 + targetType: bap endpoints: - on_search - on_select diff --git a/pkg/plugin/implementation/router/testData/bpp_receiver.yaml b/pkg/plugin/implementation/router/testData/bpp_receiver.yaml index a8f668e..7355592 100644 --- a/pkg/plugin/implementation/router/testData/bpp_receiver.yaml +++ b/pkg/plugin/implementation/router/testData/bpp_receiver.yaml @@ -1,27 +1,27 @@ routingRules: - - domain: "ONDC:TRV10" - version: "2.0.0" - targetType: "url" + - domain: ONDC:TRV10 + version: 2.0.0 + targetType: url target: - url: "https://services-backend/trv/v1" + url: https://services-backend/trv/v1 endpoints: - select - init - confirm - status - cancel - - domain: "ONDC:TRV10" - version: "2.0.0" - targetType: "publisher" + - domain: ONDC:TRV10 + version: 2.0.0 + targetType: publisher target: - publisherId: "trv_topic_id1" + publisherId: trv_topic_id1 endpoints: - search - - domain: "ONDC:TRV11" - version: "2.0.0" - targetType: "url" + - domain: ONDC:TRV11 + version: 2.0.0 + targetType: url target: - url: "https://services-backend/trv/v1" + url: https://services-backend/trv/v1 endpoints: - select - init