File size: 1,384 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package smoke

import (
	"fmt"
	"testing"

	"github.com/target/goalert/test/smoke/harness"
)

// TestGraphQLServiceLabels tests that labels for services can be created
// (currently only be created directly through db and not via GraphQL layer),
// edited and deleted.

func TestGraphQLServiceLabels(t *testing.T) {
	t.Parallel()

	// Insert initial one label into db
	const sql = `
	insert into escalation_policies (id, name) 
	values
		({{uuid "eid"}}, 'esc policy');
	insert into services (id, escalation_policy_id, name) 
	values
		({{uuid "sid"}}, {{uuid "eid"}}, 'service');

	insert into labels (id, tgt_service_id, key, value) 
	values
		('1', {{uuid "sid"}}, 'foo/bar', 'testvalue');
`

	h := harness.NewHarness(t, sql, "labels-switchover-trigger")
	defer h.Close()

	doQL := func(query string) {
		g := h.GraphQLQuery2(query)
		for _, err := range g.Errors {
			t.Error("GraphQL Error:", err.Message)
		}
		if len(g.Errors) > 0 {
			t.Fatal("errors returned from GraphQL")
		}
		t.Log("Response:", string(g.Data))
	}

	// Edit label
	doQL(fmt.Sprintf(`
		mutation {
			setLabel(input:{ target: {type: service , id: "%s"}, key: "%s", value: "%s" }) 
		}
	`, h.UUID("sid"), "foo/bar", "editedvalue"))

	// Delete label
	doQL(fmt.Sprintf(`
		mutation {
			setLabel(input:{ target: {type: service , id: "%s"}, key: "%s", value: "%s" }) 
		}
	`, h.UUID("sid"), "foo/bar", ""))
}