Skip to content

Commit

Permalink
alertmanager, revise regression test for link encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
BuJo committed Nov 13, 2023
1 parent abe4e00 commit de7c2c0
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions pkg/connectors/alertmanager/connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/synyx/tuwat/pkg/connectors/common"
)

func TestConnector(t *testing.T) {
func mockConnector() connectors.Connector {
testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
res.WriteHeader(http.StatusOK)
_, _ = res.Write([]byte(mockResponse))
Expand All @@ -27,7 +27,11 @@ func TestConnector(t *testing.T) {
},
}

var connector connectors.Connector = NewConnector(&cfg)
return NewConnector(&cfg)
}

func TestConnector(t *testing.T) {
connector := mockConnector()
alerts, err := connector.Collect(context.Background())
if err != nil {
t.Fatal(err)
Expand All @@ -36,13 +40,6 @@ func TestConnector(t *testing.T) {
if alerts == nil || len(alerts) != 3 {
t.Error("There should be alerts")
}

alert := alerts[0]
for _, link := range alert.Links {
if !strings.Contains(string(link), "://") {
t.Error("There should be a non encoded url")
}
}
}

func TestDecode(t *testing.T) {
Expand All @@ -53,6 +50,18 @@ func TestDecode(t *testing.T) {
}
}

func TestEncodingOfLinks(t *testing.T) {
connector := mockConnector()
alerts, _ := connector.Collect(context.Background())

alert := alerts[0]
for _, link := range alert.Links {
if !strings.Contains(string(link), "://") {
t.Error("There should be a non encoded url")
}
}
}

const mockResponse = `
[
{
Expand Down

0 comments on commit de7c2c0

Please sign in to comment.