MCPcopy
hub / github.com/crowdsecurity/crowdsec / TestHubUpdateAfterLoad

Function TestHubUpdateAfterLoad

pkg/cwhub/hub_test.go:207–264  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

205}
206
207func TestHubUpdateAfterLoad(t *testing.T) {
208 ctx := t.Context()
209 // Update() can't be called after Load() if the hub is not completely empty.
210 index1 := `
211{
212 "parsers": {
213 "author/pars1": {
214 "path": "parsers/s01-parse/pars1.yaml",
215 "stage": "s01-parse",
216 "version": "0.0",
217 "versions": {
218 "0.0": {
219 "digest": "44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a"
220 }
221 },
222 "content": "{}"
223 }
224 }
225}`
226 hub, err := testHub(t, index1)
227 require.NoError(t, err)
228
229 index2 := `
230{
231 "parsers": {
232 "author/pars2": {
233 "path": "parsers/s01-parse/pars2.yaml",
234 "stage": "s01-parse",
235 "version": "0.0",
236 "versions": {
237 "0.0": {
238 "digest": "44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a"
239 }
240 },
241 "content": "{}"
242 }
243 }
244}`
245
246 mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
247 if r.URL.Path != "/main/.index.json" {
248 w.WriteHeader(http.StatusNotFound)
249 }
250
251 _, err = w.Write([]byte(index2))
252 assert.NoError(t, err)
253 }))
254 defer mockServer.Close()
255
256 downloader := &Downloader{
257 Branch: "main",
258 URLTemplate: mockServer.URL + "/%s/%s",
259 }
260
261 updated, err := hub.Update(ctx, downloader, true)
262 require.ErrorIs(t, err, ErrUpdateAfterSync)
263 assert.False(t, updated)
264}

Callers

nothing calls this directly

Calls 4

testHubFunction · 0.85
WriteMethod · 0.80
CloseMethod · 0.45
UpdateMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…