Skip to content

Commit

Permalink
Changelogs; tests; linting
Browse files Browse the repository at this point in the history
  • Loading branch information
kegsay committed May 10, 2024
1 parent 2a81fe0 commit 71a9120
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog.d/85.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for blocking specific app/version/label combinations.
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ type config struct {
GenericWebhookURLs []string `yaml:"generic_webhook_urls"`
}

// RejectionCondition contains the fields that should match a bug report for it to be rejected.
type RejectionCondition struct {
Version string `yaml:"version"`
Label string `yaml:"label"`
Expand Down
98 changes: 98 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package main

import "testing"

func TestConfigRejectionCondition(t *testing.T) {
cfg := config{
RejectionConditions: []RejectionCondition{
{
App: "my-app",
Version: "0.1.0",
},
{
App: "my-app",
Label: "0.1.1",
},
{
App: "my-app",
Version: "0.1.2",
Label: "nightly",
},
},
}
rejectPayloads := []payload{
{
AppName: "my-app",
Data: map[string]string{
"Version": "0.1.0",
},
},
{
AppName: "my-app",
Data: map[string]string{},
Labels: []string{"0.1.1"},
},
{
AppName: "my-app",
Labels: []string{"foo", "nightly"},
Data: map[string]string{
"Version": "0.1.2",
},
},
}
for _, p := range rejectPayloads {
if !cfg.matchesRejectionCondition(&p) {
t.Errorf("payload was accepted when it should be rejected:\n payload=%+v\nconfig=%+v", p, cfg)
}
}
acceptPayloads := []payload{
{
AppName: "different-app",
Data: map[string]string{
"Version": "0.1.0",
},
},
{
AppName: "different-app",
Data: map[string]string{},
Labels: []string{"0.1.1"},
},
{
AppName: "different-app",
Labels: []string{"foo", "nightly"},
Data: map[string]string{
"Version": "0.1.2",
},
},
{
AppName: "my-app",
Data: map[string]string{
"Version": "0.1.0-suffix",
},
},
{
AppName: "my-app",
Data: map[string]string{},
Labels: []string{"0.1.1-suffix"},
},
{
AppName: "my-app",
Labels: []string{"foo", "nightly-suffix"},
Data: map[string]string{
"Version": "0.1.2",
},
},
{ // version matches but label does not (it's Label AND Version not OR)
AppName: "my-app",
Labels: []string{"foo"},
Data: map[string]string{
"Version": "0.1.2",
},
},
}
for _, p := range acceptPayloads {
if cfg.matchesRejectionCondition(&p) {
t.Errorf("payload was rejected when it should be accepted:\n payload=%+v\nconfig=%+v", p, cfg)
}
}
}

0 comments on commit 71a9120

Please sign in to comment.