(t *testing.T)
| 93 | } |
| 94 | |
| 95 | func 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 | |
| 141 | func TestMemoryCache_GetBlob(t *testing.T) { |
| 142 | tests := []struct { |
nothing calls this directly
no test coverage detected
searching dependent graphs…