faas/gateway/tests/unmarshall_test.go
John McCabe 89878f0c8a Migrate from alexellis org to openfaas
Note, not all `alexellis/github` references should be changed, there are
a number of repos which are not part of the openfaas org, this commit
excludes those.

Signed-off-by: John McCabe <john@johnmccabe.net>
2017-10-04 09:18:06 +01:00

42 lines
936 B
Go

// Copyright (c) Alex Ellis 2017. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
package tests
import (
"testing"
"io/ioutil"
"encoding/json"
"github.com/openfaas/faas/gateway/requests"
)
// TestUnmarshallAlert is an exploratory test from TDD'ing the struct to parse a Prometheus alert
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)
}
if (len(alert.Status)) == 0 {
t.Fatal("No status read")
}
if (len(alert.Receiver)) == 0 {
t.Fatal("No status read")
}
if (len(alert.Alerts)) == 0 {
t.Fatal("No alerts read")
}
if (len(alert.Alerts[0].Labels.AlertName)) == 0 {
t.Fatal("No alerts name")
}
if (len(alert.Alerts[0].Labels.FunctionName)) == 0 {
t.Fatal("No function name read")
}
}