Review comments resolved

This commit is contained in:
MohitKatare-protean
2025-04-11 15:46:06 +05:30
parent 5b32a51682
commit 2f033d28ad
2 changed files with 17 additions and 46 deletions

View File

@@ -101,51 +101,26 @@ func TestMainFunction(t *testing.T) {
} }
func TestRunSuccess(t *testing.T) { func TestRunSuccess(t *testing.T) {
tests := []struct { ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
name string defer cancel()
configPath string
mockMgr func() (*plugin.Manager, func(), error) configPath := "../test/validConfig.yaml"
mockLogger func(cfg *Config) error
mockServer func(ctx context.Context, mgr handler.PluginManager, cfg *Config) (http.Handler, error) // Mock dependencies
}{ originalNewManager := newManagerFunc
{ newManagerFunc = func(ctx context.Context, cfg *plugin.ManagerConfig) (*plugin.Manager, func(), error) {
name: "Valid Config", return &plugin.Manager{}, func() {}, nil
configPath: "../test/validConfig.yaml",
mockMgr: func() (*plugin.Manager, func(), error) {
return &plugin.Manager{}, func() {}, nil
},
mockLogger: func(cfg *Config) error {
return nil
},
mockServer: func(ctx context.Context, mgr handler.PluginManager, cfg *Config) (http.Handler, error) {
return http.NewServeMux(), nil
},
},
} }
defer func() { newManagerFunc = originalNewManager }()
for _, tt := range tests { originalNewServer := newServerFunc
t.Run(tt.name, func(t *testing.T) { newServerFunc = func(ctx context.Context, mgr handler.PluginManager, cfg *Config) (http.Handler, error) {
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second) return http.NewServeMux(), nil
defer cancel() }
defer func() { newServerFunc = originalNewServer }()
// Mock dependencies if err := run(ctx, filepath.Clean(configPath)); err != nil {
originalNewManager := newManagerFunc t.Errorf("Expected no error, but got: %v", err)
newManagerFunc = func(ctx context.Context, cfg *plugin.ManagerConfig) (*plugin.Manager, func(), error) {
return tt.mockMgr()
}
defer func() { newManagerFunc = originalNewManager }()
originalNewServer := newServerFunc
newServerFunc = func(ctx context.Context, mgr handler.PluginManager, cfg *Config) (http.Handler, error) {
return tt.mockServer(ctx, mgr, cfg)
}
defer func() { newServerFunc = originalNewServer }()
// Run the app using static config file
if err := run(ctx, filepath.Clean(tt.configPath)); err != nil {
t.Errorf("Expected no error, but got: %v", err)
}
})
} }
} }

View File

@@ -1,5 +1,4 @@
appName: "testAdapter" appName: "testAdapter"
log: log:
level: debug level: debug
destinations: destinations:
@@ -7,21 +6,18 @@ log:
context_keys: context_keys:
- transaction_id - transaction_id
- message_id - message_id
http: http:
port: 8080 port: 8080
timeout: timeout:
read: 30 read: 30
write: 30 write: 30
idle: 30 idle: 30
plugin: plugin:
root: "/mock/plugins" root: "/mock/plugins"
pluginZipPath: "/mock/plugins/plugins_bundle.zip" pluginZipPath: "/mock/plugins/plugins_bundle.zip"
plugins: plugins:
- testPlugin1 - testPlugin1
- testPlugin2 - testPlugin2
modules: modules:
- name: testModule - name: testModule
type: transaction type: transaction