From 71a912098ebfef05c691b9024045db00d6a87d8f Mon Sep 17 00:00:00 2001 From: Kegan Dougal <7190048+kegsay@users.noreply.github.com> Date: Fri, 10 May 2024 09:02:12 +0100 Subject: [PATCH] Changelogs; tests; linting --- changelog.d/85.feature | 1 + main.go | 1 + main_test.go | 98 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 100 insertions(+) create mode 100644 changelog.d/85.feature create mode 100644 main_test.go diff --git a/changelog.d/85.feature b/changelog.d/85.feature new file mode 100644 index 0000000..0e597c1 --- /dev/null +++ b/changelog.d/85.feature @@ -0,0 +1 @@ +Add support for blocking specific app/version/label combinations. diff --git a/main.go b/main.go index 05da3d1..468e176 100644 --- a/main.go +++ b/main.go @@ -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"` diff --git a/main_test.go b/main_test.go new file mode 100644 index 0000000..4150d7c --- /dev/null +++ b/main_test.go @@ -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) + } + } +}