-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmock.go
More file actions
104 lines (86 loc) · 2.69 KB
/
mock.go
File metadata and controls
104 lines (86 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// Package mock provides common mock implementations for testing
package mock
// LogLevel represents logging severity levels
type LogLevel int
const (
// These are placeholder values - adjust them according to actual requirements
LogDebug LogLevel = iota
LogInfo
LogWarning
LogError
LogFatal
)
// ConfigProvider implements a mock config provider
type ConfigProvider struct {
ConfigData map[string]any
}
// GetConfig implements the ConfigProvider interface
func (m *ConfigProvider) GetConfig() any {
return m.ConfigData
}
// UpdateConfigWithProperEnvStructure updates the configuration with proper environment structure
// This method fixes the "env: env: invalid structure" error that occurs with golobby config
func (m *ConfigProvider) UpdateConfigWithProperEnvStructure() *ConfigProvider {
// Create a completely fresh config map without any env section
m.ConfigData = map[string]any{
// Basic sections needed by workflow tests
"modules": []any{},
"workflows": map[string]any{},
}
// Important: Do NOT include any "env" field at all
// This should prevent the "env: env: invalid structure" error
return m
}
// NewConfigProvider creates a new mock config provider with proper env structure
func NewConfigProvider() *ConfigProvider {
cp := &ConfigProvider{
ConfigData: make(map[string]any),
}
return cp.UpdateConfigWithProperEnvStructure()
}
// WithWorkflow adds a workflow configuration to the mock config
func (m *ConfigProvider) WithWorkflow(name string, config map[string]any) *ConfigProvider {
if m.ConfigData == nil {
m.ConfigData = make(map[string]any)
}
// Ensure workflows section exists
if _, ok := m.ConfigData["workflows"]; !ok {
m.ConfigData["workflows"] = make(map[string]any)
}
workflows := m.ConfigData["workflows"].(map[string]any)
// Add the workflow config under its name
workflows[name] = config
return m
}
// Logger implements a mock logger
type Logger struct {
LogEntries []string
}
// Debug implements the Logger interface
func (m *Logger) Debug(msg string, args ...any) {
if m.LogEntries == nil {
m.LogEntries = make([]string, 0)
}
m.LogEntries = append(m.LogEntries, msg)
}
// Info implements the Logger interface
func (m *Logger) Info(msg string, args ...any) {
if m.LogEntries == nil {
m.LogEntries = make([]string, 0)
}
m.LogEntries = append(m.LogEntries, msg)
}
// Error implements the Logger interface
func (m *Logger) Error(msg string, args ...any) {
if m.LogEntries == nil {
m.LogEntries = make([]string, 0)
}
m.LogEntries = append(m.LogEntries, msg)
}
// Warn implements the Logger interface
func (m *Logger) Warn(msg string, args ...any) {
if m.LogEntries == nil {
m.LogEntries = make([]string, 0)
}
m.LogEntries = append(m.LogEntries, msg)
}