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

Function TestMemoryCache_GetArtifact

pkg/cache/memory_test.go:95–139  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

93}
94
95func TestMemoryCache_GetArtifact(t *testing.T) {
96 tests := []struct {
97 name string
98 artifactID string
99 artifactInfo types.ArtifactInfo
100 wantErr bool
101 }{
102 {
103 name: "happy path",
104 artifactID: "sha256:8652b9f0cb4c0599575e5a003f5906876e10c1ceb2ab9fe1786712dac14a50cf",
105 artifactInfo: types.ArtifactInfo{
106 SchemaVersion: 2,
107 Architecture: "amd64",
108 Created: time.Date(2020, 11, 14, 0, 20, 4, 0, time.UTC),
109 DockerVersion: "19.03.12",
110 OS: "linux",
111 },
112 wantErr: false,
113 },
114 {
115 name: "not found",
116 artifactID: "sha256:nonexistent",
117 wantErr: true,
118 },
119 }
120
121 for _, tt := range tests {
122 t.Run(tt.name, func(t *testing.T) {
123 c := cache.NewMemoryCache()
124
125 if !tt.wantErr {
126 err := c.PutArtifact(t.Context(), tt.artifactID, tt.artifactInfo)
127 require.NoError(t, err)
128 }
129
130 got, err := c.GetArtifact(t.Context(), tt.artifactID)
131 if tt.wantErr {
132 require.ErrorContains(t, err, "not found in memory cache")
133 return
134 }
135 require.NoError(t, err)
136 assert.Equal(t, tt.artifactInfo, got)
137 })
138 }
139}
140
141func TestMemoryCache_GetBlob(t *testing.T) {
142 tests := []struct {

Callers

nothing calls this directly

Calls 6

PutArtifactMethod · 0.95
GetArtifactMethod · 0.95
NewMemoryCacheFunction · 0.92
ContextMethod · 0.80
EqualMethod · 0.80
RunMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…