@@ -81,105 +81,3 @@ func TestRepository_UpsertController(t *testing.T) {
81
81
})
82
82
}
83
83
}
84
-
85
- func TestRepository_UpdateController (t * testing.T ) {
86
- ctx := context .Background ()
87
- conn , _ := db .TestSetup (t , "postgres" )
88
- rw := db .New (conn )
89
- wrapper := db .TestWrapper (t )
90
- testKms := kms .TestKms (t , conn , wrapper )
91
- testRepo , err := NewRepository (ctx , rw , rw , testKms )
92
- require .NoError (t , err )
93
-
94
- iamRepo := iam .TestRepo (t , conn , wrapper )
95
- iam .TestScopes (t , iamRepo )
96
-
97
- tests := []struct {
98
- name string
99
- originalController * Controller
100
- updatedController * Controller
101
- wantCount int
102
- wantErr bool
103
- }{
104
- {
105
- name : "nil-controller" ,
106
- wantErr : true ,
107
- },
108
- {
109
- name : "empty-id" ,
110
- updatedController : NewController ("" , WithAddress ("127.0.0.1" )),
111
- wantErr : true ,
112
- },
113
- {
114
- name : "empty-address" ,
115
- updatedController : NewController ("test-controller" ),
116
- wantErr : true ,
117
- },
118
- {
119
- name : "controller-not-found" ,
120
- updatedController : NewController ("test-controller" , WithAddress ("127.0.0.1" ), WithDescription ("new ipv4 description" )),
121
- wantErr : true ,
122
- },
123
- {
124
- name : "valid-ipv4-controller" ,
125
- originalController : NewController ("ipv4-controller" , WithAddress ("127.0.0.1" ), WithDescription ("ipv4 description" )),
126
- updatedController : NewController ("ipv4-controller" , WithAddress ("127.0.0.2" ), WithDescription ("new ipv4 description" )),
127
- wantCount : 1 ,
128
- },
129
- {
130
- name : "valid-ipv6-controller" ,
131
- originalController : NewController ("test-ipv6-controller" , WithAddress ("[2001:4860:4860:0:0:0:0:8888]" ), WithDescription ("ipv6 description" )),
132
- updatedController : NewController ("test-ipv6-controller" , WithAddress ("[2001:4860:4860:0:0:0:0:9999]" ), WithDescription ("new ipv6 description" )),
133
- wantCount : 1 ,
134
- },
135
- {
136
- name : "valid-abbreviated-ipv6-controller" ,
137
- originalController : NewController ("test-abbreviated-ipv6-controller" , WithAddress ("[2001:4860:4860::8888]" ), WithDescription ("abbreviated ipv6 description" )),
138
- updatedController : NewController ("test-abbreviated-ipv6-controller" , WithAddress ("[2001:4860:4860::9999]" ), WithDescription ("new abbreviated ipv6 description" )),
139
- wantCount : 1 ,
140
- },
141
- {
142
- name : "valid-controller-short-name" ,
143
- originalController : NewController ("test" , WithAddress ("127.0.0.1" ), WithDescription ("short name description" )),
144
- updatedController : NewController ("test" , WithAddress ("127.0.0.2" ), WithDescription ("new short name description" )),
145
- wantCount : 1 ,
146
- },
147
- }
148
- for _ , tt := range tests {
149
- t .Run (tt .name , func (t * testing.T ) {
150
- assert , require := assert .New (t ), require .New (t )
151
-
152
- var originalControllerEntry * Controller
153
- // Insert the original controller attributes if they exist
154
- if tt .originalController != nil {
155
- _ , err := testRepo .UpsertController (ctx , tt .originalController )
156
- require .NoError (err )
157
-
158
- // Retrieve the original controller in the database
159
- controllerList , err := testRepo .ListControllers (ctx , []Option {}... )
160
- require .NoError (err )
161
- originalControllerEntry = controllerList [len (controllerList )- 1 ]
162
- }
163
-
164
- // Update the controller with the updated attributes
165
- got , err := testRepo .UpdateController (ctx , tt .updatedController )
166
- if tt .wantErr {
167
- require .Error (err )
168
- assert .Equal (0 , got )
169
- return
170
- }
171
- require .NoError (err )
172
- assert .Equal (tt .wantCount , got )
173
-
174
- // Retrieve the updated controller in the database and assert updated successfully
175
- controllerList , err := testRepo .ListControllers (ctx , []Option {}... )
176
- require .NoError (err )
177
- updatedControllerEntry := controllerList [len (controllerList )- 1 ]
178
-
179
- assert .Equal (tt .updatedController .PrivateId , updatedControllerEntry .PrivateId )
180
- assert .Equal (tt .updatedController .Address , updatedControllerEntry .Address )
181
- assert .Equal (tt .updatedController .Description , updatedControllerEntry .Description )
182
- assert .True (updatedControllerEntry .UpdateTime .AsTime ().After (originalControllerEntry .UpdateTime .AsTime ()))
183
- })
184
- }
185
- }
0 commit comments