Fix data races in tests, closes #255

Signed-off-by: Alexei Dodon <adodon@cisco.com>
This commit is contained in:
Alexei Dodon
2021-11-10 14:31:03 +00:00
committed by Ramkumar Chinchani
parent 4d50ad2bb1
commit e900b09cfb
19 changed files with 589 additions and 975 deletions
+14 -10
View File
@@ -62,16 +62,7 @@ func (is *ImageStoreFS) RootDir() string {
}
func (is *ImageStoreFS) DirExists(d string) bool {
fi, err := os.Stat(d)
if err != nil && os.IsNotExist(err) {
return false
}
if !fi.IsDir() {
return false
}
return true
return DirExists(d)
}
func getRoutePrefix(name string) string {
@@ -1341,3 +1332,16 @@ func ifOlderThan(is *ImageStoreFS, repo string, delay time.Duration) casext.GCPo
return true, nil
}
}
func DirExists(d string) bool {
fi, err := os.Stat(d)
if err != nil && os.IsNotExist(err) {
return false
}
if !fi.IsDir() {
return false
}
return true
}
+18 -1
View File
@@ -595,7 +595,7 @@ func TestNegativeCases(t *testing.T) {
So(err, ShouldNotBeNil)
})
Convey("Invalid dedupe sceanrios", t, func() {
Convey("Invalid dedupe scenarios", t, func() {
dir, err := ioutil.TempDir("", "oci-repo-test")
if err != nil {
panic(err)
@@ -671,6 +671,23 @@ func TestNegativeCases(t *testing.T) {
So(err, ShouldBeNil)
So(b, ShouldEqual, l)
})
Convey("DirExists call with a filename as argument", t, func(c C) {
dir, err := ioutil.TempDir("", "oci-repo-test")
if err != nil {
panic(err)
}
defer os.RemoveAll(dir)
filePath := path.Join(dir, "file.txt")
err = ioutil.WriteFile(filePath, []byte("some dummy file content"), 0644) //nolint: gosec
if err != nil {
panic(err)
}
ok := storage.DirExists(filePath)
So(ok, ShouldBeFalse)
})
}
func TestHardLink(t *testing.T) {
+9
View File
@@ -475,6 +475,15 @@ func TestStorageAPIs(t *testing.T) {
indexContent, err := il.GetIndexContent("test")
So(err, ShouldBeNil)
if testcase.storageType == "fs" {
err = os.Chmod(path.Join(il.RootDir(), "test", "index.json"), 0000)
So(err, ShouldBeNil)
_, err = il.GetIndexContent("test")
So(err, ShouldNotBeNil)
err = os.Chmod(path.Join(il.RootDir(), "test", "index.json"), 0644)
So(err, ShouldBeNil)
}
var index ispec.Index
err = json.Unmarshal(indexContent, &index)