From 158c4122518302854c1cd25beeab056445957789 Mon Sep 17 00:00:00 2001 From: Alex Ellis Date: Sun, 22 Jan 2017 11:09:43 +0000 Subject: [PATCH] Initial test for alert unmarshall --- gateway/requests/requests.go | 5 ++++ {prometheus => gateway/tests}/test_alert.json | 0 gateway/tests/unmarshall_test.go | 29 +++++++++++++++++++ 3 files changed, 34 insertions(+) rename {prometheus => gateway/tests}/test_alert.json (100%) create mode 100644 gateway/tests/unmarshall_test.go diff --git a/gateway/requests/requests.go b/gateway/requests/requests.go index 94bfa8a3..fb40469c 100644 --- a/gateway/requests/requests.go +++ b/gateway/requests/requests.go @@ -21,3 +21,8 @@ type AlexaRequestBody struct { Session AlexaSession `json:"session"` Request AlexaRequest `json:"request"` } + +type PrometheusAlert struct { + Status string `json:"status"` + Receiver string `json:"receiver"` +} diff --git a/prometheus/test_alert.json b/gateway/tests/test_alert.json similarity index 100% rename from prometheus/test_alert.json rename to gateway/tests/test_alert.json diff --git a/gateway/tests/unmarshall_test.go b/gateway/tests/unmarshall_test.go new file mode 100644 index 00000000..989dcd33 --- /dev/null +++ b/gateway/tests/unmarshall_test.go @@ -0,0 +1,29 @@ +package requests + +import ( + "fmt" + "testing" + + "io/ioutil" + + "encoding/json" + + "github.com/alexellis/faas/gateway/requests" +) + +func TestUnmarshallAlert(t *testing.T) { + file, _ := ioutil.ReadFile("./test_alert.json") + + var alert requests.PrometheusAlert + err := json.Unmarshal(file, &alert) + if err != nil { + t.Fatal(err) + } + fmt.Println("OK", string(file), alert) + if (len(alert.Status)) == 0 { + t.Fatal("No status read") + } + if (len(alert.Receiver)) == 0 { + t.Fatal("No status read") + } +}