Skip to content

Commit

Permalink
fix(bigpanda): setup test options from configuration (#2554)
Browse files Browse the repository at this point in the history
* fix(bigpanda): setup current time in test options

* fix(bigpanda): setup configured application key

* chore: simplify code

* fix(bigpanda): exclude timestamp from in tests
  • Loading branch information
sranka committed May 19, 2021
1 parent 452f2b2 commit 6ceb6ec
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
9 changes: 8 additions & 1 deletion server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9100,7 +9100,7 @@ func TestServer_ListServiceTests(t *testing.T) {
Link: client.Link{Relation: client.Self, Href: "/kapacitor/v1/service-tests/bigpanda"},
Name: "bigpanda",
Options: client.ServiceTestOptions{
"app_key": "my-app-key-123456",
"app_key": "",
"level": "CRITICAL",
"message": "test bigpanda message",
"timestamp": "1970-01-01T00:00:01Z",
Expand Down Expand Up @@ -9483,6 +9483,13 @@ func TestServer_ListServiceTests(t *testing.T) {
for i := range expServiceTests.Services {
exp := expServiceTests.Services[i]
got := serviceTests.Services[i]
if _, expHasTimestamp := exp.Options["timestamp"]; expHasTimestamp {
if _, gotHasTimestamp := got.Options["timestamp"]; !gotHasTimestamp {
t.Errorf("timestamp not found in server test %s:\n%s", exp.Name, cmp.Diff(exp, got))
}
exp.Options["timestamp"] = ""
got.Options["timestamp"] = ""
}
if !reflect.DeepEqual(got, exp) {
t.Errorf("unexpected server test %s:\n%s", exp.Name, cmp.Diff(exp, got))
}
Expand Down
7 changes: 2 additions & 5 deletions services/bigpanda/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,8 @@ type testOptions struct {
}

func (s *Service) TestOptions() interface{} {
t, _ := time.Parse(time.RFC3339, "1970-01-01T00:00:01Z")

return &testOptions{
AppKey: "my-app-key-123456",
AppKey: s.config().AppKey,
Message: "test bigpanda message",
Level: alert.Critical,
Data: alert.EventData{
Expand All @@ -105,9 +103,8 @@ func (s *Service) TestOptions() interface{} {
Fields: make(map[string]interface{}),
Result: models.Result{},
},
Timestamp: t,
Timestamp: time.Now(),
}

}

func (s *Service) Test(options interface{}) error {
Expand Down

0 comments on commit 6ceb6ec

Please sign in to comment.