@@ -23,16 +23,18 @@ const (
23
23
)
24
24
25
25
var (
26
- app * API
27
- database db.DB
28
- counter int
26
+ app * API
27
+ database db.DB
28
+ counter int
29
+ privateAPI RulesAPI
29
30
)
30
31
31
32
// setup sets up the environment for the tests.
32
33
func setup (t * testing.T ) {
33
34
database = dbtest .Setup (t )
34
35
app = NewAPI (database )
35
36
counter = 0
37
+ privateAPI = dbStore {db : database }
36
38
}
37
39
38
40
// cleanup cleans up the environment after a test.
@@ -178,74 +180,62 @@ func Test_PostConfig_MultipleUsers(t *testing.T) {
178
180
assert .True (t , config2 .ID > config1 .ID , "%v > %v" , config2 .ID , config1 .ID )
179
181
}
180
182
181
- // // GetAllConfigs returns an empty list of configs if there aren't any.
182
- // func Test_GetAllConfigs_Empty(t *testing.T) {
183
- // setup(t)
184
- // defer cleanup(t)
185
-
186
- // w := request(t, "GET", c.PrivateEndpoint, nil)
187
- // assert.Equal(t, http.StatusOK, w.Code)
188
- // var found api.ConfigsView
189
- // err := json.Unmarshal(w.Body.Bytes(), &found)
190
- // assert.NoError(t, err, "Could not unmarshal JSON")
191
- // assert.Equal(t, api.ConfigsView{Configs: map[string]configs.View{}}, found)
192
- // }
193
-
194
- // // GetAllConfigs returns all created configs.
195
- // func Test_GetAllConfigs(t *testing.T) {
196
- // setup(t)
197
- // defer cleanup(t)
198
-
199
- // userID := makeUserID()
200
- // config := makeRulerConfig()
201
-
202
- // view := c.post(t, userID, config)
203
- // w := request(t, "GET", c.PrivateEndpoint, nil)
204
- // assert.Equal(t, http.StatusOK, w.Code)
205
- // var found api.ConfigsView
206
- // err := json.Unmarshal(w.Body.Bytes(), &found)
207
- // assert.NoError(t, err, "Could not unmarshal JSON")
208
- // assert.Equal(t, api.ConfigsView{Configs: map[string]configs.View{
209
- // userID: view,
210
- // }}, found)
211
- // }
212
-
213
- // // GetAllConfigs returns the *newest* versions of all created configs.
214
- // func Test_GetAllConfigs_Newest(t *testing.T) {
215
- // setup(t)
216
- // defer cleanup(t)
217
-
218
- // userID := makeUserID()
219
-
220
- // c.post(t, userID, makeRulerConfig())
221
- // c.post(t, userID, makeRulerConfig())
222
- // lastCreated := c.post(t, userID, makeRulerConfig())
223
-
224
- // w := request(t, "GET", c.PrivateEndpoint, nil)
225
- // assert.Equal(t, http.StatusOK, w.Code)
226
- // var found api.ConfigsView
227
- // err := json.Unmarshal(w.Body.Bytes(), &found)
228
- // assert.NoError(t, err, "Could not unmarshal JSON")
229
- // assert.Equal(t, api.ConfigsView{Configs: map[string]configs.View{
230
- // userID: lastCreated,
231
- // }}, found)
232
- // }
233
-
234
- // func Test_GetConfigs_IncludesNewerConfigsAndExcludesOlder(t *testing.T) {
235
- // setup(t)
236
- // defer cleanup(t)
237
-
238
- // c.post(t, makeUserID(), makeRulerConfig())
239
- // config2 := c.post(t, makeUserID(), makeRulerConfig())
240
- // userID3 := makeUserID()
241
- // config3 := c.post(t, userID3, makeRulerConfig())
242
-
243
- // w := request(t, "GET", fmt.Sprintf("%s?since=%d", c.PrivateEndpoint, config2.ID), nil)
244
- // assert.Equal(t, http.StatusOK, w.Code)
245
- // var found api.ConfigsView
246
- // err := json.Unmarshal(w.Body.Bytes(), &found)
247
- // assert.NoError(t, err, "Could not unmarshal JSON")
248
- // assert.Equal(t, api.ConfigsView{Configs: map[string]configs.View{
249
- // userID3: config3,
250
- // }}, found)
251
- // }
183
+ // GetAllConfigs returns an empty list of configs if there aren't any.
184
+ func Test_GetAllConfigs_Empty (t * testing.T ) {
185
+ setup (t )
186
+ defer cleanup (t )
187
+
188
+ configs , err := privateAPI .GetConfigs (0 )
189
+ assert .NoError (t , err , "error getting configs" )
190
+ assert .Equal (t , 0 , len (configs ))
191
+ }
192
+
193
+ // GetAllConfigs returns all created configs.
194
+ func Test_GetAllConfigs (t * testing.T ) {
195
+ setup (t )
196
+ defer cleanup (t )
197
+
198
+ userID := makeUserID ()
199
+ config := makeRulerConfig ()
200
+ view := post (t , userID , nil , config )
201
+
202
+ found , err := privateAPI .GetConfigs (0 )
203
+ assert .NoError (t , err , "error getting configs" )
204
+ assert .Equal (t , map [string ]configs.VersionedRulesConfig {
205
+ userID : view ,
206
+ }, found )
207
+ }
208
+
209
+ // GetAllConfigs returns the *newest* versions of all created configs.
210
+ func Test_GetAllConfigs_Newest (t * testing.T ) {
211
+ setup (t )
212
+ defer cleanup (t )
213
+
214
+ userID := makeUserID ()
215
+
216
+ config1 := post (t , userID , nil , makeRulerConfig ())
217
+ config2 := post (t , userID , config1 .Config , makeRulerConfig ())
218
+ lastCreated := post (t , userID , config2 .Config , makeRulerConfig ())
219
+
220
+ found , err := privateAPI .GetConfigs (0 )
221
+ assert .NoError (t , err , "error getting configs" )
222
+ assert .Equal (t , map [string ]configs.VersionedRulesConfig {
223
+ userID : lastCreated ,
224
+ }, found )
225
+ }
226
+
227
+ func Test_GetConfigs_IncludesNewerConfigsAndExcludesOlder (t * testing.T ) {
228
+ setup (t )
229
+ defer cleanup (t )
230
+
231
+ post (t , makeUserID (), nil , makeRulerConfig ())
232
+ config2 := post (t , makeUserID (), nil , makeRulerConfig ())
233
+ userID3 := makeUserID ()
234
+ config3 := post (t , userID3 , nil , makeRulerConfig ())
235
+
236
+ found , err := privateAPI .GetConfigs (config2 .ID )
237
+ assert .NoError (t , err , "error getting configs" )
238
+ assert .Equal (t , map [string ]configs.VersionedRulesConfig {
239
+ userID3 : config3 ,
240
+ }, found )
241
+ }
0 commit comments