yaml format changes
This commit is contained in:
@@ -32,44 +32,21 @@ func setupTestConfig(t *testing.T) string {
|
|||||||
return tempPath
|
return tempPath
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestRouterProviderSuccess tests the RouterProvider implementation for success cases.
|
// TestRouterProviderSuccess tests successful router creation.
|
||||||
func TestRouterProviderSuccess(t *testing.T) {
|
func TestRouterProviderSuccess(t *testing.T) {
|
||||||
rulesFilePath := setupTestConfig(t)
|
rulesFilePath := setupTestConfig(t)
|
||||||
defer os.RemoveAll(filepath.Dir(rulesFilePath))
|
defer os.RemoveAll(filepath.Dir(rulesFilePath))
|
||||||
|
|
||||||
// Define test cases
|
provider := RouterProvider{}
|
||||||
tests := []struct {
|
router, _, err := provider.New(context.Background(), map[string]string{
|
||||||
name string
|
"routingConfig": rulesFilePath,
|
||||||
ctx context.Context
|
})
|
||||||
config map[string]string
|
|
||||||
wantErr bool
|
if err != nil {
|
||||||
}{
|
t.Fatalf("New() unexpected error: %v", err)
|
||||||
{
|
|
||||||
name: "Valid configuration",
|
|
||||||
ctx: context.Background(),
|
|
||||||
config: map[string]string{
|
|
||||||
"routingConfig": rulesFilePath,
|
|
||||||
},
|
|
||||||
wantErr: false,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
if router == nil {
|
||||||
for _, tt := range tests {
|
t.Error("New() returned nil router, want non-nil")
|
||||||
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)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,8 +91,9 @@ func TestRouterProviderFailure(t *testing.T) {
|
|||||||
|
|
||||||
// Check for expected error
|
// Check for expected error
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Errorf("New(%v, %v) = nil error, want error containing %q", tt.ctx, tt.config, tt.wantErr)
|
t.Fatalf("New(%v, %v) = nil error, want error containing %q", tt.ctx, tt.config, tt.wantErr)
|
||||||
} else if !strings.Contains(err.Error(), 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)
|
t.Errorf("New(%v, %v) = %v, want error containing %q", tt.ctx, tt.config, err, tt.wantErr)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,23 +1,23 @@
|
|||||||
routingRules:
|
routingRules:
|
||||||
- domain: "ONDC:TRV10"
|
- domain: ONDC:TRV10
|
||||||
version: "2.0.0"
|
version: 2.0.0
|
||||||
targetType: "bpp"
|
targetType: bpp
|
||||||
target:
|
target:
|
||||||
url: "https://gateway.example.com"
|
url: https://gateway.example.com
|
||||||
endpoints:
|
endpoints:
|
||||||
- search
|
- search
|
||||||
- domain: "ONDC:TRV10"
|
- domain: ONDC:TRV10
|
||||||
version: "2.0.0"
|
version: 2.0.0
|
||||||
targetType: "bpp"
|
targetType: bpp
|
||||||
endpoints:
|
endpoints:
|
||||||
- select
|
- select
|
||||||
- init
|
- init
|
||||||
- confirm
|
- confirm
|
||||||
- status
|
- status
|
||||||
- cancel
|
- cancel
|
||||||
- domain: "ONDC:TRV12"
|
- domain: ONDC:TRV12
|
||||||
version: "2.0.0"
|
version: 2.0.0
|
||||||
targetType: "bpp"
|
targetType: bpp
|
||||||
endpoints:
|
endpoints:
|
||||||
- select
|
- select
|
||||||
- init
|
- init
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
routingRules:
|
routingRules:
|
||||||
- domain: "ONDC:TRV10"
|
- domain: ONDC:TRV10
|
||||||
version: "2.0.0"
|
version: 2.0.0
|
||||||
targetType: "url"
|
targetType: url
|
||||||
target:
|
target:
|
||||||
url: "https://services-backend/trv/v1"
|
url: https://services-backend/trv/v1
|
||||||
endpoints:
|
endpoints:
|
||||||
- on_select
|
- on_select
|
||||||
- on_init
|
- on_init
|
||||||
@@ -11,10 +11,10 @@ routingRules:
|
|||||||
- on_status
|
- on_status
|
||||||
- on_update
|
- on_update
|
||||||
- on_cancel
|
- on_cancel
|
||||||
- domain: "ONDC:TRV10"
|
- domain: ONDC:TRV10
|
||||||
version: "2.0.0"
|
version: 2.0.0
|
||||||
targetType: "publisher"
|
targetType: publisher
|
||||||
target:
|
target:
|
||||||
publisherId: "trv_topic_id1"
|
publisherId: trv_topic_id1
|
||||||
endpoints:
|
endpoints:
|
||||||
- on_search
|
- on_search
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
routingRules:
|
routingRules:
|
||||||
- domain: "ONDC:TRV10"
|
- domain: ONDC:TRV10
|
||||||
version: "2.0.0"
|
version: 2.0.0
|
||||||
targetType: "bap"
|
targetType: bap
|
||||||
endpoints:
|
endpoints:
|
||||||
- on_search
|
- on_search
|
||||||
- on_select
|
- on_select
|
||||||
@@ -10,9 +10,9 @@ routingRules:
|
|||||||
- on_status
|
- on_status
|
||||||
- on_update
|
- on_update
|
||||||
- on_cancel
|
- on_cancel
|
||||||
- domain: "ONDC:TRV11"
|
- domain: ONDC:TRV11
|
||||||
version: "2.0.0"
|
version: 2.0.0
|
||||||
targetType: "bap"
|
targetType: bap
|
||||||
endpoints:
|
endpoints:
|
||||||
- on_search
|
- on_search
|
||||||
- on_select
|
- on_select
|
||||||
|
|||||||
@@ -1,27 +1,27 @@
|
|||||||
routingRules:
|
routingRules:
|
||||||
- domain: "ONDC:TRV10"
|
- domain: ONDC:TRV10
|
||||||
version: "2.0.0"
|
version: 2.0.0
|
||||||
targetType: "url"
|
targetType: url
|
||||||
target:
|
target:
|
||||||
url: "https://services-backend/trv/v1"
|
url: https://services-backend/trv/v1
|
||||||
endpoints:
|
endpoints:
|
||||||
- select
|
- select
|
||||||
- init
|
- init
|
||||||
- confirm
|
- confirm
|
||||||
- status
|
- status
|
||||||
- cancel
|
- cancel
|
||||||
- domain: "ONDC:TRV10"
|
- domain: ONDC:TRV10
|
||||||
version: "2.0.0"
|
version: 2.0.0
|
||||||
targetType: "publisher"
|
targetType: publisher
|
||||||
target:
|
target:
|
||||||
publisherId: "trv_topic_id1"
|
publisherId: trv_topic_id1
|
||||||
endpoints:
|
endpoints:
|
||||||
- search
|
- search
|
||||||
- domain: "ONDC:TRV11"
|
- domain: ONDC:TRV11
|
||||||
version: "2.0.0"
|
version: 2.0.0
|
||||||
targetType: "url"
|
targetType: url
|
||||||
target:
|
target:
|
||||||
url: "https://services-backend/trv/v1"
|
url: https://services-backend/trv/v1
|
||||||
endpoints:
|
endpoints:
|
||||||
- select
|
- select
|
||||||
- init
|
- init
|
||||||
|
|||||||
Reference in New Issue
Block a user