forked from zerotier/terraform-provider-zerotier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_source_test.go
52 lines (40 loc) · 1.28 KB
/
data_source_test.go
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
package main
import (
"testing"
)
func TestDataSourceNetwork(t *testing.T) {
tf := getTFTest(t)
tf.Apply("testdata/plans/data-source-network.tf")
tf.Refresh()
for _, data := range a(tf.State()["resources"]) {
m := h(data)
attrs := h(h(a(m["instances"])[0])["attributes"])
if m["type"] == "zerotier_network" {
if attrs["name"].(string) != "bobs_garage" {
t.Fatal("name was not set on object, was:", attrs["name"])
}
if attrs["description"].(string) != "so say we bob" {
t.Fatal("description was incorrect, was:", attrs["description"])
}
if attrs["id"].(string) == "" {
t.Fatal("id was not set on object, was", attrs["id"])
}
}
}
}
func TestDataSourceMembers(t *testing.T) {
tf := getTFTest(t)
tf.Apply("testdata/plans/data-source-members.tf")
tf.Refresh()
outputs := h(tf.State()["outputs"])
memberName := s(h(outputs["member_name"])["value"])
memberNameExp := "bobs_car"
if memberName != memberNameExp {
t.Fatalf("member name was not set correctly: expected: %q, found: %q", memberNameExp, memberName)
}
memberDesc := s(h(outputs["member_description"])["value"])
memberDescExp := "bobs shiny car"
if memberDesc != memberDescExp {
t.Fatalf("member description was not set correctly: expected: %q, found: %q", memberDescExp, memberDesc)
}
}