fix: error msg change, t.helper
This commit is contained in:
@@ -29,7 +29,7 @@ type Manager struct {
|
||||
|
||||
func validateMgrCfg(cfg *ManagerConfig) error {
|
||||
if cfg.Root == "" {
|
||||
return fmt.Errorf("Root path cannot be empty")
|
||||
return fmt.Errorf("root path cannot be empty")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -261,7 +261,8 @@ type mockRegistryLookup struct {
|
||||
}
|
||||
|
||||
// createTestZip creates a zip file with test content in a temporary directory.
|
||||
func createTestZip(t *testing.T) (string, func()) {
|
||||
func createTestZip(t *testing.T) string {
|
||||
t.Helper()
|
||||
// Create a temporary directory for the zip file
|
||||
tempDir := t.TempDir()
|
||||
zipPath := filepath.Join(tempDir, "test.zip")
|
||||
@@ -286,9 +287,7 @@ func createTestZip(t *testing.T) (string, func()) {
|
||||
t.Fatalf("Failed to write to file: %v", err)
|
||||
}
|
||||
|
||||
return zipPath, func() {
|
||||
os.RemoveAll(tempDir)
|
||||
}
|
||||
return zipPath
|
||||
}
|
||||
|
||||
// TestNewManagerSuccess tests the successful scenarios of the NewManager function.
|
||||
@@ -322,7 +321,7 @@ func TestNewManagerSuccess(t *testing.T) {
|
||||
cfg: &ManagerConfig{
|
||||
Root: t.TempDir(),
|
||||
RemoteRoot: func() string {
|
||||
zipPath, _ := createTestZip(t)
|
||||
zipPath := createTestZip(t)
|
||||
return zipPath
|
||||
}(),
|
||||
},
|
||||
@@ -377,7 +376,7 @@ func TestNewManagerFailure(t *testing.T) {
|
||||
Root: "",
|
||||
RemoteRoot: "",
|
||||
},
|
||||
expectedError: "Root path cannot be empty",
|
||||
expectedError: "root path cannot be empty",
|
||||
},
|
||||
{
|
||||
name: "invalid config with nonexistent root",
|
||||
@@ -635,38 +634,27 @@ func TestSchemaValidatorFailure(t *testing.T) {
|
||||
|
||||
// TestRouterSuccess tests the successful scenarios of the Router method.
|
||||
func TestRouterSuccess(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
cfg *Config
|
||||
plugin *mockRouterProvider
|
||||
}{
|
||||
{
|
||||
name: "successful router creation",
|
||||
cfg: &Config{
|
||||
t.Run("successful router creation", func(t *testing.T) {
|
||||
cfg := &Config{
|
||||
ID: "test-router",
|
||||
Config: map[string]string{},
|
||||
},
|
||||
plugin: &mockRouterProvider{
|
||||
}
|
||||
plugin := &mockRouterProvider{
|
||||
router: &mockRouter{},
|
||||
errFunc: func() error { return nil },
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
// Create a manager with the mock plugin.
|
||||
m := &Manager{
|
||||
plugins: map[string]onixPlugin{
|
||||
tt.cfg.ID: &mockPlugin{
|
||||
symbol: tt.plugin,
|
||||
cfg.ID: &mockPlugin{
|
||||
symbol: plugin,
|
||||
},
|
||||
},
|
||||
closers: []func(){},
|
||||
}
|
||||
|
||||
// Call Router.
|
||||
router, err := m.Router(context.Background(), tt.cfg)
|
||||
router, err := m.Router(context.Background(), cfg)
|
||||
|
||||
// Check success case.
|
||||
if err != nil {
|
||||
@@ -675,7 +663,7 @@ func TestRouterSuccess(t *testing.T) {
|
||||
if router == nil {
|
||||
t.Fatal("expected non-nil router, got nil")
|
||||
}
|
||||
if router != tt.plugin.router {
|
||||
if router != plugin.router {
|
||||
t.Fatal("router does not match expected instance")
|
||||
}
|
||||
|
||||
@@ -685,7 +673,6 @@ func TestRouterSuccess(t *testing.T) {
|
||||
|
||||
m.closers[0]()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestRouterFailure tests the failure scenarios of the Router method.
|
||||
|
||||
Reference in New Issue
Block a user