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

Function TestHubUpdateCannotWrite

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

Source from the content-addressed store, hash-verified

161}
162
163func TestHubUpdateCannotWrite(t *testing.T) {
164 ctx := t.Context()
165 hub, err := testHub(t, "{}")
166 require.NoError(t, err)
167
168 index1 := `
169{
170 "parsers": {
171 "author/pars1": {
172 "path": "parsers/s01-parse/pars1.yaml",
173 "stage": "s01-parse",
174 "version": "0.0",
175 "versions": {
176 "0.0": {
177 "digest": "44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a"
178 }
179 },
180 "content": "{}"
181 }
182 }
183}`
184
185 mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
186 if r.URL.Path != "/main/.index.json" {
187 w.WriteHeader(http.StatusNotFound)
188 }
189
190 _, err = w.Write([]byte(index1))
191 assert.NoError(t, err)
192 }))
193 defer mockServer.Close()
194
195 downloader := &Downloader{
196 Branch: "main",
197 URLTemplate: mockServer.URL + "/%s/%s",
198 }
199
200 hub.local.HubIndexFile = "/proc/foo/bar/baz/.index.json"
201
202 updated, err := hub.Update(ctx, downloader, true)
203 cstest.RequireErrorContains(t, err, "failed to create temporary download file for /proc/foo/bar/baz/.index.json")
204 assert.False(t, updated)
205}
206
207func TestHubUpdateAfterLoad(t *testing.T) {
208 ctx := t.Context()

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…