storage/s3: fix checker prefix (#1239)

This commit is contained in:
Marwan Sulaiman
2019-05-24 09:47:24 -04:00
committed by GitHub
parent acfbbb3216
commit 3779208d49
2 changed files with 32 additions and 2 deletions
+19
View File
@@ -25,6 +25,7 @@ func RunTests(t *testing.T, b storage.Backend, clearBackend func() error) {
testDelete(t, b)
testGet(t, b)
testExists(t, b)
testShouldNotExist(t, b)
testCatalog(t, b)
}
@@ -166,6 +167,24 @@ func testExists(t *testing.T, b storage.Backend) {
require.Equal(t, true, exists)
}
func testShouldNotExist(t *testing.T, b storage.Backend) {
ctx := context.Background()
mod := "shouldNotExist"
ver := "v1.2.3-pre.1"
mock := getMockModule()
zipBts, _ := ioutil.ReadAll(mock.Zip)
err := b.Save(ctx, mod, ver, mock.Mod, bytes.NewReader(zipBts), mock.Info)
require.NoError(t, err, "should successfully safe a mock module")
defer b.Delete(ctx, mod, ver)
prefixVer := "v1.2.3-pre"
exists, err := b.Exists(ctx, mod, prefixVer)
require.NoError(t, err)
if exists {
t.Fatal("a non existing version that has the same prefix of an existing version should not exist")
}
}
// testDelete tests that a module can be deleted from a
// storage Backend and the the Exists method returns false
// afterwards.
+13 -2
View File
@@ -30,6 +30,17 @@ func (s *Storage) Exists(ctx context.Context, module, version string) (bool, err
if err != nil {
return false, errors.E(op, err, errors.M(module), errors.V(version))
}
return len(loo.Contents) == 3, nil
var count int
for _, o := range loo.Contents {
// sane assumption: no duplicate keys.
switch *o.Key {
case config.PackageVersionedName(module, version, "info"):
count++
case config.PackageVersionedName(module, version, "mod"):
count++
case config.PackageVersionedName(module, version, "zip"):
count++
}
}
return count == 3, nil
}