Skip to content

Commit da83cb5

Browse files
zakiskpipelines-as-code[bot]
authored andcommitted
chore: Add test cases for GetCurrentControllerName
added test cases for func GetCurrentControllerName Signed-off-by: Zaki Shaikh <zashaikh@redhat.com>
1 parent e99fb4f commit da83cb5

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

pkg/params/info/controller_info_test.go

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,48 @@ func TestGetCurrentControllerName(t *testing.T) {
9494
args args
9595
want string
9696
}{
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+
},
98139
}
99140
for _, tt := range tests {
100141
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)