Skip to content

Commit 6bcf85c

Browse files
jkahujaclaude
andcommitted
test: add TestBuildSource_Slack for buildSource coverage
Verifies the Slack branch in buildSource() correctly reads env vars for bot/app tokens and parses CSV CLI args for trigger command, channels, and allowed users. Towards AIE-17 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 3b15485 commit 6bcf85c

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

cmd/kelos-spawner/main_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,46 @@ func TestBuildSource_Jira(t *testing.T) {
273273
}
274274
}
275275

276+
func TestBuildSource_Slack(t *testing.T) {
277+
t.Setenv("SLACK_BOT_TOKEN", "xoxb-test-token")
278+
t.Setenv("SLACK_APP_TOKEN", "xapp-test-token")
279+
280+
ts := &kelosv1alpha1.TaskSpawner{
281+
Spec: kelosv1alpha1.TaskSpawnerSpec{
282+
When: kelosv1alpha1.When{
283+
Slack: &kelosv1alpha1.Slack{
284+
SecretRef: kelosv1alpha1.SecretReference{Name: "slack-creds"},
285+
},
286+
},
287+
},
288+
}
289+
290+
src, err := buildSource(ts, "", "", "", "", "", "", "", "/kelos", "C123,C456", "U001,U002", nil)
291+
if err != nil {
292+
t.Fatalf("Unexpected error: %v", err)
293+
}
294+
295+
slackSrc, ok := src.(*source.SlackSource)
296+
if !ok {
297+
t.Fatalf("Expected *source.SlackSource, got %T", src)
298+
}
299+
if slackSrc.BotToken != "xoxb-test-token" {
300+
t.Errorf("BotToken = %q, want %q", slackSrc.BotToken, "xoxb-test-token")
301+
}
302+
if slackSrc.AppToken != "xapp-test-token" {
303+
t.Errorf("AppToken = %q, want %q", slackSrc.AppToken, "xapp-test-token")
304+
}
305+
if slackSrc.TriggerCommand != "/kelos" {
306+
t.Errorf("TriggerCommand = %q, want %q", slackSrc.TriggerCommand, "/kelos")
307+
}
308+
if len(slackSrc.Channels) != 2 || slackSrc.Channels[0] != "C123" || slackSrc.Channels[1] != "C456" {
309+
t.Errorf("Channels = %v, want [C123 C456]", slackSrc.Channels)
310+
}
311+
if len(slackSrc.AllowedUsers) != 2 || slackSrc.AllowedUsers[0] != "U001" || slackSrc.AllowedUsers[1] != "U002" {
312+
t.Errorf("AllowedUsers = %v, want [U001 U002]", slackSrc.AllowedUsers)
313+
}
314+
}
315+
276316
func TestRunCycleWithSource_NoMaxConcurrency(t *testing.T) {
277317
ts := newTaskSpawner("spawner", "default", nil)
278318
cl, key := setupTest(t, ts)

0 commit comments

Comments
 (0)