-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcycle_detection_base_bdd_test.go
More file actions
210 lines (167 loc) · 5.6 KB
/
cycle_detection_base_bdd_test.go
File metadata and controls
210 lines (167 loc) · 5.6 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
package modular
import (
"fmt"
"strings"
)
// EnhancedCycleDetectionBDDTestContext holds the test context for cycle detection BDD scenarios
type EnhancedCycleDetectionBDDTestContext struct {
app Application
modules map[string]Module
lastError error
initializeResult error
cycleDetected bool
}
// Test interfaces for cycle detection scenarios
type TestInterfaceA interface {
MethodA() string
}
type TestInterfaceB interface {
MethodB() string
}
type TestInterfaceC interface {
MethodC() string
}
// Similar interfaces for name disambiguation testing
type EnhancedTestInterface interface {
TestMethod() string
}
type AnotherEnhancedTestInterface interface {
AnotherTestMethod() string
}
// TestInterfaceAImpl implements TestInterfaceA for self-dependency testing
type TestInterfaceAImpl struct {
name string
}
func (t *TestInterfaceAImpl) MethodA() string {
return t.name
}
// TestInterfaceBImpl implements TestInterfaceB
type TestInterfaceBImpl struct {
name string
}
func (t *TestInterfaceBImpl) MethodB() string {
return t.name
}
// TestInterfaceCImpl implements TestInterfaceC
type TestInterfaceCImpl struct {
name string
}
func (t *TestInterfaceCImpl) MethodC() string {
return t.name
}
// EnhancedTestInterfaceImpl implements EnhancedTestInterface
type EnhancedTestInterfaceImpl struct {
name string
}
func (t *EnhancedTestInterfaceImpl) TestMethod() string {
return t.name
}
// AnotherEnhancedTestInterfaceImpl implements AnotherEnhancedTestInterface
type AnotherEnhancedTestInterfaceImpl struct {
name string
}
func (t *AnotherEnhancedTestInterfaceImpl) AnotherTestMethod() string {
return t.name
}
// BDD Step implementations
func (ctx *EnhancedCycleDetectionBDDTestContext) iHaveAModularApplication() error {
app, err := NewApplication(
WithLogger(&testLogger{}),
WithConfigProvider(NewStdConfigProvider(testCfg{Str: "test"})),
)
if err != nil {
return err
}
ctx.app = app
ctx.modules = make(map[string]Module)
return nil
}
func (ctx *EnhancedCycleDetectionBDDTestContext) iTryToInitializeTheApplication() error {
ctx.initializeResult = ctx.app.Init()
return nil
}
func (ctx *EnhancedCycleDetectionBDDTestContext) theInitializationShouldFailWithACircularDependencyError() error {
if ctx.initializeResult == nil {
return fmt.Errorf("expected initialization to fail with circular dependency error, but it succeeded")
}
if !IsErrCircularDependency(ctx.initializeResult) {
return fmt.Errorf("expected ErrCircularDependency, got %T: %v", ctx.initializeResult, ctx.initializeResult)
}
ctx.cycleDetected = true
return nil
}
func (ctx *EnhancedCycleDetectionBDDTestContext) theErrorMessageShouldIncludeBothModuleNames() error {
if ctx.initializeResult == nil {
return fmt.Errorf("no error to check")
}
errorMsg := ctx.initializeResult.Error()
if !strings.Contains(errorMsg, "moduleA") || !strings.Contains(errorMsg, "moduleB") {
return fmt.Errorf("error message should contain both module names, got: %s", errorMsg)
}
return nil
}
func (ctx *EnhancedCycleDetectionBDDTestContext) theErrorMessageShouldIndicateInterfaceBasedDependencies() error {
if ctx.initializeResult == nil {
return fmt.Errorf("no error to check")
}
errorMsg := ctx.initializeResult.Error()
if !strings.Contains(errorMsg, "interface:") {
return fmt.Errorf("error message should indicate interface-based dependencies, got: %s", errorMsg)
}
return nil
}
func (ctx *EnhancedCycleDetectionBDDTestContext) theErrorMessageShouldShowTheCompleteDependencyCycle() error {
if ctx.initializeResult == nil {
return fmt.Errorf("no error to check")
}
errorMsg := ctx.initializeResult.Error()
if !strings.Contains(errorMsg, "cycle:") {
return fmt.Errorf("error message should show complete cycle, got: %s", errorMsg)
}
// Check for arrow notation indicating dependency flow
if !strings.Contains(errorMsg, "→") {
return fmt.Errorf("error message should use arrow notation for dependency flow, got: %s", errorMsg)
}
return nil
}
func (ctx *EnhancedCycleDetectionBDDTestContext) theErrorMessageShouldContain(expectedMsg string) error {
if ctx.initializeResult == nil {
return fmt.Errorf("no error to check")
}
errorMsg := ctx.initializeResult.Error()
// The exact format might vary, so let's check for key components
requiredComponents := []string{"cycle:", "moduleA", "moduleB", "interface:", "TestInterface"}
for _, component := range requiredComponents {
if !strings.Contains(errorMsg, component) {
return fmt.Errorf("error message should contain '%s', got: %s", component, errorMsg)
}
}
return nil
}
func (ctx *EnhancedCycleDetectionBDDTestContext) theErrorMessageShouldClearlyShowTheInterfaceCausingTheCycle() error {
if ctx.initializeResult == nil {
return fmt.Errorf("no error to check")
}
errorMsg := ctx.initializeResult.Error()
// Look for interface specification in the error message
if !strings.Contains(errorMsg, "TestInterface") {
return fmt.Errorf("error message should clearly show TestInterface causing the cycle, got: %s", errorMsg)
}
return nil
}
func (ctx *EnhancedCycleDetectionBDDTestContext) iInitializeTheApplication() error {
ctx.initializeResult = ctx.app.Init()
return nil
}
func (ctx *EnhancedCycleDetectionBDDTestContext) theInitializationShouldSucceed() error {
if ctx.initializeResult != nil {
return fmt.Errorf("expected initialization to succeed, got error: %v", ctx.initializeResult)
}
return nil
}
func (ctx *EnhancedCycleDetectionBDDTestContext) noCircularDependencyErrorShouldBeReported() error {
if IsErrCircularDependency(ctx.initializeResult) {
return fmt.Errorf("unexpected circular dependency error: %v", ctx.initializeResult)
}
return nil
}