mirror of
https://github.com/project-zot/zot.git
synced 2026-06-16 04:17:55 +08:00
Fix data races in tests, closes #255
Signed-off-by: Alexei Dodon <adodon@cisco.com>
This commit is contained in:
committed by
Ramkumar Chinchani
parent
4d50ad2bb1
commit
e900b09cfb
+14
-10
@@ -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
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user