Skip to content

Commit

Permalink
Add tests for hooks template loading
Browse files Browse the repository at this point in the history
  • Loading branch information
moorereason committed Nov 8, 2017
1 parent c3e6516 commit b4cb248
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion hook/hook_test.go
Expand Up @@ -244,7 +244,9 @@ var hooksLoadFromFileTests = []struct {
}

func TestHooksLoadFromFile(t *testing.T) {
os.Setenv("XXXTEST_SECRET", `foo"123`)
secret := `foo"123`
os.Setenv("XXXTEST_SECRET", secret)

for _, tt := range hooksLoadFromFileTests {
h := &Hooks{}
err := h.LoadFromFile(tt.path, tt.asTemplate)
Expand All @@ -254,6 +256,29 @@ func TestHooksLoadFromFile(t *testing.T) {
}
}

func TestHooksTemplateLoadFromFile(t *testing.T) {
secret := `foo"123`
os.Setenv("XXXTEST_SECRET", secret)

for _, tt := range hooksLoadFromFileTests {
if !tt.asTemplate {
continue
}

h := &Hooks{}
err := h.LoadFromFile(tt.path, tt.asTemplate)
if (err == nil) != tt.ok {
t.Errorf(err.Error())
continue
}

s := (*h.Match("webhook").TriggerRule.And)[0].Match.Secret
if s != secret {
t.Errorf("Expected secret of %q, got %q", secret, s)
}
}
}

var hooksMatchTests = []struct {
id string
hooks Hooks
Expand Down

0 comments on commit b4cb248

Please sign in to comment.