MCPcopy
hub / github.com/aquasecurity/trivy / TestRemoteCache_PutArtifactInsecure

Function TestRemoteCache_PutArtifactInsecure

pkg/cache/remote_test.go:306–355  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

304}
305
306func TestRemoteCache_PutArtifactInsecure(t *testing.T) {
307 ts := httptest.NewTLSServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) {}))
308 defer ts.Close()
309
310 type args struct {
311 imageID string
312 imageInfo types.ArtifactInfo
313 insecure bool
314 }
315 tests := []struct {
316 name string
317 args args
318 wantErr string
319 }{
320 {
321 name: "happy path",
322 args: args{
323 imageID: "sha256:e7d92cdc71feacf90708cb59182d0df1b911f8ae022d29e8e95d75ca6a99776a",
324 imageInfo: types.ArtifactInfo{},
325 insecure: true,
326 },
327 },
328 {
329 name: "sad path",
330 args: args{
331 imageID: "sha256:e7d92cdc71feacf90708cb59182d0df1b911f8ae022d29e8e95d75ca6a99776a",
332 imageInfo: types.ArtifactInfo{},
333 insecure: false,
334 },
335 wantErr: "failed to do request",
336 },
337 }
338 for _, tt := range tests {
339 t.Run(tt.name, func(t *testing.T) {
340 ctx := xhttp.WithTransport(t.Context(), xhttp.NewTransport(xhttp.Options{
341 Insecure: tt.args.insecure,
342 }))
343 c := cache.NewRemoteCache(ctx, cache.RemoteOptions{
344 ServerAddr: ts.URL,
345 CustomHeaders: nil,
346 })
347 err := c.PutArtifact(t.Context(), tt.args.imageID, tt.args.imageInfo)
348 if tt.wantErr != "" {
349 require.ErrorContains(t, err, tt.wantErr)
350 return
351 }
352 require.NoError(t, err, tt.name)
353 })
354 }
355}

Callers

nothing calls this directly

Calls 4

PutArtifactMethod · 0.95
ContextMethod · 0.80
CloseMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…