Skip to content

Commit e8bb9da

Browse files
authored
fix configuration when webhook set in the URL (#108)
1 parent 6d5fccd commit e8bb9da

2 files changed

Lines changed: 17 additions & 29 deletions

File tree

config/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,9 @@ func (c *Config) CheckMissingResourceEnvvars() {
308308
if (c.Handler.SlackWebhook.Slackwebhookurl == "") && (os.Getenv("KW_SLACK_WEBHOOK_URL") != "") {
309309
c.Handler.SlackWebhook.Slackwebhookurl = os.Getenv("KW_SLACK_WEBHOOK_URL")
310310
}
311+
if (c.Handler.Webhook.Url == "") && (os.Getenv("KW_WEBHOOK_URL") != "") {
312+
c.Handler.Webhook.Url = os.Getenv("KW_WEBHOOK_URL")
313+
}
311314
}
312315

313316
func (c *Config) Write() error {

config/config_test.go

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ package config
1818

1919
import (
2020
//"io/ioutil"
21-
//"os"
22-
//"testing"
21+
"os"
22+
"testing"
2323
)
2424

2525
var configStr = `
@@ -48,30 +48,15 @@ var configStr = `
4848
}
4949
`
5050

51-
//func TestLoadOK(t *testing.T) {
52-
// content := []byte(configStr)
53-
// tmpConfigFile, err := ioutil.TempFile(homeDir(), "kubewatch")
54-
// if err != nil {
55-
// t.Fatalf("TestLoad(): %+v", err)
56-
// }
57-
//
58-
// defer func() {
59-
// _ = os.Remove(tmpConfigFile.Name())
60-
// }()
61-
//
62-
// if _, err := tmpConfigFile.Write(content); err != nil {
63-
// t.Fatalf("TestLoad(): %+v", err)
64-
// }
65-
// if err := tmpConfigFile.Close(); err != nil {
66-
// t.Fatalf("TestLoad(): %+v", err)
67-
// }
68-
//
69-
// ConfigFileName = "kubewatch"
70-
//
71-
// c, err := New()
72-
//
73-
// err = c.Load()
74-
// if err != nil {
75-
// t.Fatalf("TestLoad(): %+v", err)
76-
// }
77-
//}
51+
func TestCheckMissingResourceEnvvars_Webhook(t *testing.T) {
52+
expectedURL := "http://example.com/webhook"
53+
os.Setenv("KW_WEBHOOK_URL", expectedURL)
54+
defer os.Unsetenv("KW_WEBHOOK_URL")
55+
56+
c := &Config{}
57+
c.CheckMissingResourceEnvvars()
58+
59+
if c.Handler.Webhook.Url != expectedURL {
60+
t.Errorf("Expected Webhook URL to be %q, but got %q", expectedURL, c.Handler.Webhook.Url)
61+
}
62+
}

0 commit comments

Comments
 (0)