()
| 109 | } |
| 110 | |
| 111 | func (s *testSuite) TestExists() { |
| 112 | assert := assert.New(s.T()) |
| 113 | // Valid image |
| 114 | err := s.validBackend.Upload(context.TODO(), bytes.NewBuffer(s.uploadedContent), s.casResource) |
| 115 | require.NoError(s.T(), err) |
| 116 | // Image not uploaded by us |
| 117 | digestOthers := "another-deadbeef" |
| 118 | ref, err := name.ParseReference(s.validBackend.resourcePath(digestOthers)) |
| 119 | require.NoError(s.T(), err) |
| 120 | err = remote.Write(ref, empty.Image, remote.WithAuthFromKeychain(s.validBackend.keychain)) |
| 121 | require.NoError(s.T(), err) |
| 122 | |
| 123 | testCases := []struct { |
| 124 | name string |
| 125 | digest string |
| 126 | wantErr bool |
| 127 | errMsg string |
| 128 | want bool |
| 129 | }{ |
| 130 | { |
| 131 | name: "empty digest", |
| 132 | digest: "", |
| 133 | wantErr: true, |
| 134 | errMsg: "digest is empty", |
| 135 | }, |
| 136 | { |
| 137 | name: "image not found", |
| 138 | digest: "deadbeef", |
| 139 | want: false, |
| 140 | }, |
| 141 | { |
| 142 | name: "image already exists", |
| 143 | digest: s.casResource.Digest, |
| 144 | want: true, |
| 145 | }, |
| 146 | { |
| 147 | name: "image exists but not uploaded by us", |
| 148 | digest: digestOthers, |
| 149 | want: false, |
| 150 | }, |
| 151 | } |
| 152 | |
| 153 | for _, tc := range testCases { |
| 154 | s.T().Run(tc.name, func(t *testing.T) { |
| 155 | g, err := s.validBackend.Exists(context.Background(), tc.digest) |
| 156 | if tc.wantErr { |
| 157 | assert.ErrorContains(err, tc.errMsg) |
| 158 | } else { |
| 159 | assert.NoError(err) |
| 160 | assert.Equal(tc.want, g) |
| 161 | } |
| 162 | }) |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | func (s *testSuite) TestDescribe() { |
| 167 | testCases := []struct { |
nothing calls this directly
no test coverage detected