changed adapter test case
created test folder to add test config and use it in adapter test cases.
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"flag"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -99,18 +100,17 @@ func TestMainFunction(t *testing.T) {
|
||||
main()
|
||||
}
|
||||
|
||||
// TestRunSuccess tests the successful execution of the run function with different configurations.
|
||||
func TestRunSuccess(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
configData string
|
||||
configPath string
|
||||
mockMgr func() (*plugin.Manager, func(), error)
|
||||
mockLogger func(cfg *Config) error
|
||||
mockServer func(ctx context.Context, mgr handler.PluginManager, cfg *Config) (http.Handler, error)
|
||||
}{
|
||||
{
|
||||
name: "Valid Config",
|
||||
configData: "valid_config.yaml",
|
||||
configPath: "../test/validConfig.yaml",
|
||||
mockMgr: func() (*plugin.Manager, func(), error) {
|
||||
return &plugin.Manager{}, func() {}, nil
|
||||
},
|
||||
@@ -128,51 +128,6 @@ func TestRunSuccess(t *testing.T) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
||||
defer cancel()
|
||||
|
||||
testFilePath := tt.configData
|
||||
mockConfig := `appName: "testAdapter"
|
||||
log:
|
||||
level: debug
|
||||
destinations:
|
||||
- type: stdout
|
||||
context_keys:
|
||||
- transaction_id
|
||||
- message_id
|
||||
http:
|
||||
port: 8080
|
||||
timeout:
|
||||
read: 30
|
||||
write: 30
|
||||
idle: 30
|
||||
plugin:
|
||||
root: "/mock/plugins"
|
||||
pluginZipPath: "/mock/plugins/plugins_bundle.zip"
|
||||
plugins:
|
||||
- testPlugin1
|
||||
- testPlugin2
|
||||
modules:
|
||||
- name: testModule
|
||||
type: transaction
|
||||
path: /testPath
|
||||
targetType: msgQ
|
||||
plugin:
|
||||
schemaValidator:
|
||||
id: testValidator
|
||||
publisher:
|
||||
id: testPublisher
|
||||
config:
|
||||
project: test-project
|
||||
topic: test-topic
|
||||
router:
|
||||
id: testRouter
|
||||
config:
|
||||
routingConfigPath: "/mock/configs/testRouting-config.yaml"`
|
||||
|
||||
err := os.WriteFile(testFilePath, []byte(mockConfig), 0644)
|
||||
if err != nil {
|
||||
t.Errorf("Failed to create test config file: %v", err)
|
||||
}
|
||||
defer os.Remove(testFilePath)
|
||||
|
||||
// Mock dependencies
|
||||
originalNewManager := newManagerFunc
|
||||
newManagerFunc = func(ctx context.Context, cfg *plugin.ManagerConfig) (*plugin.Manager, func(), error) {
|
||||
@@ -186,9 +141,8 @@ modules:
|
||||
}
|
||||
defer func() { newServerFunc = originalNewServer }()
|
||||
|
||||
// Run function
|
||||
err = run(ctx, testFilePath)
|
||||
if err != nil {
|
||||
// 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)
|
||||
}
|
||||
})
|
||||
|
||||
41
cmd/test/validConfig.yaml
Normal file
41
cmd/test/validConfig.yaml
Normal file
@@ -0,0 +1,41 @@
|
||||
appName: "testAdapter"
|
||||
|
||||
log:
|
||||
level: debug
|
||||
destinations:
|
||||
- type: stdout
|
||||
context_keys:
|
||||
- transaction_id
|
||||
- message_id
|
||||
|
||||
http:
|
||||
port: 8080
|
||||
timeout:
|
||||
read: 30
|
||||
write: 30
|
||||
idle: 30
|
||||
|
||||
plugin:
|
||||
root: "/mock/plugins"
|
||||
pluginZipPath: "/mock/plugins/plugins_bundle.zip"
|
||||
plugins:
|
||||
- testPlugin1
|
||||
- testPlugin2
|
||||
|
||||
modules:
|
||||
- name: testModule
|
||||
type: transaction
|
||||
path: /testPath
|
||||
targetType: msgQ
|
||||
plugin:
|
||||
schemaValidator:
|
||||
id: testValidator
|
||||
publisher:
|
||||
id: testPublisher
|
||||
config:
|
||||
project: test-project
|
||||
topic: test-topic
|
||||
router:
|
||||
id: testRouter
|
||||
config:
|
||||
routingConfigPath: "/mock/configs/testRouting-config.yaml"
|
||||
Reference in New Issue
Block a user