@@ -94,7 +94,48 @@ func TestGetCurrentControllerName(t *testing.T) {
94
94
args args
95
95
want string
96
96
}{
97
- // TODO: Add test cases.
97
+ {
98
+ name : "Controller name present in context" ,
99
+ args : args {
100
+ ctx : context .WithValue (context .Background (), currentControllerName , "MyTestController" ),
101
+ },
102
+ want : "MyTestController" ,
103
+ },
104
+ {
105
+ name : "Controller name not present in context" ,
106
+ args : args {
107
+ ctx : context .Background (), // Empty context
108
+ },
109
+ want : "" ,
110
+ },
111
+ {
112
+ name : "Value present but not a string" ,
113
+ args : args {
114
+ ctx : context .WithValue (context .Background (), currentControllerName , 12345 ), // Value is an int
115
+ },
116
+ want : "" , // Expect empty string as per GetCurrentControllerName logic
117
+ },
118
+ {
119
+ name : "Context with a different key (should not find ours)" ,
120
+ args : args {
121
+ ctx : context .WithValue (context .Background (), contextKey ("otherKey" ), "SomeOtherValue" ),
122
+ },
123
+ want : "" ,
124
+ },
125
+ {
126
+ name : "Context with our key and another key" ,
127
+ args : args {
128
+ ctx : context .WithValue (context .WithValue (context .Background (), contextKey ("otherKey" ), "SomeOtherValue" ), currentControllerName , "PrimaryController" ),
129
+ },
130
+ want : "PrimaryController" ,
131
+ },
132
+ {
133
+ name : "Empty string as controller name" ,
134
+ args : args {
135
+ ctx : context .WithValue (context .Background (), currentControllerName , "" ),
136
+ },
137
+ want : "" , // If an empty string is stored, it should be retrieved as such.
138
+ },
98
139
}
99
140
for _ , tt := range tests {
100
141
t .Run (tt .name , func (t * testing.T ) {
0 commit comments