@@ -10,15 +10,9 @@ import (
10
10
)
11
11
12
12
func Test_NewResourceWithTags (t * testing.T ) {
13
- config := aws.Config {
14
- Region : "us-east-1" ,
15
- }
16
- ctx := context2.AWSetsCtx {
17
- AWSCfg : config ,
18
- AccountId : "123456789" ,
19
- Context : context .Background (),
20
- Logger : nil ,
21
- }
13
+
14
+ ctx := getContext ()
15
+
22
16
object := map [string ]interface {}{
23
17
"Foo" : "Bar" ,
24
18
"Tags" : map [string ]string {
@@ -27,16 +21,117 @@ func Test_NewResourceWithTags(t *testing.T) {
27
21
},
28
22
}
29
23
r := New (ctx , Ec2Instance , "resource_id" , "resource_name" , object )
24
+ if r .Region != "us-east-1" {
25
+ t .Fatalf ("expected us-east-1, got %s\n " , r .Region )
26
+ }
30
27
if r .Tags ["tag1" ] != "value1" {
31
28
t .Fatalf ("expected tag that was not present\n " )
32
29
}
33
30
if r .Id != "resource_id" {
34
31
t .Fatalf ("expected %s, got %s\n " , "resource_id" , r .Id )
35
32
}
36
- if r .Id != "resource_name" {
33
+ if r .Name != "resource_name" {
34
+ t .Fatalf ("expected %s, got %s\n " , "resource_name" , r .Name )
35
+ }
36
+ if r .Version != "" {
37
+ t .Fatalf ("expected empty version, got %s\n " , r .Version )
38
+ }
39
+ }
40
+
41
+ func Test_NewResourceWithoutTags (t * testing.T ) {
42
+
43
+ ctx := getContext ()
44
+
45
+ object := map [string ]interface {}{
46
+ "Foo" : "Bar" ,
47
+ }
48
+ r := New (ctx , Ec2Instance , "resource_id" , "resource_name" , object )
49
+ if len (r .Tags ) != 0 {
50
+ t .Fatalf ("expected zero tags\n " )
51
+ }
52
+ if r .Id != "resource_id" {
53
+ t .Fatalf ("expected %s, got %s\n " , "resource_id" , r .Id )
54
+ }
55
+ if r .Name != "resource_name" {
37
56
t .Fatalf ("expected %s, got %s\n " , "resource_name" , r .Name )
38
57
}
58
+ }
59
+
60
+ func Test_NewGlobalResource (t * testing.T ) {
61
+
62
+ ctx := getContext ()
63
+
64
+ object := map [string ]interface {}{
65
+ "Foo" : "Bar" ,
66
+ "Tags" : map [string ]string {
67
+ "tag1" : "value1" ,
68
+ "tag2" : "value2" ,
69
+ },
70
+ }
71
+ r := NewGlobal (ctx , IamRole , "resource_id" , "resource_name" , object )
72
+ if r .Region != "aws-global" {
73
+ t .Fatalf ("expected aws-global, got %s" , r .Region )
74
+ }
75
+ if r .Tags ["tag1" ] != "value1" {
76
+ t .Fatalf ("expected tag that was not present\n " )
77
+ }
78
+ }
79
+
80
+ func Test_NewResourceVersion (t * testing.T ) {
81
+
82
+ ctx := getContext ()
83
+
84
+ object := map [string ]interface {}{
85
+ "Foo" : "Bar" ,
86
+ "Tags" : map [string ]string {
87
+ "tag1" : "value1" ,
88
+ "tag2" : "value2" ,
89
+ },
90
+ }
91
+ r := NewVersion (ctx , IamRole , "resource_id" , "resource_name" , "v1" , object )
92
+ if r .Version != "v1" {
93
+ t .Fatalf ("expected v1, got %s\n " , r .Version )
94
+ }
95
+ if r .Tags ["tag1" ] != "value1" {
96
+ t .Fatalf ("expected tag that was not present\n " )
97
+ }
98
+ }
99
+
100
+ func Test_ResourceAddRelation (t * testing.T ) {
101
+
102
+ ctx := getContext ()
103
+ object := map [string ]interface {}{
104
+ "Foo" : "Bar" ,
105
+ "Tags" : map [string ]string {
106
+ "tag1" : "value1" ,
107
+ "tag2" : "value2" ,
108
+ },
109
+ }
110
+ r := New (ctx , Ec2Instance , "resource_id" , "resource_name" , object )
111
+ r .AddRelation (IamRole , "role1" , "role1" )
112
+ r .AddARNRelation (IamRole , "arn:aws:iam::123456789:role/role2" )
113
+
114
+ if len (r .Relations ) != 2 {
115
+ t .Fatalf ("expected 2 relationships, got %d\n " , len (r .Relations ))
116
+ }
117
+ if r .Relations [0 ].Id != "role1" {
118
+ t .Fatalf ("expected relationship with id of role1, got %s\n " , r .Relations [0 ].Id )
119
+ }
120
+ if r .Relations [1 ].Id != "role2" {
121
+ t .Fatalf ("expected relationship with id of role2, got %s\n " , r .Relations [1 ].Id )
122
+ }
123
+ }
39
124
125
+ func getContext () context2.AWSetsCtx {
126
+ config := aws.Config {
127
+ Region : "us-east-1" ,
128
+ }
129
+ return context2.AWSetsCtx {
130
+ AWSCfg : config ,
131
+ AccountId : "123456789" ,
132
+ Context : context .Background (),
133
+ Logger : nil ,
134
+ }
40
135
}
41
136
42
137
func Test_toString (t * testing.T ) {
0 commit comments