-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_test.go
More file actions
41 lines (36 loc) · 1.21 KB
/
Copy pathmain_test.go
File metadata and controls
41 lines (36 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main
import (
"bytes"
"path/filepath"
"strings"
"testing"
"github.com/m7medVision/sx/internal/agent"
)
func TestAgentNotifyStoresExplicitEvent(t *testing.T) {
path := filepath.Join(t.TempDir(), "events.json")
t.Setenv("SX_AGENT_EVENT_STORE", path)
var stdout, stderr bytes.Buffer
if code := run([]string{"agent", "notify", "api", "completed", "released to production"}, &stdout, &stderr); code != 0 {
t.Fatalf("notify exit = %d, stderr = %s", code, stderr.String())
}
events, err := (agent.Store{Path: path}).Load()
if err != nil {
t.Fatal(err)
}
if event := events["api"]; event.State != agent.Completed || event.Summary != "released to production" {
t.Fatalf("event = %#v", event)
}
}
func TestAgentNotifyRejectsMissingOrInvalidArguments(t *testing.T) {
for _, args := range [][]string{{"agent", "notify", "api"}, {"agent", "notify", "api", "later"}} {
var stdout, stderr bytes.Buffer
if code := run(args, &stdout, &stderr); code == 0 || !strings.Contains(stderr.String(), "sx agent notify") {
t.Fatalf("run(%q) = %d, stderr = %q", args, code, stderr.String())
}
}
}
func TestFirstLine(t *testing.T) {
if got := firstLine("one\ntwo"); got != "one" {
t.Fatalf("firstLine = %q", got)
}
}