-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuilder_test.go
102 lines (70 loc) · 3.12 KB
/
builder_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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package graph
import (
"context"
"testing"
)
type kinesis struct {
ctxt context.Context
Arn string
}
type dynamo struct {
ctxt context.Context
}
type deployment struct {
ctxt context.Context
KinesisArn string
}
func TestCheckField(t *testing.T) {
ctxt := context.Background()
kinesisResource := MakeResource("mykin", nil, &kinesis{ctxt: ctxt}, func(x interface{}) (string, error) { return "", nil }, func(x interface{}) error { return nil })
if checkField(kinesisResource, "Arn") != nil {
t.Fatal("Arn field exists in kinesisResource")
}
if checkField(kinesisResource, "Bad") == nil {
t.Fatal("Bad field does not exist in kinesisResource")
}
}
func TestCopyValue(t *testing.T) {
ctxt := context.Background()
arn := "hello123"
kinesisResource := MakeResource("mykin", nil, &kinesis{ctxt, arn}, func(x interface{}) (string, error) { return "", nil }, func(x interface{}) error { return nil })
deploymentResource := MakeResource("mydep1", []Dependency{{"mykin", "Arn", "KinesisArn"}}, &deployment{ctxt: ctxt}, func(x interface{}) (string, error) { d := x.(*deployment); return d.KinesisArn, nil }, func(x interface{}) error { return nil })
copyValue(deploymentResource, "KinesisArn", kinesisResource, "Arn")
out, err := deploymentResource.Update(context.Background())
if err != nil {
t.Fatalf("error calling Update! err = %v", err)
}
if out != arn {
t.Fatalf("expected arn to match!")
}
}
func TestSync(t *testing.T) {
mykin := "mykin"
ctxt := context.Background()
arn := "hello123"
kinesisResource := MakeResource(mykin, nil, &kinesis{ctxt, arn}, func(x interface{}) (string, error) { return "", nil }, func(x interface{}) error { return nil })
dynamoResource := MakeResource("mydyn", nil, &dynamo{ctxt: ctxt}, func(x interface{}) (string, error) { return "", nil }, func(x interface{}) error { return nil })
deploymentResource := MakeResource("mydep1", []Dependency{{"mykin", "Arn", "KinesisArn"}}, &deployment{ctxt: ctxt}, func(x interface{}) (string, error) { d := x.(*deployment); return d.KinesisArn, nil }, func(x interface{}) error { return nil })
resources := []Resource{kinesisResource, dynamoResource, deploymentResource}
lib := New(&Opts{CustomLogger: t.Log})
status, err := lib.Sync(ctxt, resources, false)
if err != nil {
t.Fatalf("unable to sync %v", err)
}
if status["mydep1"] != arn {
t.Fatal("expected mydep1 status to return kinesis arn")
}
}
func TestInvalidDependency(t *testing.T) {
mykin := "mykin"
ctxt := context.Background()
arn := "hello123"
kinesisResource := MakeResource(mykin, nil, &kinesis{ctxt, arn}, func(x interface{}) (string, error) { return "", nil }, func(x interface{}) error { return nil })
deploymentResource := MakeResource("mydep1", []Dependency{{"mykin2", "Arn", "KinesisArn"}}, &deployment{ctxt: ctxt}, func(x interface{}) (string, error) { d := x.(*deployment); return d.KinesisArn, nil }, func(x interface{}) error { return nil })
resources := []Resource{kinesisResource, deploymentResource}
lib := New(&Opts{CustomLogger: t.Log})
_, err := lib.Sync(ctxt, resources, false)
if err == nil {
t.Fatalf("expected sync to fail with invalid dependency")
}
}