mirror of
https://github.com/project-zot/zot.git
synced 2026-06-15 20:07:55 +08:00
test: use T.TempDir to create temporary test directory
The directory created by `T.TempDir` is automatically removed when the test and all its subtests complete. Reference: https://pkg.go.dev/testing#T.TempDir Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
This commit is contained in:
committed by
Ramkumar Chinchani
parent
4be2652085
commit
0d77b60de7
+42
-211
@@ -109,11 +109,7 @@ func TestRunAlreadyRunningServer(t *testing.T) {
|
|||||||
|
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
|
|
||||||
globalDir, err := ioutil.TempDir("", "oci-repo-test")
|
globalDir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(globalDir)
|
|
||||||
|
|
||||||
ctlr.Config.Storage.RootDirectory = globalDir
|
ctlr.Config.Storage.RootDirectory = globalDir
|
||||||
|
|
||||||
@@ -137,7 +133,7 @@ func TestRunAlreadyRunningServer(t *testing.T) {
|
|||||||
_ = ctlr.Server.Shutdown(ctx)
|
_ = ctlr.Server.Shutdown(ctx)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
err = ctlr.Run()
|
err := ctlr.Run()
|
||||||
So(err, ShouldNotBeNil)
|
So(err, ShouldNotBeNil)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -253,12 +249,7 @@ func TestHtpasswdSingleCred(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
dir, err := ioutil.TempDir("", "oci-repo-test")
|
ctlr.Config.Storage.RootDirectory = t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
ctlr.Config.Storage.RootDirectory = dir
|
|
||||||
|
|
||||||
go startServer(ctlr)
|
go startServer(ctlr)
|
||||||
defer stopServer(ctlr)
|
defer stopServer(ctlr)
|
||||||
@@ -308,12 +299,7 @@ func TestHtpasswdTwoCreds(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
dir, err := ioutil.TempDir("", "oci-repo-test")
|
ctlr.Config.Storage.RootDirectory = t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
ctlr.Config.Storage.RootDirectory = dir
|
|
||||||
|
|
||||||
go startServer(ctlr)
|
go startServer(ctlr)
|
||||||
defer stopServer(ctlr)
|
defer stopServer(ctlr)
|
||||||
@@ -364,12 +350,7 @@ func TestHtpasswdFiveCreds(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
dir, err := ioutil.TempDir("", "oci-repo-test")
|
ctlr.Config.Storage.RootDirectory = t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
ctlr.Config.Storage.RootDirectory = dir
|
|
||||||
|
|
||||||
go startServer(ctlr)
|
go startServer(ctlr)
|
||||||
defer stopServer(ctlr)
|
defer stopServer(ctlr)
|
||||||
@@ -402,12 +383,7 @@ func TestRatelimit(t *testing.T) {
|
|||||||
Rate: &rate,
|
Rate: &rate,
|
||||||
}
|
}
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
dir, err := ioutil.TempDir("", "oci-repo-test")
|
ctlr.Config.Storage.RootDirectory = t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
ctlr.Config.Storage.RootDirectory = dir
|
|
||||||
|
|
||||||
go startServer(ctlr)
|
go startServer(ctlr)
|
||||||
defer stopServer(ctlr)
|
defer stopServer(ctlr)
|
||||||
@@ -443,12 +419,7 @@ func TestRatelimit(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
dir, err := ioutil.TempDir("", "oci-repo-test")
|
ctlr.Config.Storage.RootDirectory = t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
ctlr.Config.Storage.RootDirectory = dir
|
|
||||||
|
|
||||||
go startServer(ctlr)
|
go startServer(ctlr)
|
||||||
defer stopServer(ctlr)
|
defer stopServer(ctlr)
|
||||||
@@ -485,12 +456,7 @@ func TestRatelimit(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
dir, err := ioutil.TempDir("", "oci-repo-test")
|
ctlr.Config.Storage.RootDirectory = t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
ctlr.Config.Storage.RootDirectory = dir
|
|
||||||
|
|
||||||
go startServer(ctlr)
|
go startServer(ctlr)
|
||||||
defer stopServer(ctlr)
|
defer stopServer(ctlr)
|
||||||
@@ -526,12 +492,7 @@ func TestBasicAuth(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
dir, err := ioutil.TempDir("", "oci-repo-test")
|
ctlr.Config.Storage.RootDirectory = t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
ctlr.Config.Storage.RootDirectory = dir
|
|
||||||
|
|
||||||
go startServer(ctlr)
|
go startServer(ctlr)
|
||||||
defer stopServer(ctlr)
|
defer stopServer(ctlr)
|
||||||
@@ -565,13 +526,7 @@ func TestInterruptedBlobUpload(t *testing.T) {
|
|||||||
conf.HTTP.Port = port
|
conf.HTTP.Port = port
|
||||||
|
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
dir, err := ioutil.TempDir("", "oci-repo-test")
|
ctlr.Config.Storage.RootDirectory = t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
ctlr.Config.Storage.RootDirectory = dir
|
|
||||||
|
|
||||||
go startServer(ctlr)
|
go startServer(ctlr)
|
||||||
defer stopServer(ctlr)
|
defer stopServer(ctlr)
|
||||||
@@ -805,17 +760,8 @@ func TestMultipleInstance(t *testing.T) {
|
|||||||
err := ctlr.Run()
|
err := ctlr.Run()
|
||||||
So(err, ShouldEqual, errors.ErrImgStoreNotFound)
|
So(err, ShouldEqual, errors.ErrImgStoreNotFound)
|
||||||
|
|
||||||
globalDir, err := ioutil.TempDir("", "oci-repo-test")
|
globalDir := t.TempDir()
|
||||||
if err != nil {
|
subDir := t.TempDir()
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(globalDir)
|
|
||||||
|
|
||||||
subDir, err := ioutil.TempDir("", "oci-sub-test")
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(subDir)
|
|
||||||
|
|
||||||
ctlr.Config.Storage.RootDirectory = globalDir
|
ctlr.Config.Storage.RootDirectory = globalDir
|
||||||
subPathMap := make(map[string]config.StorageConfig)
|
subPathMap := make(map[string]config.StorageConfig)
|
||||||
@@ -848,17 +794,8 @@ func TestMultipleInstance(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
globalDir, err := ioutil.TempDir("", "oci-repo-test")
|
globalDir := t.TempDir()
|
||||||
if err != nil {
|
subDir := t.TempDir()
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(globalDir)
|
|
||||||
|
|
||||||
subDir, err := ioutil.TempDir("", "oci-sub-test")
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(subDir)
|
|
||||||
|
|
||||||
ctlr.Config.Storage.RootDirectory = globalDir
|
ctlr.Config.Storage.RootDirectory = globalDir
|
||||||
subPathMap := make(map[string]config.StorageConfig)
|
subPathMap := make(map[string]config.StorageConfig)
|
||||||
@@ -916,12 +853,7 @@ func TestTLSWithBasicAuth(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
dir, err := ioutil.TempDir("", "oci-repo-test")
|
ctlr.Config.Storage.RootDirectory = t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
ctlr.Config.Storage.RootDirectory = dir
|
|
||||||
|
|
||||||
go startServer(ctlr)
|
go startServer(ctlr)
|
||||||
defer stopServer(ctlr)
|
defer stopServer(ctlr)
|
||||||
@@ -982,12 +914,7 @@ func TestTLSWithBasicAuthAllowReadAccess(t *testing.T) {
|
|||||||
conf.HTTP.AllowReadAccess = true
|
conf.HTTP.AllowReadAccess = true
|
||||||
|
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
dir, err := ioutil.TempDir("", "oci-repo-test")
|
ctlr.Config.Storage.RootDirectory = t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
ctlr.Config.Storage.RootDirectory = dir
|
|
||||||
|
|
||||||
go startServer(ctlr)
|
go startServer(ctlr)
|
||||||
defer stopServer(ctlr)
|
defer stopServer(ctlr)
|
||||||
@@ -1042,12 +969,7 @@ func TestTLSMutualAuth(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
dir, err := ioutil.TempDir("", "oci-repo-test")
|
ctlr.Config.Storage.RootDirectory = t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
ctlr.Config.Storage.RootDirectory = dir
|
|
||||||
|
|
||||||
go startServer(ctlr)
|
go startServer(ctlr)
|
||||||
defer stopServer(ctlr)
|
defer stopServer(ctlr)
|
||||||
@@ -1115,12 +1037,7 @@ func TestTLSMutualAuthAllowReadAccess(t *testing.T) {
|
|||||||
conf.HTTP.AllowReadAccess = true
|
conf.HTTP.AllowReadAccess = true
|
||||||
|
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
dir, err := ioutil.TempDir("", "oci-repo-test")
|
ctlr.Config.Storage.RootDirectory = t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
ctlr.Config.Storage.RootDirectory = dir
|
|
||||||
|
|
||||||
go startServer(ctlr)
|
go startServer(ctlr)
|
||||||
defer stopServer(ctlr)
|
defer stopServer(ctlr)
|
||||||
@@ -1201,12 +1118,7 @@ func TestTLSMutualAndBasicAuth(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
dir, err := ioutil.TempDir("", "oci-repo-test")
|
ctlr.Config.Storage.RootDirectory = t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
ctlr.Config.Storage.RootDirectory = dir
|
|
||||||
|
|
||||||
go startServer(ctlr)
|
go startServer(ctlr)
|
||||||
defer stopServer(ctlr)
|
defer stopServer(ctlr)
|
||||||
@@ -1284,12 +1196,7 @@ func TestTLSMutualAndBasicAuthAllowReadAccess(t *testing.T) {
|
|||||||
conf.HTTP.AllowReadAccess = true
|
conf.HTTP.AllowReadAccess = true
|
||||||
|
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
dir, err := ioutil.TempDir("", "oci-repo-test")
|
ctlr.Config.Storage.RootDirectory = t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
ctlr.Config.Storage.RootDirectory = dir
|
|
||||||
|
|
||||||
go startServer(ctlr)
|
go startServer(ctlr)
|
||||||
defer stopServer(ctlr)
|
defer stopServer(ctlr)
|
||||||
@@ -1443,12 +1350,7 @@ func TestBasicAuthWithLDAP(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
dir, err := ioutil.TempDir("", "oci-repo-test")
|
ctlr.Config.Storage.RootDirectory = t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
ctlr.Config.Storage.RootDirectory = dir
|
|
||||||
|
|
||||||
go startServer(ctlr)
|
go startServer(ctlr)
|
||||||
defer stopServer(ctlr)
|
defer stopServer(ctlr)
|
||||||
@@ -1532,10 +1434,7 @@ func TestBearerAuth(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
dir, err := ioutil.TempDir("", "oci-repo-test")
|
ctlr.Config.Storage.RootDirectory = t.TempDir()
|
||||||
So(err, ShouldBeNil)
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
ctlr.Config.Storage.RootDirectory = dir
|
|
||||||
|
|
||||||
go startServer(ctlr)
|
go startServer(ctlr)
|
||||||
defer stopServer(ctlr)
|
defer stopServer(ctlr)
|
||||||
@@ -1699,10 +1598,7 @@ func TestBearerAuthWithAllowReadAccess(t *testing.T) {
|
|||||||
}
|
}
|
||||||
conf.HTTP.AllowReadAccess = true
|
conf.HTTP.AllowReadAccess = true
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
dir, err := ioutil.TempDir("", "oci-repo-test")
|
ctlr.Config.Storage.RootDirectory = t.TempDir()
|
||||||
So(err, ShouldBeNil)
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
ctlr.Config.Storage.RootDirectory = dir
|
|
||||||
|
|
||||||
go startServer(ctlr)
|
go startServer(ctlr)
|
||||||
defer stopServer(ctlr)
|
defer stopServer(ctlr)
|
||||||
@@ -1931,12 +1827,8 @@ func TestAuthorizationWithBasicAuth(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
dir, err := ioutil.TempDir("", "oci-repo-test")
|
dir := t.TempDir()
|
||||||
if err != nil {
|
err := test.CopyFiles("../../test/data", dir)
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
err = test.CopyFiles("../../test/data", dir)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@@ -2459,12 +2351,7 @@ func TestHTTPReadOnly(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
dir, err := ioutil.TempDir("", "oci-repo-test")
|
ctlr.Config.Storage.RootDirectory = t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
ctlr.Config.Storage.RootDirectory = dir
|
|
||||||
|
|
||||||
go startServer(ctlr)
|
go startServer(ctlr)
|
||||||
defer stopServer(ctlr)
|
defer stopServer(ctlr)
|
||||||
@@ -2476,7 +2363,7 @@ func TestHTTPReadOnly(t *testing.T) {
|
|||||||
So(resp.StatusCode(), ShouldEqual, http.StatusOK)
|
So(resp.StatusCode(), ShouldEqual, http.StatusOK)
|
||||||
|
|
||||||
// with creds, any modifications should still fail on read-only mode
|
// with creds, any modifications should still fail on read-only mode
|
||||||
resp, err = resty.R().SetBasicAuth(user, password).
|
resp, err := resty.R().SetBasicAuth(user, password).
|
||||||
Post(baseURL + "/v2/" + AuthorizedNamespace + "/blobs/uploads/")
|
Post(baseURL + "/v2/" + AuthorizedNamespace + "/blobs/uploads/")
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
So(resp, ShouldNotBeNil)
|
So(resp, ShouldNotBeNil)
|
||||||
@@ -2510,16 +2397,12 @@ func TestCrossRepoMount(t *testing.T) {
|
|||||||
|
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
|
|
||||||
dir, err := ioutil.TempDir("", "oci-repo-test")
|
dir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
err = test.CopyFiles("../../test/data", dir)
|
err := test.CopyFiles("../../test/data", dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
ctlr.Config.Storage.RootDirectory = dir
|
ctlr.Config.Storage.RootDirectory = dir
|
||||||
|
|
||||||
go startServer(ctlr)
|
go startServer(ctlr)
|
||||||
@@ -2694,16 +2577,12 @@ func TestCrossRepoMount(t *testing.T) {
|
|||||||
|
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
|
|
||||||
dir, err := ioutil.TempDir("", "oci-repo-test")
|
dir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
err = test.CopyFiles("../../test/data", dir)
|
err := test.CopyFiles("../../test/data", dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
|
|
||||||
ctlr.Config.Storage.RootDirectory = dir
|
ctlr.Config.Storage.RootDirectory = dir
|
||||||
ctlr.Config.Storage.Dedupe = false
|
ctlr.Config.Storage.Dedupe = false
|
||||||
@@ -2836,32 +2715,9 @@ func TestParallelRequests(t *testing.T) {
|
|||||||
|
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
|
|
||||||
dir, err := ioutil.TempDir("", "oci-repo-test")
|
dir := t.TempDir()
|
||||||
if err != nil {
|
firstSubDir := t.TempDir()
|
||||||
panic(err)
|
secondSubDir := t.TempDir()
|
||||||
}
|
|
||||||
|
|
||||||
t.Cleanup(func() {
|
|
||||||
os.RemoveAll(dir)
|
|
||||||
})
|
|
||||||
|
|
||||||
firstSubDir, err := ioutil.TempDir("", "oci-sub-dir")
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
t.Cleanup(func() {
|
|
||||||
os.RemoveAll(firstSubDir)
|
|
||||||
})
|
|
||||||
|
|
||||||
secondSubDir, err := ioutil.TempDir("", "oci-sub-dir")
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
t.Cleanup(func() {
|
|
||||||
os.RemoveAll(secondSubDir)
|
|
||||||
})
|
|
||||||
|
|
||||||
subPaths := make(map[string]config.StorageConfig)
|
subPaths := make(map[string]config.StorageConfig)
|
||||||
|
|
||||||
@@ -3079,22 +2935,14 @@ func TestHardLink(t *testing.T) {
|
|||||||
|
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
|
|
||||||
dir, err := ioutil.TempDir("", "hard-link-test")
|
dir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
|
|
||||||
err = os.Chmod(dir, 0o400)
|
err := os.Chmod(dir, 0o400)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
subDir, err := ioutil.TempDir("", "sub-hardlink-test")
|
subDir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(subDir)
|
|
||||||
|
|
||||||
err = os.Chmod(subDir, 0o400)
|
err = os.Chmod(subDir, 0o400)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -3135,11 +2983,7 @@ func TestImageSignatures(t *testing.T) {
|
|||||||
conf.HTTP.Port = port
|
conf.HTTP.Port = port
|
||||||
|
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
dir, err := ioutil.TempDir("", "oci-repo-test")
|
dir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
ctlr.Config.Storage.RootDirectory = dir
|
ctlr.Config.Storage.RootDirectory = dir
|
||||||
go func(controller *api.Controller) {
|
go func(controller *api.Controller) {
|
||||||
// this blocks
|
// this blocks
|
||||||
@@ -3235,9 +3079,7 @@ func TestImageSignatures(t *testing.T) {
|
|||||||
cwd, err := os.Getwd()
|
cwd, err := os.Getwd()
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
defer func() { _ = os.Chdir(cwd) }()
|
defer func() { _ = os.Chdir(cwd) }()
|
||||||
tdir, err := ioutil.TempDir("", "cosign")
|
tdir := t.TempDir()
|
||||||
So(err, ShouldBeNil)
|
|
||||||
defer os.RemoveAll(tdir)
|
|
||||||
_ = os.Chdir(tdir)
|
_ = os.Chdir(tdir)
|
||||||
|
|
||||||
// generate a keypair
|
// generate a keypair
|
||||||
@@ -3321,9 +3163,7 @@ func TestImageSignatures(t *testing.T) {
|
|||||||
cwd, err := os.Getwd()
|
cwd, err := os.Getwd()
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
defer func() { _ = os.Chdir(cwd) }()
|
defer func() { _ = os.Chdir(cwd) }()
|
||||||
tdir, err := ioutil.TempDir("", "notation")
|
tdir := t.TempDir()
|
||||||
So(err, ShouldBeNil)
|
|
||||||
defer os.RemoveAll(tdir)
|
|
||||||
_ = os.Chdir(tdir)
|
_ = os.Chdir(tdir)
|
||||||
|
|
||||||
// "notation" (notaryv2) doesn't yet support exported apis, so use the binary instead
|
// "notation" (notaryv2) doesn't yet support exported apis, so use the binary instead
|
||||||
@@ -3474,12 +3314,7 @@ func TestRouteFailures(t *testing.T) {
|
|||||||
conf.HTTP.Port = port
|
conf.HTTP.Port = port
|
||||||
|
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
dir, err := ioutil.TempDir("", "oci-repo-test")
|
ctlr.Config.Storage.RootDirectory = t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
ctlr.Config.Storage.RootDirectory = dir
|
|
||||||
ctlr.Config.Storage.Commit = true
|
ctlr.Config.Storage.Commit = true
|
||||||
|
|
||||||
go startServer(ctlr)
|
go startServer(ctlr)
|
||||||
@@ -4061,11 +3896,7 @@ func TestStorageCommit(t *testing.T) {
|
|||||||
conf.HTTP.Port = port
|
conf.HTTP.Port = port
|
||||||
|
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
dir, err := ioutil.TempDir("", "oci-repo-test")
|
dir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
ctlr.Config.Storage.RootDirectory = dir
|
ctlr.Config.Storage.RootDirectory = dir
|
||||||
ctlr.Config.Storage.Commit = true
|
ctlr.Config.Storage.Commit = true
|
||||||
|
|
||||||
|
|||||||
+4
-24
@@ -69,12 +69,7 @@ func TestTLSWithAuth(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
dir, err := ioutil.TempDir("", "oci-repo-test")
|
ctlr.Config.Storage.RootDirectory = t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
ctlr.Config.Storage.RootDirectory = dir
|
|
||||||
go func() {
|
go func() {
|
||||||
// this blocks
|
// this blocks
|
||||||
if err := ctlr.Run(); err != nil {
|
if err := ctlr.Run(); err != nil {
|
||||||
@@ -166,12 +161,7 @@ func TestTLSWithoutAuth(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
dir, err := ioutil.TempDir("", "oci-repo-test")
|
ctlr.Config.Storage.RootDirectory = t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
ctlr.Config.Storage.RootDirectory = dir
|
|
||||||
go func() {
|
go func() {
|
||||||
// this blocks
|
// this blocks
|
||||||
if err := ctlr.Run(); err != nil {
|
if err := ctlr.Run(); err != nil {
|
||||||
@@ -234,12 +224,7 @@ func TestTLSWithoutAuth(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
dir, err := ioutil.TempDir("", "oci-repo-test")
|
ctlr.Config.Storage.RootDirectory = t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
ctlr.Config.Storage.RootDirectory = dir
|
|
||||||
go func() {
|
go func() {
|
||||||
// this blocks
|
// this blocks
|
||||||
if err := ctlr.Run(); err != nil {
|
if err := ctlr.Run(); err != nil {
|
||||||
@@ -297,12 +282,7 @@ func TestTLSBadCerts(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
dir, err := ioutil.TempDir("", "oci-repo-test")
|
ctlr.Config.Storage.RootDirectory = t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
ctlr.Config.Storage.RootDirectory = dir
|
|
||||||
go func() {
|
go func() {
|
||||||
// this blocks
|
// this blocks
|
||||||
if err := ctlr.Run(); err != nil {
|
if err := ctlr.Run(); err != nil {
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"regexp"
|
"regexp"
|
||||||
@@ -291,18 +290,13 @@ func TestServerCVEResponse(t *testing.T) {
|
|||||||
conf := config.New()
|
conf := config.New()
|
||||||
conf.HTTP.Port = port
|
conf.HTTP.Port = port
|
||||||
|
|
||||||
dir, err := ioutil.TempDir("", "oci-repo-test")
|
dir := t.TempDir()
|
||||||
|
|
||||||
|
err := test.CopyFiles("../../test/data/zot-cve-test", path.Join(dir, "zot-cve-test"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = test.CopyFiles("../../test/data/zot-cve-test", path.Join(dir, "zot-cve-test"))
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
|
|
||||||
conf.Storage.RootDirectory = dir
|
conf.Storage.RootDirectory = dir
|
||||||
cveConfig := &extconf.CVEConfig{
|
cveConfig := &extconf.CVEConfig{
|
||||||
UpdateInterval: 2,
|
UpdateInterval: 2,
|
||||||
|
|||||||
@@ -291,13 +291,7 @@ func TestServerResponse(t *testing.T) {
|
|||||||
Search: &extconf.SearchConfig{Enable: &defaultVal},
|
Search: &extconf.SearchConfig{Enable: &defaultVal},
|
||||||
}
|
}
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
dir, err := ioutil.TempDir("", "oci-repo-test")
|
ctlr.Config.Storage.RootDirectory = t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
|
|
||||||
ctlr.Config.Storage.RootDirectory = dir
|
|
||||||
go func(controller *api.Controller) {
|
go func(controller *api.Controller) {
|
||||||
// this blocks
|
// this blocks
|
||||||
if err := controller.Run(); err != nil {
|
if err := controller.Run(); err != nil {
|
||||||
@@ -329,7 +323,7 @@ func TestServerResponse(t *testing.T) {
|
|||||||
cmd.SetOut(buff)
|
cmd.SetOut(buff)
|
||||||
cmd.SetErr(buff)
|
cmd.SetErr(buff)
|
||||||
cmd.SetArgs(args)
|
cmd.SetArgs(args)
|
||||||
err = cmd.Execute()
|
err := cmd.Execute()
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
space := regexp.MustCompile(`\s+`)
|
space := regexp.MustCompile(`\s+`)
|
||||||
str := space.ReplaceAllString(buff.String(), " ")
|
str := space.ReplaceAllString(buff.String(), " ")
|
||||||
@@ -348,7 +342,7 @@ func TestServerResponse(t *testing.T) {
|
|||||||
cmd.SetOut(buff)
|
cmd.SetOut(buff)
|
||||||
cmd.SetErr(buff)
|
cmd.SetErr(buff)
|
||||||
cmd.SetArgs(args)
|
cmd.SetArgs(args)
|
||||||
err = cmd.Execute()
|
err := cmd.Execute()
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
space := regexp.MustCompile(`\s+`)
|
space := regexp.MustCompile(`\s+`)
|
||||||
str := space.ReplaceAllString(buff.String(), " ")
|
str := space.ReplaceAllString(buff.String(), " ")
|
||||||
@@ -373,7 +367,7 @@ func TestServerResponse(t *testing.T) {
|
|||||||
cmd.SetOut(buff)
|
cmd.SetOut(buff)
|
||||||
cmd.SetErr(buff)
|
cmd.SetErr(buff)
|
||||||
cmd.SetArgs(args)
|
cmd.SetArgs(args)
|
||||||
err = cmd.Execute()
|
err := cmd.Execute()
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
space := regexp.MustCompile(`\s+`)
|
space := regexp.MustCompile(`\s+`)
|
||||||
str := space.ReplaceAllString(buff.String(), " ")
|
str := space.ReplaceAllString(buff.String(), " ")
|
||||||
@@ -411,7 +405,7 @@ func TestServerResponse(t *testing.T) {
|
|||||||
cmd.SetOut(buff)
|
cmd.SetOut(buff)
|
||||||
cmd.SetErr(buff)
|
cmd.SetErr(buff)
|
||||||
cmd.SetArgs(args)
|
cmd.SetArgs(args)
|
||||||
err = cmd.Execute()
|
err := cmd.Execute()
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
space := regexp.MustCompile(`\s+`)
|
space := regexp.MustCompile(`\s+`)
|
||||||
str := space.ReplaceAllString(buff.String(), " ")
|
str := space.ReplaceAllString(buff.String(), " ")
|
||||||
@@ -452,7 +446,7 @@ func TestServerResponse(t *testing.T) {
|
|||||||
cmd.SetOut(buff)
|
cmd.SetOut(buff)
|
||||||
cmd.SetErr(buff)
|
cmd.SetErr(buff)
|
||||||
cmd.SetArgs(args)
|
cmd.SetArgs(args)
|
||||||
err = cmd.Execute()
|
err := cmd.Execute()
|
||||||
So(err, ShouldNotBeNil)
|
So(err, ShouldNotBeNil)
|
||||||
actual := buff.String()
|
actual := buff.String()
|
||||||
So(actual, ShouldContainSubstring, "unknown")
|
So(actual, ShouldContainSubstring, "unknown")
|
||||||
|
|||||||
+2
-11
@@ -398,12 +398,7 @@ func TestScrub(t *testing.T) {
|
|||||||
config.HTTP.Port = port
|
config.HTTP.Port = port
|
||||||
controller := api.NewController(config)
|
controller := api.NewController(config)
|
||||||
|
|
||||||
dir, err := ioutil.TempDir("", "scrub-test")
|
dir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
|
|
||||||
controller.Config.Storage.RootDirectory = dir
|
controller.Config.Storage.RootDirectory = dir
|
||||||
go func(controller *api.Controller) {
|
go func(controller *api.Controller) {
|
||||||
@@ -480,11 +475,7 @@ func TestScrub(t *testing.T) {
|
|||||||
Convey("bad index.json", func(c C) {
|
Convey("bad index.json", func(c C) {
|
||||||
port := GetFreePort()
|
port := GetFreePort()
|
||||||
|
|
||||||
dir, err := ioutil.TempDir("", "scrub-test")
|
dir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
|
|
||||||
repoName := "badIndex"
|
repoName := "badIndex"
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package v1_0_0_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -25,7 +24,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestWorkflows(t *testing.T) {
|
func TestWorkflows(t *testing.T) {
|
||||||
ctrl, randomPort := startServer()
|
ctrl, randomPort := startServer(t)
|
||||||
defer stopServer(ctrl)
|
defer stopServer(ctrl)
|
||||||
|
|
||||||
storageInfo := []string{defaultDir, firstDir, secondDir}
|
storageInfo := []string{defaultDir, firstDir, secondDir}
|
||||||
@@ -38,7 +37,7 @@ func TestWorkflows(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestWorkflowsOutputJSON(t *testing.T) {
|
func TestWorkflowsOutputJSON(t *testing.T) {
|
||||||
ctrl, randomPort := startServer()
|
ctrl, randomPort := startServer(t)
|
||||||
defer stopServer(ctrl)
|
defer stopServer(ctrl)
|
||||||
|
|
||||||
storageInfo := []string{defaultDir, firstDir, secondDir}
|
storageInfo := []string{defaultDir, firstDir, secondDir}
|
||||||
@@ -52,7 +51,9 @@ func TestWorkflowsOutputJSON(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// start local server on random open port.
|
// start local server on random open port.
|
||||||
func startServer() (*api.Controller, string) {
|
func startServer(t *testing.T) (*api.Controller, string) {
|
||||||
|
t.Helper()
|
||||||
|
|
||||||
port := GetFreePort()
|
port := GetFreePort()
|
||||||
baseURL := GetBaseURL(port)
|
baseURL := GetBaseURL(port)
|
||||||
conf := config.New()
|
conf := config.New()
|
||||||
@@ -60,25 +61,13 @@ func startServer() (*api.Controller, string) {
|
|||||||
conf.HTTP.Port = port
|
conf.HTTP.Port = port
|
||||||
ctrl := api.NewController(conf)
|
ctrl := api.NewController(conf)
|
||||||
|
|
||||||
dir, err := ioutil.TempDir("", "oci-repo-test")
|
dir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
defaultDir = dir
|
defaultDir = dir
|
||||||
|
|
||||||
firstSubDir, err := ioutil.TempDir("", "oci-repo-test")
|
firstSubDir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
firstDir = firstSubDir
|
firstDir = firstSubDir
|
||||||
|
|
||||||
secondSubDir, err := ioutil.TempDir("", "oci-repo-test")
|
secondSubDir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
secondDir = secondSubDir
|
secondDir = secondSubDir
|
||||||
|
|
||||||
subPaths := make(map[string]config.StorageConfig)
|
subPaths := make(map[string]config.StorageConfig)
|
||||||
|
|||||||
@@ -8,10 +8,8 @@ import (
|
|||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"math/big"
|
"math/big"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -85,8 +83,7 @@ func TestNewExporter(t *testing.T) {
|
|||||||
exporterPort := GetFreePort()
|
exporterPort := GetFreePort()
|
||||||
serverPort := GetFreePort()
|
serverPort := GetFreePort()
|
||||||
exporterConfig.Exporter.Port = exporterPort
|
exporterConfig.Exporter.Port = exporterPort
|
||||||
dir, _ := ioutil.TempDir("", "metrics")
|
exporterConfig.Exporter.Metrics.Path = strings.TrimPrefix(t.TempDir(), "/tmp/")
|
||||||
exporterConfig.Exporter.Metrics.Path = strings.TrimPrefix(dir, "/tmp/")
|
|
||||||
exporterConfig.Server.Port = serverPort
|
exporterConfig.Server.Port = serverPort
|
||||||
exporterController := api.NewController(exporterConfig)
|
exporterController := api.NewController(exporterConfig)
|
||||||
|
|
||||||
@@ -126,9 +123,7 @@ func TestNewExporter(t *testing.T) {
|
|||||||
serverController := zotapi.NewController(servercConfig)
|
serverController := zotapi.NewController(servercConfig)
|
||||||
So(serverController, ShouldNotBeNil)
|
So(serverController, ShouldNotBeNil)
|
||||||
|
|
||||||
dir, err := ioutil.TempDir("", "exporter-test")
|
dir := t.TempDir()
|
||||||
So(err, ShouldBeNil)
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
serverController.Config.Storage.RootDirectory = dir
|
serverController.Config.Storage.RootDirectory = dir
|
||||||
go func(c *zotapi.Controller) {
|
go func(c *zotapi.Controller) {
|
||||||
// this blocks
|
// this blocks
|
||||||
|
|||||||
@@ -5,9 +5,7 @@ package monitoring_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
|
||||||
"path"
|
"path"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@@ -28,11 +26,7 @@ func TestExtensionMetrics(t *testing.T) {
|
|||||||
conf := config.New()
|
conf := config.New()
|
||||||
conf.HTTP.Port = port
|
conf.HTTP.Port = port
|
||||||
|
|
||||||
rootDir, err := ioutil.TempDir("", "metrics-test")
|
rootDir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(rootDir)
|
|
||||||
|
|
||||||
conf.Storage.RootDirectory = rootDir
|
conf.Storage.RootDirectory = rootDir
|
||||||
conf.Extensions = &extconf.ExtensionConfig{}
|
conf.Extensions = &extconf.ExtensionConfig{}
|
||||||
@@ -61,7 +55,7 @@ func TestExtensionMetrics(t *testing.T) {
|
|||||||
monitoring.IncDownloadCounter(ctlr.Metrics, "alpine")
|
monitoring.IncDownloadCounter(ctlr.Metrics, "alpine")
|
||||||
monitoring.IncUploadCounter(ctlr.Metrics, "alpine")
|
monitoring.IncUploadCounter(ctlr.Metrics, "alpine")
|
||||||
|
|
||||||
err = test.CopyFiles("../../../test/data/zot-test", path.Join(rootDir, "alpine"))
|
err := test.CopyFiles("../../../test/data/zot-test", path.Join(rootDir, "alpine"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@@ -88,13 +82,7 @@ func TestExtensionMetrics(t *testing.T) {
|
|||||||
conf := config.New()
|
conf := config.New()
|
||||||
conf.HTTP.Port = port
|
conf.HTTP.Port = port
|
||||||
|
|
||||||
rootDir, err := ioutil.TempDir("", "metrics-test")
|
conf.Storage.RootDirectory = t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(rootDir)
|
|
||||||
|
|
||||||
conf.Storage.RootDirectory = rootDir
|
|
||||||
conf.Extensions = &extconf.ExtensionConfig{}
|
conf.Extensions = &extconf.ExtensionConfig{}
|
||||||
var disabled bool
|
var disabled bool
|
||||||
conf.Extensions.Metrics = &extconf.MetricsConfig{Enable: &disabled}
|
conf.Extensions.Metrics = &extconf.MetricsConfig{Enable: &disabled}
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ package common_test
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -66,22 +65,17 @@ type ImageInfo struct {
|
|||||||
Labels string
|
Labels string
|
||||||
}
|
}
|
||||||
|
|
||||||
func testSetup() error {
|
func testSetup(t *testing.T) error {
|
||||||
dir, err := ioutil.TempDir("", "search_test")
|
t.Helper()
|
||||||
if err != nil {
|
dir := t.TempDir()
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
subDir, err := ioutil.TempDir("", "sub_search_test")
|
subDir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
rootDir = dir
|
rootDir = dir
|
||||||
|
|
||||||
subRootDir = subDir
|
subRootDir = subDir
|
||||||
|
|
||||||
err = CopyFiles("../../../../test/data", rootDir)
|
err := CopyFiles("../../../../test/data", rootDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -184,7 +178,7 @@ func TestImageFormat(t *testing.T) {
|
|||||||
|
|
||||||
func TestLatestTagSearchHTTP(t *testing.T) {
|
func TestLatestTagSearchHTTP(t *testing.T) {
|
||||||
Convey("Test latest image search by timestamp", t, func() {
|
Convey("Test latest image search by timestamp", t, func() {
|
||||||
err := testSetup()
|
err := testSetup(t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@@ -322,7 +316,7 @@ func TestLatestTagSearchHTTP(t *testing.T) {
|
|||||||
|
|
||||||
func TestExpandedRepoInfo(t *testing.T) {
|
func TestExpandedRepoInfo(t *testing.T) {
|
||||||
Convey("Test expanded repo info", t, func() {
|
Convey("Test expanded repo info", t, func() {
|
||||||
err := testSetup()
|
err := testSetup(t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@@ -512,17 +506,9 @@ func TestUtilsMethod(t *testing.T) {
|
|||||||
|
|
||||||
log := log.NewLogger("debug", "")
|
log := log.NewLogger("debug", "")
|
||||||
|
|
||||||
rootDir, err := ioutil.TempDir("", "common_utils_test")
|
rootDir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(rootDir)
|
|
||||||
|
|
||||||
subRootDir, err := ioutil.TempDir("", "common_utils_test")
|
subRootDir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(subRootDir)
|
|
||||||
|
|
||||||
metrics := monitoring.NewMetricsServer(false, log)
|
metrics := monitoring.NewMetricsServer(false, log)
|
||||||
defaultStore := storage.NewImageStore(rootDir, false, storage.DefaultGCDelay, false, false, log, metrics)
|
defaultStore := storage.NewImageStore(rootDir, false, storage.DefaultGCDelay, false, false, log, metrics)
|
||||||
|
|||||||
@@ -325,23 +325,9 @@ func makeTestFile(fileName string, content string) error {
|
|||||||
func TestMultipleStoragePath(t *testing.T) {
|
func TestMultipleStoragePath(t *testing.T) {
|
||||||
Convey("Test multiple storage path", t, func() {
|
Convey("Test multiple storage path", t, func() {
|
||||||
// Create temporary directory
|
// Create temporary directory
|
||||||
firstRootDir, err := ioutil.TempDir("", "util_test")
|
firstRootDir := t.TempDir()
|
||||||
if err != nil {
|
secondRootDir := t.TempDir()
|
||||||
panic(err)
|
thirdRootDir := t.TempDir()
|
||||||
}
|
|
||||||
defer os.RemoveAll(firstRootDir)
|
|
||||||
|
|
||||||
secondRootDir, err := ioutil.TempDir("", "util_test")
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(secondRootDir)
|
|
||||||
|
|
||||||
thirdRootDir, err := ioutil.TempDir("", "util_test")
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(thirdRootDir)
|
|
||||||
|
|
||||||
log := log.NewLogger("debug", "")
|
log := log.NewLogger("debug", "")
|
||||||
metrics := monitoring.NewMetricsServer(false, log)
|
metrics := monitoring.NewMetricsServer(false, log)
|
||||||
@@ -628,19 +614,11 @@ func TestCVEConfig(t *testing.T) {
|
|||||||
|
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
|
|
||||||
firstDir, err := ioutil.TempDir("", "oci-repo-test")
|
firstDir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
secondDir, err := ioutil.TempDir("", "oci-repo-test")
|
secondDir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(firstDir)
|
|
||||||
defer os.RemoveAll(secondDir)
|
|
||||||
|
|
||||||
err = CopyFiles("../../../../test/data", path.Join(secondDir, "a"))
|
err := CopyFiles("../../../../test/data", path.Join(secondDir, "a"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -342,13 +342,11 @@ func TestDigestSearchHTTPSubPaths(t *testing.T) {
|
|||||||
func TestDigestSearchDisabled(t *testing.T) {
|
func TestDigestSearchDisabled(t *testing.T) {
|
||||||
Convey("Test disabling image search", t, func() {
|
Convey("Test disabling image search", t, func() {
|
||||||
var disabled bool
|
var disabled bool
|
||||||
dir, err := ioutil.TempDir("", "digest_test")
|
|
||||||
So(err, ShouldBeNil)
|
|
||||||
port := GetFreePort()
|
port := GetFreePort()
|
||||||
baseURL := GetBaseURL(port)
|
baseURL := GetBaseURL(port)
|
||||||
conf := config.New()
|
conf := config.New()
|
||||||
conf.HTTP.Port = port
|
conf.HTTP.Port = port
|
||||||
conf.Storage.RootDirectory = dir
|
conf.Storage.RootDirectory = t.TempDir()
|
||||||
conf.Extensions = &extconf.ExtensionConfig{
|
conf.Extensions = &extconf.ExtensionConfig{
|
||||||
Search: &extconf.SearchConfig{Enable: &disabled},
|
Search: &extconf.SearchConfig{Enable: &disabled},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,17 +58,10 @@ func TestInjectSyncUtils(t *testing.T) {
|
|||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
}
|
}
|
||||||
|
|
||||||
storageDir, err := ioutil.TempDir("", "oci-dest-repo-test")
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
defer os.RemoveAll(storageDir)
|
|
||||||
|
|
||||||
log := log.Logger{Logger: zerolog.New(os.Stdout)}
|
log := log.Logger{Logger: zerolog.New(os.Stdout)}
|
||||||
metrics := monitoring.NewMetricsServer(false, log)
|
metrics := monitoring.NewMetricsServer(false, log)
|
||||||
|
|
||||||
imageStore := storage.NewImageStore(storageDir, false, storage.DefaultGCDelay, false, false, log, metrics)
|
imageStore := storage.NewImageStore(t.TempDir(), false, storage.DefaultGCDelay, false, false, log, metrics)
|
||||||
|
|
||||||
injected = test.InjectFailure(0)
|
injected = test.InjectFailure(0)
|
||||||
_, _, err = getLocalImageRef(imageStore, testImage, testImageTag)
|
_, _, err = getLocalImageRef(imageStore, testImage, testImageTag)
|
||||||
@@ -155,19 +148,12 @@ func TestSyncInternal(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
Convey("Verify getLocalImageRef()", t, func() {
|
Convey("Verify getLocalImageRef()", t, func() {
|
||||||
storageDir, err := ioutil.TempDir("", "oci-dest-repo-test")
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
defer os.RemoveAll(storageDir)
|
|
||||||
|
|
||||||
log := log.Logger{Logger: zerolog.New(os.Stdout)}
|
log := log.Logger{Logger: zerolog.New(os.Stdout)}
|
||||||
metrics := monitoring.NewMetricsServer(false, log)
|
metrics := monitoring.NewMetricsServer(false, log)
|
||||||
|
|
||||||
imageStore := storage.NewImageStore(storageDir, false, storage.DefaultGCDelay, false, false, log, metrics)
|
imageStore := storage.NewImageStore(t.TempDir(), false, storage.DefaultGCDelay, false, false, log, metrics)
|
||||||
|
|
||||||
err = os.Chmod(imageStore.RootDir(), 0o000)
|
err := os.Chmod(imageStore.RootDir(), 0o000)
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
_, _, err = getLocalImageRef(imageStore, testImage, testImageTag)
|
_, _, err = getLocalImageRef(imageStore, testImage, testImageTag)
|
||||||
@@ -206,17 +192,12 @@ func TestSyncInternal(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
Convey("Test getHttpClient() with bad certs", t, func() {
|
Convey("Test getHttpClient() with bad certs", t, func() {
|
||||||
badCertsDir, err := ioutil.TempDir("", "bad_certs*")
|
badCertsDir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := os.WriteFile(path.Join(badCertsDir, "ca.crt"), []byte("certificate"), 0o600); err != nil {
|
if err := os.WriteFile(path.Join(badCertsDir, "ca.crt"), []byte("certificate"), 0o600); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
defer os.RemoveAll(badCertsDir)
|
|
||||||
|
|
||||||
var tlsVerify bool
|
var tlsVerify bool
|
||||||
updateDuration := time.Microsecond
|
updateDuration := time.Microsecond
|
||||||
port := test.GetFreePort()
|
port := test.GetFreePort()
|
||||||
@@ -296,18 +277,13 @@ func TestSyncInternal(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
Convey("Test canSkipImage()", t, func() {
|
Convey("Test canSkipImage()", t, func() {
|
||||||
storageDir, err := ioutil.TempDir("", "oci-dest-repo-test")
|
storageDir := t.TempDir()
|
||||||
|
|
||||||
|
err := test.CopyFiles("../../../test/data", storageDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = test.CopyFiles("../../../test/data", storageDir)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
defer os.RemoveAll(storageDir)
|
|
||||||
|
|
||||||
log := log.Logger{Logger: zerolog.New(os.Stdout)}
|
log := log.Logger{Logger: zerolog.New(os.Stdout)}
|
||||||
metrics := monitoring.NewMetricsServer(false, log)
|
metrics := monitoring.NewMetricsServer(false, log)
|
||||||
|
|
||||||
@@ -369,12 +345,7 @@ func TestSyncInternal(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
Convey("Verify pushSyncedLocalImage func", t, func() {
|
Convey("Verify pushSyncedLocalImage func", t, func() {
|
||||||
storageDir, err := ioutil.TempDir("", "oci-dest-repo-test")
|
storageDir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
defer os.RemoveAll(storageDir)
|
|
||||||
|
|
||||||
log := log.Logger{Logger: zerolog.New(os.Stdout)}
|
log := log.Logger{Logger: zerolog.New(os.Stdout)}
|
||||||
metrics := monitoring.NewMetricsServer(false, log)
|
metrics := monitoring.NewMetricsServer(false, log)
|
||||||
@@ -387,7 +358,7 @@ func TestSyncInternal(t *testing.T) {
|
|||||||
testRootDir := path.Join(imageStore.RootDir(), testImage, SyncBlobUploadDir)
|
testRootDir := path.Join(imageStore.RootDir(), testImage, SyncBlobUploadDir)
|
||||||
// testImagePath := path.Join(testRootDir, testImage)
|
// testImagePath := path.Join(testRootDir, testImage)
|
||||||
|
|
||||||
err = pushSyncedLocalImage(testImage, testImageTag, testRootDir, storeController, log)
|
err := pushSyncedLocalImage(testImage, testImageTag, testRootDir, storeController, log)
|
||||||
So(err, ShouldNotBeNil)
|
So(err, ShouldNotBeNil)
|
||||||
|
|
||||||
err = os.MkdirAll(testRootDir, 0o755)
|
err = os.MkdirAll(testRootDir, 0o755)
|
||||||
|
|||||||
@@ -93,11 +93,13 @@ func copyFile(sourceFilePath, destFilePath string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func startUpstreamServer(secure, basicAuth bool) (*api.Controller, string, string, string, *resty.Client) {
|
func startUpstreamServer(
|
||||||
|
t *testing.T, secure, basicAuth bool,
|
||||||
|
) (*api.Controller, string, string, string, *resty.Client) {
|
||||||
|
t.Helper()
|
||||||
|
|
||||||
srcPort := test.GetFreePort()
|
srcPort := test.GetFreePort()
|
||||||
|
|
||||||
srcConfig := config.New()
|
srcConfig := config.New()
|
||||||
|
|
||||||
client := resty.New()
|
client := resty.New()
|
||||||
|
|
||||||
var srcBaseURL string
|
var srcBaseURL string
|
||||||
@@ -142,12 +144,9 @@ func startUpstreamServer(secure, basicAuth bool) (*api.Controller, string, strin
|
|||||||
|
|
||||||
srcConfig.HTTP.Port = srcPort
|
srcConfig.HTTP.Port = srcPort
|
||||||
|
|
||||||
srcDir, err := ioutil.TempDir("", "oci-src-repo-test")
|
srcDir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
err = test.CopyFiles("../../../test/data", srcDir)
|
err := test.CopyFiles("../../../test/data", srcDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@@ -176,11 +175,13 @@ func startUpstreamServer(secure, basicAuth bool) (*api.Controller, string, strin
|
|||||||
return sctlr, srcBaseURL, srcDir, htpasswdPath, client
|
return sctlr, srcBaseURL, srcDir, htpasswdPath, client
|
||||||
}
|
}
|
||||||
|
|
||||||
func startDownstreamServer(secure bool, syncConfig *sync.Config) (*api.Controller, string, string, *resty.Client) {
|
func startDownstreamServer(
|
||||||
|
t *testing.T, secure bool, syncConfig *sync.Config,
|
||||||
|
) (*api.Controller, string, string, *resty.Client) {
|
||||||
|
t.Helper()
|
||||||
|
|
||||||
destPort := test.GetFreePort()
|
destPort := test.GetFreePort()
|
||||||
|
|
||||||
destConfig := config.New()
|
destConfig := config.New()
|
||||||
|
|
||||||
client := resty.New()
|
client := resty.New()
|
||||||
|
|
||||||
var destBaseURL string
|
var destBaseURL string
|
||||||
@@ -215,10 +216,7 @@ func startDownstreamServer(secure bool, syncConfig *sync.Config) (*api.Controlle
|
|||||||
|
|
||||||
destConfig.HTTP.Port = destPort
|
destConfig.HTTP.Port = destPort
|
||||||
|
|
||||||
destDir, err := ioutil.TempDir("", "oci-dest-repo-test")
|
destDir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
destConfig.Storage.RootDirectory = destDir
|
destConfig.Storage.RootDirectory = destDir
|
||||||
destConfig.Storage.Dedupe = false
|
destConfig.Storage.Dedupe = false
|
||||||
@@ -252,8 +250,7 @@ func startDownstreamServer(secure bool, syncConfig *sync.Config) (*api.Controlle
|
|||||||
|
|
||||||
func TestOnDemand(t *testing.T) {
|
func TestOnDemand(t *testing.T) {
|
||||||
Convey("Verify sync on demand feature", t, func() {
|
Convey("Verify sync on demand feature", t, func() {
|
||||||
sctlr, srcBaseURL, srcDir, _, srcClient := startUpstreamServer(false, false)
|
sctlr, srcBaseURL, _, _, srcClient := startUpstreamServer(t, false, false)
|
||||||
defer os.RemoveAll(srcDir)
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
sctlr.Shutdown()
|
sctlr.Shutdown()
|
||||||
@@ -286,8 +283,7 @@ func TestOnDemand(t *testing.T) {
|
|||||||
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
||||||
}
|
}
|
||||||
|
|
||||||
dctlr, destBaseURL, destDir, destClient := startDownstreamServer(false, syncConfig)
|
dctlr, destBaseURL, destDir, destClient := startDownstreamServer(t, false, syncConfig)
|
||||||
defer os.RemoveAll(destDir)
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
dctlr.Shutdown()
|
dctlr.Shutdown()
|
||||||
@@ -384,8 +380,7 @@ func TestPeriodically(t *testing.T) {
|
|||||||
Convey("Verify sync feature", t, func() {
|
Convey("Verify sync feature", t, func() {
|
||||||
updateDuration, _ := time.ParseDuration("30m")
|
updateDuration, _ := time.ParseDuration("30m")
|
||||||
|
|
||||||
sctlr, srcBaseURL, srcDir, _, srcClient := startUpstreamServer(false, false)
|
sctlr, srcBaseURL, _, _, srcClient := startUpstreamServer(t, false, false)
|
||||||
defer os.RemoveAll(srcDir)
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
sctlr.Shutdown()
|
sctlr.Shutdown()
|
||||||
@@ -422,8 +417,7 @@ func TestPeriodically(t *testing.T) {
|
|||||||
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
||||||
}
|
}
|
||||||
|
|
||||||
dctlr, destBaseURL, destDir, destClient := startDownstreamServer(false, syncConfig)
|
dctlr, destBaseURL, _, destClient := startDownstreamServer(t, false, syncConfig)
|
||||||
defer os.RemoveAll(destDir)
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
dctlr.Shutdown()
|
dctlr.Shutdown()
|
||||||
@@ -497,8 +491,7 @@ func TestPeriodically(t *testing.T) {
|
|||||||
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
||||||
}
|
}
|
||||||
|
|
||||||
dctlr, destBaseURL, destDir, destClient := startDownstreamServer(false, syncConfig)
|
dctlr, destBaseURL, _, destClient := startDownstreamServer(t, false, syncConfig)
|
||||||
defer os.RemoveAll(destDir)
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
dctlr.Shutdown()
|
dctlr.Shutdown()
|
||||||
@@ -560,8 +553,7 @@ func TestOnDemandPermsDenied(t *testing.T) {
|
|||||||
Convey("Verify sync on demand feature without perm on sync cache", t, func() {
|
Convey("Verify sync on demand feature without perm on sync cache", t, func() {
|
||||||
updateDuration, _ := time.ParseDuration("30m")
|
updateDuration, _ := time.ParseDuration("30m")
|
||||||
|
|
||||||
sctlr, srcBaseURL, srcDir, _, _ := startUpstreamServer(false, false)
|
sctlr, srcBaseURL, _, _, _ := startUpstreamServer(t, false, false)
|
||||||
defer os.RemoveAll(srcDir)
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
sctlr.Shutdown()
|
sctlr.Shutdown()
|
||||||
@@ -600,12 +592,7 @@ func TestOnDemandPermsDenied(t *testing.T) {
|
|||||||
|
|
||||||
destConfig.HTTP.Port = destPort
|
destConfig.HTTP.Port = destPort
|
||||||
|
|
||||||
destDir, err := ioutil.TempDir("", "oci-dest-repo-test")
|
destDir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
defer os.RemoveAll(destDir)
|
|
||||||
|
|
||||||
destConfig.Storage.RootDirectory = destDir
|
destConfig.Storage.RootDirectory = destDir
|
||||||
|
|
||||||
@@ -628,7 +615,7 @@ func TestOnDemandPermsDenied(t *testing.T) {
|
|||||||
|
|
||||||
syncSubDir := path.Join(destDir, testImage, sync.SyncBlobUploadDir)
|
syncSubDir := path.Join(destDir, testImage, sync.SyncBlobUploadDir)
|
||||||
|
|
||||||
err = os.MkdirAll(syncSubDir, 0o755)
|
err := os.MkdirAll(syncSubDir, 0o755)
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
err = os.Chmod(syncSubDir, 0o000)
|
err = os.Chmod(syncSubDir, 0o000)
|
||||||
@@ -659,8 +646,7 @@ func TestBadTLS(t *testing.T) {
|
|||||||
Convey("Verify sync TLS feature", t, func() {
|
Convey("Verify sync TLS feature", t, func() {
|
||||||
updateDuration, _ := time.ParseDuration("30m")
|
updateDuration, _ := time.ParseDuration("30m")
|
||||||
|
|
||||||
sctlr, srcBaseURL, srcDir, _, _ := startUpstreamServer(true, false)
|
sctlr, srcBaseURL, _, _, _ := startUpstreamServer(t, true, false)
|
||||||
defer os.RemoveAll(srcDir)
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
sctlr.Shutdown()
|
sctlr.Shutdown()
|
||||||
@@ -692,8 +678,7 @@ func TestBadTLS(t *testing.T) {
|
|||||||
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
||||||
}
|
}
|
||||||
|
|
||||||
dctlr, destBaseURL, destDir, destClient := startDownstreamServer(true, syncConfig)
|
dctlr, destBaseURL, _, destClient := startDownstreamServer(t, true, syncConfig)
|
||||||
defer os.RemoveAll(destDir)
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
dctlr.Shutdown()
|
dctlr.Shutdown()
|
||||||
@@ -720,8 +705,7 @@ func TestTLS(t *testing.T) {
|
|||||||
Convey("Verify sync TLS feature", t, func() {
|
Convey("Verify sync TLS feature", t, func() {
|
||||||
updateDuration, _ := time.ParseDuration("1h")
|
updateDuration, _ := time.ParseDuration("1h")
|
||||||
|
|
||||||
sctlr, srcBaseURL, srcDir, _, _ := startUpstreamServer(true, false)
|
sctlr, srcBaseURL, srcDir, _, _ := startUpstreamServer(t, true, false)
|
||||||
defer os.RemoveAll(srcDir)
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
sctlr.Shutdown()
|
sctlr.Shutdown()
|
||||||
@@ -740,10 +724,7 @@ func TestTLS(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// copy upstream client certs, use them in sync config
|
// copy upstream client certs, use them in sync config
|
||||||
destClientCertDir, err := ioutil.TempDir("", "destCerts")
|
destClientCertDir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
destFilePath := path.Join(destClientCertDir, "ca.crt")
|
destFilePath := path.Join(destClientCertDir, "ca.crt")
|
||||||
err = copyFile(CACert, destFilePath)
|
err = copyFile(CACert, destFilePath)
|
||||||
@@ -763,8 +744,6 @@ func TestTLS(t *testing.T) {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
defer os.RemoveAll(destClientCertDir)
|
|
||||||
|
|
||||||
regex := ".*"
|
regex := ".*"
|
||||||
var semver bool
|
var semver bool
|
||||||
tlsVerify := true
|
tlsVerify := true
|
||||||
@@ -791,8 +770,7 @@ func TestTLS(t *testing.T) {
|
|||||||
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
||||||
}
|
}
|
||||||
|
|
||||||
dctlr, _, destDir, _ := startDownstreamServer(true, syncConfig)
|
dctlr, _, destDir, _ := startDownstreamServer(t, true, syncConfig)
|
||||||
defer os.RemoveAll(destDir)
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
dctlr.Shutdown()
|
dctlr.Shutdown()
|
||||||
@@ -826,9 +804,8 @@ func TestBasicAuth(t *testing.T) {
|
|||||||
updateDuration, _ := time.ParseDuration("1h")
|
updateDuration, _ := time.ParseDuration("1h")
|
||||||
|
|
||||||
Convey("Verify sync basic auth with file credentials", func() {
|
Convey("Verify sync basic auth with file credentials", func() {
|
||||||
sctlr, srcBaseURL, srcDir, htpasswdPath, srcClient := startUpstreamServer(false, true)
|
sctlr, srcBaseURL, _, htpasswdPath, srcClient := startUpstreamServer(t, false, true)
|
||||||
defer os.Remove(htpasswdPath)
|
defer os.Remove(htpasswdPath)
|
||||||
defer os.RemoveAll(srcDir)
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
sctlr.Shutdown()
|
sctlr.Shutdown()
|
||||||
@@ -858,8 +835,7 @@ func TestBasicAuth(t *testing.T) {
|
|||||||
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
||||||
}
|
}
|
||||||
|
|
||||||
dctlr, destBaseURL, destDir, destClient := startDownstreamServer(false, syncConfig)
|
dctlr, destBaseURL, _, destClient := startDownstreamServer(t, false, syncConfig)
|
||||||
defer os.RemoveAll(destDir)
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
dctlr.Shutdown()
|
dctlr.Shutdown()
|
||||||
@@ -899,9 +875,8 @@ func TestBasicAuth(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
Convey("Verify sync basic auth with wrong file credentials", func() {
|
Convey("Verify sync basic auth with wrong file credentials", func() {
|
||||||
sctlr, srcBaseURL, srcDir, htpasswdPath, _ := startUpstreamServer(false, true)
|
sctlr, srcBaseURL, _, htpasswdPath, _ := startUpstreamServer(t, false, true)
|
||||||
defer os.Remove(htpasswdPath)
|
defer os.Remove(htpasswdPath)
|
||||||
defer os.RemoveAll(srcDir)
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
sctlr.Shutdown()
|
sctlr.Shutdown()
|
||||||
@@ -913,10 +888,7 @@ func TestBasicAuth(t *testing.T) {
|
|||||||
destConfig := config.New()
|
destConfig := config.New()
|
||||||
destConfig.HTTP.Port = destPort
|
destConfig.HTTP.Port = destPort
|
||||||
|
|
||||||
destDir, err := ioutil.TempDir("", "oci-dest-repo-test")
|
destDir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
destConfig.Storage.SubPaths = map[string]config.StorageConfig{
|
destConfig.Storage.SubPaths = map[string]config.StorageConfig{
|
||||||
"a": {
|
"a": {
|
||||||
@@ -927,8 +899,6 @@ func TestBasicAuth(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
defer os.RemoveAll(destDir)
|
|
||||||
|
|
||||||
destConfig.Storage.RootDirectory = destDir
|
destConfig.Storage.RootDirectory = destDir
|
||||||
|
|
||||||
regex := ".*"
|
regex := ".*"
|
||||||
@@ -996,9 +966,8 @@ func TestBasicAuth(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
Convey("Verify sync basic auth with bad file credentials", func() {
|
Convey("Verify sync basic auth with bad file credentials", func() {
|
||||||
sctlr, srcBaseURL, srcDir, htpasswdPath, _ := startUpstreamServer(false, true)
|
sctlr, srcBaseURL, _, htpasswdPath, _ := startUpstreamServer(t, false, true)
|
||||||
defer os.Remove(htpasswdPath)
|
defer os.Remove(htpasswdPath)
|
||||||
defer os.RemoveAll(srcDir)
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
sctlr.Shutdown()
|
sctlr.Shutdown()
|
||||||
@@ -1044,8 +1013,7 @@ func TestBasicAuth(t *testing.T) {
|
|||||||
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
||||||
}
|
}
|
||||||
|
|
||||||
dctlr, destBaseURL, destDir, destClient := startDownstreamServer(false, syncConfig)
|
dctlr, destBaseURL, _, destClient := startDownstreamServer(t, false, syncConfig)
|
||||||
defer os.RemoveAll(destDir)
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
dctlr.Shutdown()
|
dctlr.Shutdown()
|
||||||
@@ -1059,9 +1027,8 @@ func TestBasicAuth(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
Convey("Verify on demand sync with basic auth", func() {
|
Convey("Verify on demand sync with basic auth", func() {
|
||||||
sctlr, srcBaseURL, srcDir, htpasswdPath, srcClient := startUpstreamServer(false, true)
|
sctlr, srcBaseURL, _, htpasswdPath, srcClient := startUpstreamServer(t, false, true)
|
||||||
defer os.Remove(htpasswdPath)
|
defer os.Remove(htpasswdPath)
|
||||||
defer os.RemoveAll(srcDir)
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
sctlr.Shutdown()
|
sctlr.Shutdown()
|
||||||
@@ -1097,8 +1064,7 @@ func TestBasicAuth(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
dctlr, destBaseURL, destDir, destClient := startDownstreamServer(false, syncConfig)
|
dctlr, destBaseURL, _, destClient := startDownstreamServer(t, false, syncConfig)
|
||||||
defer os.RemoveAll(destDir)
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
dctlr.Shutdown()
|
dctlr.Shutdown()
|
||||||
@@ -1189,8 +1155,7 @@ func TestBadURL(t *testing.T) {
|
|||||||
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
||||||
}
|
}
|
||||||
|
|
||||||
dctlr, destBaseURL, destDir, destClient := startDownstreamServer(false, syncConfig)
|
dctlr, destBaseURL, _, destClient := startDownstreamServer(t, false, syncConfig)
|
||||||
defer os.RemoveAll(destDir)
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
dctlr.Shutdown()
|
dctlr.Shutdown()
|
||||||
@@ -1206,8 +1171,7 @@ func TestNoImagesByRegex(t *testing.T) {
|
|||||||
Convey("Verify sync with no images on source based on regex", t, func() {
|
Convey("Verify sync with no images on source based on regex", t, func() {
|
||||||
updateDuration, _ := time.ParseDuration("1h")
|
updateDuration, _ := time.ParseDuration("1h")
|
||||||
|
|
||||||
sctlr, srcBaseURL, srcDir, _, _ := startUpstreamServer(false, false)
|
sctlr, srcBaseURL, _, _, _ := startUpstreamServer(t, false, false)
|
||||||
defer os.RemoveAll(srcDir)
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
sctlr.Shutdown()
|
sctlr.Shutdown()
|
||||||
@@ -1237,8 +1201,7 @@ func TestNoImagesByRegex(t *testing.T) {
|
|||||||
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
||||||
}
|
}
|
||||||
|
|
||||||
dctlr, destBaseURL, destDir, destClient := startDownstreamServer(false, syncConfig)
|
dctlr, destBaseURL, _, destClient := startDownstreamServer(t, false, syncConfig)
|
||||||
defer os.RemoveAll(destDir)
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
dctlr.Shutdown()
|
dctlr.Shutdown()
|
||||||
@@ -1267,8 +1230,7 @@ func TestInvalidRegex(t *testing.T) {
|
|||||||
Convey("Verify sync with invalid regex", t, func() {
|
Convey("Verify sync with invalid regex", t, func() {
|
||||||
updateDuration, _ := time.ParseDuration("1h")
|
updateDuration, _ := time.ParseDuration("1h")
|
||||||
|
|
||||||
sctlr, srcBaseURL, srcDir, _, _ := startUpstreamServer(false, false)
|
sctlr, srcBaseURL, _, _, _ := startUpstreamServer(t, false, false)
|
||||||
defer os.RemoveAll(srcDir)
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
sctlr.Shutdown()
|
sctlr.Shutdown()
|
||||||
@@ -1299,8 +1261,7 @@ func TestInvalidRegex(t *testing.T) {
|
|||||||
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
||||||
}
|
}
|
||||||
|
|
||||||
dctlr, _, destDir, _ := startDownstreamServer(false, syncConfig)
|
dctlr, _, _, _ := startDownstreamServer(t, false, syncConfig)
|
||||||
defer os.RemoveAll(destDir)
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
dctlr.Shutdown()
|
dctlr.Shutdown()
|
||||||
@@ -1312,8 +1273,7 @@ func TestNotSemver(t *testing.T) {
|
|||||||
Convey("Verify sync feature semver compliant", t, func() {
|
Convey("Verify sync feature semver compliant", t, func() {
|
||||||
updateDuration, _ := time.ParseDuration("30m")
|
updateDuration, _ := time.ParseDuration("30m")
|
||||||
|
|
||||||
sctlr, srcBaseURL, srcDir, _, _ := startUpstreamServer(false, false)
|
sctlr, srcBaseURL, _, _, _ := startUpstreamServer(t, false, false)
|
||||||
defer os.RemoveAll(srcDir)
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
sctlr.Shutdown()
|
sctlr.Shutdown()
|
||||||
@@ -1358,8 +1318,7 @@ func TestNotSemver(t *testing.T) {
|
|||||||
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
||||||
}
|
}
|
||||||
|
|
||||||
dctlr, destBaseURL, destDir, destClient := startDownstreamServer(false, syncConfig)
|
dctlr, destBaseURL, _, destClient := startDownstreamServer(t, false, syncConfig)
|
||||||
defer os.RemoveAll(destDir)
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
dctlr.Shutdown()
|
dctlr.Shutdown()
|
||||||
@@ -1392,21 +1351,17 @@ func TestInvalidCerts(t *testing.T) {
|
|||||||
Convey("Verify sync with bad certs", t, func() {
|
Convey("Verify sync with bad certs", t, func() {
|
||||||
updateDuration, _ := time.ParseDuration("1h")
|
updateDuration, _ := time.ParseDuration("1h")
|
||||||
|
|
||||||
sctlr, srcBaseURL, srcDir, _, _ := startUpstreamServer(true, false)
|
sctlr, srcBaseURL, _, _, _ := startUpstreamServer(t, true, false)
|
||||||
defer os.RemoveAll(srcDir)
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
sctlr.Shutdown()
|
sctlr.Shutdown()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// copy client certs, use them in sync config
|
// copy client certs, use them in sync config
|
||||||
clientCertDir, err := ioutil.TempDir("", "certs")
|
clientCertDir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
destFilePath := path.Join(clientCertDir, "ca.crt")
|
destFilePath := path.Join(clientCertDir, "ca.crt")
|
||||||
err = copyFile(CACert, destFilePath)
|
err := copyFile(CACert, destFilePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@@ -1434,8 +1389,6 @@ func TestInvalidCerts(t *testing.T) {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
defer os.RemoveAll(clientCertDir)
|
|
||||||
|
|
||||||
var tlsVerify bool
|
var tlsVerify bool
|
||||||
|
|
||||||
syncRegistryConfig := sync.RegistryConfig{
|
syncRegistryConfig := sync.RegistryConfig{
|
||||||
@@ -1457,8 +1410,7 @@ func TestInvalidCerts(t *testing.T) {
|
|||||||
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
||||||
}
|
}
|
||||||
|
|
||||||
dctlr, destBaseURL, destDir, destClient := startDownstreamServer(false, syncConfig)
|
dctlr, destBaseURL, _, destClient := startDownstreamServer(t, false, syncConfig)
|
||||||
defer os.RemoveAll(destDir)
|
|
||||||
|
|
||||||
resp, err := destClient.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag)
|
resp, err := destClient.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag)
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
@@ -1515,8 +1467,7 @@ func TestInvalidUrl(t *testing.T) {
|
|||||||
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
||||||
}
|
}
|
||||||
|
|
||||||
dctlr, destBaseURL, destDir, destClient := startDownstreamServer(false, syncConfig)
|
dctlr, destBaseURL, _, destClient := startDownstreamServer(t, false, syncConfig)
|
||||||
defer os.RemoveAll(destDir)
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
dctlr.Shutdown()
|
dctlr.Shutdown()
|
||||||
@@ -1532,8 +1483,7 @@ func TestInvalidTags(t *testing.T) {
|
|||||||
Convey("Verify sync invalid tags", t, func() {
|
Convey("Verify sync invalid tags", t, func() {
|
||||||
updateDuration, _ := time.ParseDuration("30m")
|
updateDuration, _ := time.ParseDuration("30m")
|
||||||
|
|
||||||
sctlr, srcBaseURL, srcDir, _, _ := startUpstreamServer(false, false)
|
sctlr, srcBaseURL, _, _, _ := startUpstreamServer(t, false, false)
|
||||||
defer os.RemoveAll(srcDir)
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
sctlr.Shutdown()
|
sctlr.Shutdown()
|
||||||
@@ -1567,8 +1517,7 @@ func TestInvalidTags(t *testing.T) {
|
|||||||
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
||||||
}
|
}
|
||||||
|
|
||||||
dctlr, destBaseURL, destDir, destClient := startDownstreamServer(false, syncConfig)
|
dctlr, destBaseURL, _, destClient := startDownstreamServer(t, false, syncConfig)
|
||||||
defer os.RemoveAll(destDir)
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
dctlr.Shutdown()
|
dctlr.Shutdown()
|
||||||
@@ -1591,14 +1540,11 @@ func TestSubPaths(t *testing.T) {
|
|||||||
|
|
||||||
srcConfig.HTTP.Port = srcPort
|
srcConfig.HTTP.Port = srcPort
|
||||||
|
|
||||||
srcDir, err := ioutil.TempDir("", "oci-src-repo-test")
|
srcDir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
subpath := "/subpath"
|
subpath := "/subpath"
|
||||||
|
|
||||||
err = test.CopyFiles("../../../test/data", path.Join(srcDir, subpath))
|
err := test.CopyFiles("../../../test/data", path.Join(srcDir, subpath))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@@ -1658,17 +1604,9 @@ func TestSubPaths(t *testing.T) {
|
|||||||
destPort := test.GetFreePort()
|
destPort := test.GetFreePort()
|
||||||
destConfig := config.New()
|
destConfig := config.New()
|
||||||
|
|
||||||
destDir, err := ioutil.TempDir("", "oci-dest-repo-test")
|
destDir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(destDir)
|
|
||||||
|
|
||||||
subPathDestDir, err := ioutil.TempDir("", "oci-dest-subpath-repo-test")
|
subPathDestDir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(subPathDestDir)
|
|
||||||
|
|
||||||
destConfig.Storage.RootDirectory = destDir
|
destConfig.Storage.RootDirectory = destDir
|
||||||
|
|
||||||
@@ -1765,8 +1703,7 @@ func TestOnDemandRepoErr(t *testing.T) {
|
|||||||
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
||||||
}
|
}
|
||||||
|
|
||||||
dctlr, destBaseURL, destDir, _ := startDownstreamServer(false, syncConfig)
|
dctlr, destBaseURL, _, _ := startDownstreamServer(t, false, syncConfig)
|
||||||
defer os.RemoveAll(destDir)
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
dctlr.Shutdown()
|
dctlr.Shutdown()
|
||||||
@@ -1780,8 +1717,7 @@ func TestOnDemandRepoErr(t *testing.T) {
|
|||||||
|
|
||||||
func TestOnDemandContentFiltering(t *testing.T) {
|
func TestOnDemandContentFiltering(t *testing.T) {
|
||||||
Convey("Verify sync on demand feature", t, func() {
|
Convey("Verify sync on demand feature", t, func() {
|
||||||
sctlr, srcBaseURL, srcDir, _, _ := startUpstreamServer(false, false)
|
sctlr, srcBaseURL, _, _, _ := startUpstreamServer(t, false, false)
|
||||||
defer os.RemoveAll(srcDir)
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
sctlr.Shutdown()
|
sctlr.Shutdown()
|
||||||
@@ -1815,8 +1751,7 @@ func TestOnDemandContentFiltering(t *testing.T) {
|
|||||||
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
||||||
}
|
}
|
||||||
|
|
||||||
dctlr, destBaseURL, destDir, _ := startDownstreamServer(false, syncConfig)
|
dctlr, destBaseURL, _, _ := startDownstreamServer(t, false, syncConfig)
|
||||||
defer os.RemoveAll(destDir)
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
dctlr.Shutdown()
|
dctlr.Shutdown()
|
||||||
@@ -1855,8 +1790,7 @@ func TestOnDemandContentFiltering(t *testing.T) {
|
|||||||
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
||||||
}
|
}
|
||||||
|
|
||||||
dctlr, destBaseURL, destDir, _ := startDownstreamServer(false, syncConfig)
|
dctlr, destBaseURL, _, _ := startDownstreamServer(t, false, syncConfig)
|
||||||
defer os.RemoveAll(destDir)
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
dctlr.Shutdown()
|
dctlr.Shutdown()
|
||||||
@@ -1871,8 +1805,7 @@ func TestOnDemandContentFiltering(t *testing.T) {
|
|||||||
|
|
||||||
func TestConfigRules(t *testing.T) {
|
func TestConfigRules(t *testing.T) {
|
||||||
Convey("Verify sync config rules", t, func() {
|
Convey("Verify sync config rules", t, func() {
|
||||||
sctlr, srcBaseURL, srcDir, _, _ := startUpstreamServer(false, false)
|
sctlr, srcBaseURL, _, _, _ := startUpstreamServer(t, false, false)
|
||||||
defer os.RemoveAll(srcDir)
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
sctlr.Shutdown()
|
sctlr.Shutdown()
|
||||||
@@ -1905,8 +1838,7 @@ func TestConfigRules(t *testing.T) {
|
|||||||
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
||||||
}
|
}
|
||||||
|
|
||||||
dctlr, destBaseURL, destDir, _ := startDownstreamServer(false, syncConfig)
|
dctlr, destBaseURL, _, _ := startDownstreamServer(t, false, syncConfig)
|
||||||
defer os.RemoveAll(destDir)
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
dctlr.Shutdown()
|
dctlr.Shutdown()
|
||||||
@@ -1936,8 +1868,7 @@ func TestConfigRules(t *testing.T) {
|
|||||||
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
||||||
}
|
}
|
||||||
|
|
||||||
dctlr, destBaseURL, destDir, _ := startDownstreamServer(false, syncConfig)
|
dctlr, destBaseURL, _, _ := startDownstreamServer(t, false, syncConfig)
|
||||||
defer os.RemoveAll(destDir)
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
dctlr.Shutdown()
|
dctlr.Shutdown()
|
||||||
@@ -1964,8 +1895,7 @@ func TestConfigRules(t *testing.T) {
|
|||||||
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
||||||
}
|
}
|
||||||
|
|
||||||
dctlr, destBaseURL, destDir, _ := startDownstreamServer(false, syncConfig)
|
dctlr, destBaseURL, _, _ := startDownstreamServer(t, false, syncConfig)
|
||||||
defer os.RemoveAll(destDir)
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
dctlr.Shutdown()
|
dctlr.Shutdown()
|
||||||
@@ -1982,8 +1912,7 @@ func TestMultipleURLs(t *testing.T) {
|
|||||||
Convey("Verify sync feature", t, func() {
|
Convey("Verify sync feature", t, func() {
|
||||||
updateDuration, _ := time.ParseDuration("30m")
|
updateDuration, _ := time.ParseDuration("30m")
|
||||||
|
|
||||||
sctlr, srcBaseURL, srcDir, _, srcClient := startUpstreamServer(false, false)
|
sctlr, srcBaseURL, _, _, srcClient := startUpstreamServer(t, false, false)
|
||||||
defer os.RemoveAll(srcDir)
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
sctlr.Shutdown()
|
sctlr.Shutdown()
|
||||||
@@ -2015,8 +1944,7 @@ func TestMultipleURLs(t *testing.T) {
|
|||||||
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
||||||
}
|
}
|
||||||
|
|
||||||
dc, destBaseURL, destDir, destClient := startDownstreamServer(false, syncConfig)
|
dc, destBaseURL, _, destClient := startDownstreamServer(t, false, syncConfig)
|
||||||
defer os.RemoveAll(destDir)
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
dc.Shutdown()
|
dc.Shutdown()
|
||||||
@@ -2060,8 +1988,7 @@ func TestPeriodicallySignatures(t *testing.T) {
|
|||||||
Convey("Verify sync signatures", t, func() {
|
Convey("Verify sync signatures", t, func() {
|
||||||
updateDuration, _ := time.ParseDuration("30m")
|
updateDuration, _ := time.ParseDuration("30m")
|
||||||
|
|
||||||
sctlr, srcBaseURL, srcDir, _, _ := startUpstreamServer(false, false)
|
sctlr, srcBaseURL, srcDir, _, _ := startUpstreamServer(t, false, false)
|
||||||
defer os.RemoveAll(srcDir)
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
sctlr.Shutdown()
|
sctlr.Shutdown()
|
||||||
@@ -2079,9 +2006,7 @@ func TestPeriodicallySignatures(t *testing.T) {
|
|||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
defer func() { _ = os.Chdir(cwd) }()
|
defer func() { _ = os.Chdir(cwd) }()
|
||||||
tdir, err := ioutil.TempDir("", "sigs")
|
tdir := t.TempDir()
|
||||||
So(err, ShouldBeNil)
|
|
||||||
defer os.RemoveAll(tdir)
|
|
||||||
_ = os.Chdir(tdir)
|
_ = os.Chdir(tdir)
|
||||||
generateKeyPairs(tdir)
|
generateKeyPairs(tdir)
|
||||||
|
|
||||||
@@ -2114,8 +2039,7 @@ func TestPeriodicallySignatures(t *testing.T) {
|
|||||||
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
||||||
}
|
}
|
||||||
|
|
||||||
dctlr, destBaseURL, destDir, destClient := startDownstreamServer(false, syncConfig)
|
dctlr, destBaseURL, destDir, destClient := startDownstreamServer(t, false, syncConfig)
|
||||||
defer os.RemoveAll(destDir)
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
dctlr.Shutdown()
|
dctlr.Shutdown()
|
||||||
@@ -2340,8 +2264,7 @@ func TestPeriodicallySignaturesErr(t *testing.T) {
|
|||||||
Convey("Verify sync signatures gives error", t, func() {
|
Convey("Verify sync signatures gives error", t, func() {
|
||||||
updateDuration, _ := time.ParseDuration("30m")
|
updateDuration, _ := time.ParseDuration("30m")
|
||||||
|
|
||||||
sctlr, srcBaseURL, srcDir, _, _ := startUpstreamServer(false, false)
|
sctlr, srcBaseURL, srcDir, _, _ := startUpstreamServer(t, false, false)
|
||||||
defer os.RemoveAll(srcDir)
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
sctlr.Shutdown()
|
sctlr.Shutdown()
|
||||||
@@ -2359,9 +2282,7 @@ func TestPeriodicallySignaturesErr(t *testing.T) {
|
|||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
defer func() { _ = os.Chdir(cwd) }()
|
defer func() { _ = os.Chdir(cwd) }()
|
||||||
tdir, err := ioutil.TempDir("", "sigs")
|
tdir := t.TempDir()
|
||||||
So(err, ShouldBeNil)
|
|
||||||
defer os.RemoveAll(tdir)
|
|
||||||
_ = os.Chdir(tdir)
|
_ = os.Chdir(tdir)
|
||||||
generateKeyPairs(tdir)
|
generateKeyPairs(tdir)
|
||||||
|
|
||||||
@@ -2431,10 +2352,9 @@ func TestPeriodicallySignaturesErr(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dctlr, _, destDir, _ := startDownstreamServer(false, syncConfig)
|
dctlr, _, _, _ := startDownstreamServer(t, false, syncConfig)
|
||||||
defer func() {
|
defer func() {
|
||||||
dctlr.Shutdown()
|
dctlr.Shutdown()
|
||||||
defer os.RemoveAll(destDir)
|
|
||||||
}()
|
}()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -2447,12 +2367,9 @@ func TestOnDemandRetryGoroutine(t *testing.T) {
|
|||||||
|
|
||||||
srcConfig.HTTP.Port = srcPort
|
srcConfig.HTTP.Port = srcPort
|
||||||
|
|
||||||
srcDir, err := ioutil.TempDir("", "oci-src-repo-test")
|
srcDir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
err = test.CopyFiles("../../../test/data", srcDir)
|
err := test.CopyFiles("../../../test/data", srcDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@@ -2461,8 +2378,6 @@ func TestOnDemandRetryGoroutine(t *testing.T) {
|
|||||||
|
|
||||||
sctlr := api.NewController(srcConfig)
|
sctlr := api.NewController(srcConfig)
|
||||||
|
|
||||||
defer os.RemoveAll(srcDir)
|
|
||||||
|
|
||||||
regex := ".*"
|
regex := ".*"
|
||||||
semver := true
|
semver := true
|
||||||
var tlsVerify bool
|
var tlsVerify bool
|
||||||
@@ -2494,8 +2409,7 @@ func TestOnDemandRetryGoroutine(t *testing.T) {
|
|||||||
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
||||||
}
|
}
|
||||||
|
|
||||||
dc, destBaseURL, destDir, destClient := startDownstreamServer(false, syncConfig)
|
dc, destBaseURL, destDir, destClient := startDownstreamServer(t, false, syncConfig)
|
||||||
defer os.RemoveAll(destDir)
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
dc.Shutdown()
|
dc.Shutdown()
|
||||||
@@ -2540,12 +2454,9 @@ func TestOnDemandMultipleRetries(t *testing.T) {
|
|||||||
|
|
||||||
srcConfig.HTTP.Port = srcPort
|
srcConfig.HTTP.Port = srcPort
|
||||||
|
|
||||||
srcDir, err := ioutil.TempDir("", "oci-src-repo-test")
|
srcDir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
err = test.CopyFiles("../../../test/data", srcDir)
|
err := test.CopyFiles("../../../test/data", srcDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@@ -2554,8 +2465,6 @@ func TestOnDemandMultipleRetries(t *testing.T) {
|
|||||||
|
|
||||||
sctlr := api.NewController(srcConfig)
|
sctlr := api.NewController(srcConfig)
|
||||||
|
|
||||||
defer os.RemoveAll(srcDir)
|
|
||||||
|
|
||||||
var tlsVerify bool
|
var tlsVerify bool
|
||||||
|
|
||||||
syncRegistryConfig := sync.RegistryConfig{
|
syncRegistryConfig := sync.RegistryConfig{
|
||||||
@@ -2576,8 +2485,7 @@ func TestOnDemandMultipleRetries(t *testing.T) {
|
|||||||
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
||||||
}
|
}
|
||||||
|
|
||||||
dc, destBaseURL, destDir, destClient := startDownstreamServer(false, syncConfig)
|
dc, destBaseURL, destDir, destClient := startDownstreamServer(t, false, syncConfig)
|
||||||
defer os.RemoveAll(destDir)
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
dc.Shutdown()
|
dc.Shutdown()
|
||||||
@@ -2657,8 +2565,7 @@ func TestOnDemandMultipleRetries(t *testing.T) {
|
|||||||
|
|
||||||
func TestOnDemandPullsOnce(t *testing.T) {
|
func TestOnDemandPullsOnce(t *testing.T) {
|
||||||
Convey("Verify sync on demand pulls only one time", t, func(conv C) {
|
Convey("Verify sync on demand pulls only one time", t, func(conv C) {
|
||||||
sc, srcBaseURL, srcDir, _, _ := startUpstreamServer(false, false)
|
sc, srcBaseURL, _, _, _ := startUpstreamServer(t, false, false)
|
||||||
defer os.RemoveAll(srcDir)
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
sc.Shutdown()
|
sc.Shutdown()
|
||||||
@@ -2690,8 +2597,7 @@ func TestOnDemandPullsOnce(t *testing.T) {
|
|||||||
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
||||||
}
|
}
|
||||||
|
|
||||||
dc, destBaseURL, destDir, _ := startDownstreamServer(false, syncConfig)
|
dc, destBaseURL, destDir, _ := startDownstreamServer(t, false, syncConfig)
|
||||||
defer os.RemoveAll(destDir)
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
dc.Shutdown()
|
dc.Shutdown()
|
||||||
@@ -2757,8 +2663,7 @@ func TestError(t *testing.T) {
|
|||||||
Convey("Verify periodically sync pushSyncedLocalImage() error", t, func() {
|
Convey("Verify periodically sync pushSyncedLocalImage() error", t, func() {
|
||||||
updateDuration, _ := time.ParseDuration("30m")
|
updateDuration, _ := time.ParseDuration("30m")
|
||||||
|
|
||||||
sctlr, srcBaseURL, srcDir, _, _ := startUpstreamServer(false, false)
|
sctlr, srcBaseURL, _, _, _ := startUpstreamServer(t, false, false)
|
||||||
defer os.RemoveAll(srcDir)
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
sctlr.Shutdown()
|
sctlr.Shutdown()
|
||||||
@@ -2790,8 +2695,7 @@ func TestError(t *testing.T) {
|
|||||||
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
||||||
}
|
}
|
||||||
|
|
||||||
dctlr, destBaseURL, destDir, client := startDownstreamServer(false, syncConfig)
|
dctlr, destBaseURL, destDir, client := startDownstreamServer(t, false, syncConfig)
|
||||||
defer os.RemoveAll(destDir)
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
dctlr.Shutdown()
|
dctlr.Shutdown()
|
||||||
@@ -2813,8 +2717,7 @@ func TestError(t *testing.T) {
|
|||||||
|
|
||||||
func TestSignaturesOnDemand(t *testing.T) {
|
func TestSignaturesOnDemand(t *testing.T) {
|
||||||
Convey("Verify sync signatures on demand feature", t, func() {
|
Convey("Verify sync signatures on demand feature", t, func() {
|
||||||
sctlr, srcBaseURL, srcDir, _, _ := startUpstreamServer(false, false)
|
sctlr, srcBaseURL, srcDir, _, _ := startUpstreamServer(t, false, false)
|
||||||
defer os.RemoveAll(srcDir)
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
sctlr.Shutdown()
|
sctlr.Shutdown()
|
||||||
@@ -2832,9 +2735,7 @@ func TestSignaturesOnDemand(t *testing.T) {
|
|||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
defer func() { _ = os.Chdir(cwd) }()
|
defer func() { _ = os.Chdir(cwd) }()
|
||||||
tdir, err := ioutil.TempDir("", "sigs")
|
tdir := t.TempDir()
|
||||||
So(err, ShouldBeNil)
|
|
||||||
defer os.RemoveAll(tdir)
|
|
||||||
_ = os.Chdir(tdir)
|
_ = os.Chdir(tdir)
|
||||||
|
|
||||||
generateKeyPairs(tdir)
|
generateKeyPairs(tdir)
|
||||||
@@ -2856,8 +2757,7 @@ func TestSignaturesOnDemand(t *testing.T) {
|
|||||||
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
||||||
}
|
}
|
||||||
|
|
||||||
dctlr, destBaseURL, destDir, _ := startDownstreamServer(false, syncConfig)
|
dctlr, destBaseURL, destDir, _ := startDownstreamServer(t, false, syncConfig)
|
||||||
defer os.RemoveAll(destDir)
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
dctlr.Shutdown()
|
dctlr.Shutdown()
|
||||||
@@ -2950,8 +2850,7 @@ func TestSignaturesOnDemand(t *testing.T) {
|
|||||||
|
|
||||||
func TestOnlySignaturesOnDemand(t *testing.T) {
|
func TestOnlySignaturesOnDemand(t *testing.T) {
|
||||||
Convey("Verify sync signatures on demand feature when we already have the image", t, func() {
|
Convey("Verify sync signatures on demand feature when we already have the image", t, func() {
|
||||||
sctlr, srcBaseURL, srcDir, _, _ := startUpstreamServer(false, false)
|
sctlr, srcBaseURL, _, _, _ := startUpstreamServer(t, false, false)
|
||||||
defer os.RemoveAll(srcDir)
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
sctlr.Shutdown()
|
sctlr.Shutdown()
|
||||||
@@ -2969,9 +2868,7 @@ func TestOnlySignaturesOnDemand(t *testing.T) {
|
|||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
defer func() { _ = os.Chdir(cwd) }()
|
defer func() { _ = os.Chdir(cwd) }()
|
||||||
tdir, err := ioutil.TempDir("", "sigs")
|
tdir := t.TempDir()
|
||||||
So(err, ShouldBeNil)
|
|
||||||
defer os.RemoveAll(tdir)
|
|
||||||
_ = os.Chdir(tdir)
|
_ = os.Chdir(tdir)
|
||||||
|
|
||||||
var tlsVerify bool
|
var tlsVerify bool
|
||||||
@@ -2996,8 +2893,7 @@ func TestOnlySignaturesOnDemand(t *testing.T) {
|
|||||||
Registries: []sync.RegistryConfig{syncBadRegistryConfig, syncRegistryConfig},
|
Registries: []sync.RegistryConfig{syncBadRegistryConfig, syncRegistryConfig},
|
||||||
}
|
}
|
||||||
|
|
||||||
dctlr, destBaseURL, destDir, _ := startDownstreamServer(false, syncConfig)
|
dctlr, destBaseURL, _, _ := startDownstreamServer(t, false, syncConfig)
|
||||||
defer os.RemoveAll(destDir)
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
dctlr.Shutdown()
|
dctlr.Shutdown()
|
||||||
@@ -3068,8 +2964,7 @@ func TestSyncOnlyDiff(t *testing.T) {
|
|||||||
Convey("Verify sync only difference between local and upstream", t, func() {
|
Convey("Verify sync only difference between local and upstream", t, func() {
|
||||||
updateDuration, _ := time.ParseDuration("30m")
|
updateDuration, _ := time.ParseDuration("30m")
|
||||||
|
|
||||||
sctlr, srcBaseURL, srcDir, _, _ := startUpstreamServer(false, false)
|
sctlr, srcBaseURL, _, _, _ := startUpstreamServer(t, false, false)
|
||||||
defer os.RemoveAll(srcDir)
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
sctlr.Shutdown()
|
sctlr.Shutdown()
|
||||||
@@ -3101,13 +2996,10 @@ func TestSyncOnlyDiff(t *testing.T) {
|
|||||||
destBaseURL := test.GetBaseURL(destPort)
|
destBaseURL := test.GetBaseURL(destPort)
|
||||||
destConfig.HTTP.Port = destPort
|
destConfig.HTTP.Port = destPort
|
||||||
|
|
||||||
destDir, err := ioutil.TempDir("", "oci-dest-repo-test")
|
destDir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// copy images so we have them before syncing, sync should not pull them again
|
// copy images so we have them before syncing, sync should not pull them again
|
||||||
err = test.CopyFiles("../../../test/data", destDir)
|
err := test.CopyFiles("../../../test/data", destDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@@ -3141,7 +3033,6 @@ func TestSyncOnlyDiff(t *testing.T) {
|
|||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
dctlr.Shutdown()
|
dctlr.Shutdown()
|
||||||
os.RemoveAll(destDir)
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// watch .sync subdir, shouldn't be populated
|
// watch .sync subdir, shouldn't be populated
|
||||||
@@ -3177,8 +3068,7 @@ func TestSyncWithDiffDigest(t *testing.T) {
|
|||||||
Convey("Verify sync correctly detects changes in upstream images", t, func() {
|
Convey("Verify sync correctly detects changes in upstream images", t, func() {
|
||||||
updateDuration, _ := time.ParseDuration("30m")
|
updateDuration, _ := time.ParseDuration("30m")
|
||||||
|
|
||||||
sctlr, srcBaseURL, srcDir, _, _ := startUpstreamServer(false, false)
|
sctlr, srcBaseURL, _, _, _ := startUpstreamServer(t, false, false)
|
||||||
defer os.RemoveAll(srcDir)
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
sctlr.Shutdown()
|
sctlr.Shutdown()
|
||||||
@@ -3210,13 +3100,10 @@ func TestSyncWithDiffDigest(t *testing.T) {
|
|||||||
destBaseURL := test.GetBaseURL(destPort)
|
destBaseURL := test.GetBaseURL(destPort)
|
||||||
destConfig.HTTP.Port = destPort
|
destConfig.HTTP.Port = destPort
|
||||||
|
|
||||||
destDir, err := ioutil.TempDir("", "oci-dest-repo-test")
|
destDir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// copy images so we have them before syncing, sync should not pull them again
|
// copy images so we have them before syncing, sync should not pull them again
|
||||||
err = test.CopyFiles("../../../test/data", destDir)
|
err := test.CopyFiles("../../../test/data", destDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@@ -3311,7 +3198,6 @@ func TestSyncWithDiffDigest(t *testing.T) {
|
|||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
dctlr.Shutdown()
|
dctlr.Shutdown()
|
||||||
os.RemoveAll(destDir)
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// wait till ready
|
// wait till ready
|
||||||
|
|||||||
+2
-6
@@ -43,12 +43,8 @@ type AuditLog struct {
|
|||||||
|
|
||||||
func TestAuditLogMessages(t *testing.T) {
|
func TestAuditLogMessages(t *testing.T) {
|
||||||
Convey("Make a new controller", t, func() {
|
Convey("Make a new controller", t, func() {
|
||||||
dir, err := ioutil.TempDir("", "oci-repo-test")
|
dir := t.TempDir()
|
||||||
if err != nil {
|
err := CopyFiles("../../test/data", dir)
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
err = CopyFiles("../../test/data", dir)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package storage_test
|
package storage_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"path"
|
"path"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@@ -14,10 +12,7 @@ import (
|
|||||||
|
|
||||||
func TestCache(t *testing.T) {
|
func TestCache(t *testing.T) {
|
||||||
Convey("Make a new cache", t, func() {
|
Convey("Make a new cache", t, func() {
|
||||||
dir, err := ioutil.TempDir("", "cache_test")
|
dir := t.TempDir()
|
||||||
So(err, ShouldBeNil)
|
|
||||||
So(dir, ShouldNotBeEmpty)
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
|
|
||||||
log := log.NewLogger("debug", "")
|
log := log.NewLogger("debug", "")
|
||||||
So(log, ShouldNotBeNil)
|
So(log, ShouldNotBeNil)
|
||||||
|
|||||||
@@ -25,12 +25,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestCheckAllBlobsIntegrity(t *testing.T) {
|
func TestCheckAllBlobsIntegrity(t *testing.T) {
|
||||||
dir, err := ioutil.TempDir("", "scrub-test")
|
dir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
|
|
||||||
log := log.NewLogger("debug", "")
|
log := log.NewLogger("debug", "")
|
||||||
|
|
||||||
@@ -40,7 +35,7 @@ func TestCheckAllBlobsIntegrity(t *testing.T) {
|
|||||||
|
|
||||||
Convey("Scrub only one repo", t, func(c C) {
|
Convey("Scrub only one repo", t, func(c C) {
|
||||||
// initialize repo
|
// initialize repo
|
||||||
err = imgStore.InitRepo(repoName)
|
err := imgStore.InitRepo(repoName)
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
ok := imgStore.DirExists(path.Join(imgStore.RootDir(), repoName))
|
ok := imgStore.DirExists(path.Join(imgStore.RootDir(), repoName))
|
||||||
So(ok, ShouldBeTrue)
|
So(ok, ShouldBeTrue)
|
||||||
|
|||||||
@@ -30,12 +30,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestStorageFSAPIs(t *testing.T) {
|
func TestStorageFSAPIs(t *testing.T) {
|
||||||
dir, err := ioutil.TempDir("", "oci-repo-test")
|
dir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
|
|
||||||
log := log.Logger{Logger: zerolog.New(os.Stdout)}
|
log := log.Logger{Logger: zerolog.New(os.Stdout)}
|
||||||
metrics := monitoring.NewMetricsServer(false, log)
|
metrics := monitoring.NewMetricsServer(false, log)
|
||||||
@@ -167,12 +162,7 @@ func TestStorageFSAPIs(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestDedupeLinks(t *testing.T) {
|
func TestDedupeLinks(t *testing.T) {
|
||||||
dir, err := ioutil.TempDir("", "oci-repo-test")
|
dir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
|
|
||||||
log := log.Logger{Logger: zerolog.New(os.Stdout)}
|
log := log.Logger{Logger: zerolog.New(os.Stdout)}
|
||||||
metrics := monitoring.NewMetricsServer(false, log)
|
metrics := monitoring.NewMetricsServer(false, log)
|
||||||
@@ -308,11 +298,7 @@ func TestDedupe(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
Convey("Valid ImageStore", func() {
|
Convey("Valid ImageStore", func() {
|
||||||
dir, err := ioutil.TempDir("", "oci-repo-test")
|
dir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
|
|
||||||
log := log.Logger{Logger: zerolog.New(os.Stdout)}
|
log := log.Logger{Logger: zerolog.New(os.Stdout)}
|
||||||
metrics := monitoring.NewMetricsServer(false, log)
|
metrics := monitoring.NewMetricsServer(false, log)
|
||||||
@@ -326,11 +312,7 @@ func TestDedupe(t *testing.T) {
|
|||||||
// nolint: gocyclo
|
// nolint: gocyclo
|
||||||
func TestNegativeCases(t *testing.T) {
|
func TestNegativeCases(t *testing.T) {
|
||||||
Convey("Invalid root dir", t, func(c C) {
|
Convey("Invalid root dir", t, func(c C) {
|
||||||
dir, err := ioutil.TempDir("", "oci-repo-test")
|
dir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
os.RemoveAll(dir)
|
|
||||||
|
|
||||||
log := log.Logger{Logger: zerolog.New(os.Stdout)}
|
log := log.Logger{Logger: zerolog.New(os.Stdout)}
|
||||||
metrics := monitoring.NewMetricsServer(false, log)
|
metrics := monitoring.NewMetricsServer(false, log)
|
||||||
@@ -342,17 +324,13 @@ func TestNegativeCases(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
Convey("Invalid init repo", t, func(c C) {
|
Convey("Invalid init repo", t, func(c C) {
|
||||||
dir, err := ioutil.TempDir("", "oci-repo-test")
|
dir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
|
|
||||||
log := log.Logger{Logger: zerolog.New(os.Stdout)}
|
log := log.Logger{Logger: zerolog.New(os.Stdout)}
|
||||||
metrics := monitoring.NewMetricsServer(false, log)
|
metrics := monitoring.NewMetricsServer(false, log)
|
||||||
imgStore := storage.NewImageStore(dir, true, storage.DefaultGCDelay, true, true, log, metrics)
|
imgStore := storage.NewImageStore(dir, true, storage.DefaultGCDelay, true, true, log, metrics)
|
||||||
|
|
||||||
err = os.Chmod(dir, 0o000) // remove all perms
|
err := os.Chmod(dir, 0o000) // remove all perms
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@@ -381,11 +359,7 @@ func TestNegativeCases(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
Convey("Invalid validate repo", t, func(c C) {
|
Convey("Invalid validate repo", t, func(c C) {
|
||||||
dir, err := ioutil.TempDir("", "oci-repo-test")
|
dir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
|
|
||||||
log := log.Logger{Logger: zerolog.New(os.Stdout)}
|
log := log.Logger{Logger: zerolog.New(os.Stdout)}
|
||||||
metrics := monitoring.NewMetricsServer(false, log)
|
metrics := monitoring.NewMetricsServer(false, log)
|
||||||
@@ -394,7 +368,7 @@ func TestNegativeCases(t *testing.T) {
|
|||||||
So(imgStore, ShouldNotBeNil)
|
So(imgStore, ShouldNotBeNil)
|
||||||
So(imgStore.InitRepo("test"), ShouldBeNil)
|
So(imgStore.InitRepo("test"), ShouldBeNil)
|
||||||
|
|
||||||
err = os.MkdirAll(path.Join(dir, "invalid-test"), 0o755)
|
err := os.MkdirAll(path.Join(dir, "invalid-test"), 0o755)
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
err = os.Chmod(path.Join(dir, "invalid-test"), 0o000) // remove all perms
|
err = os.Chmod(path.Join(dir, "invalid-test"), 0o000) // remove all perms
|
||||||
@@ -499,11 +473,7 @@ func TestNegativeCases(t *testing.T) {
|
|||||||
_, err := ilfs.GetImageTags("test")
|
_, err := ilfs.GetImageTags("test")
|
||||||
So(err, ShouldNotBeNil)
|
So(err, ShouldNotBeNil)
|
||||||
|
|
||||||
dir, err := ioutil.TempDir("", "oci-repo-test")
|
dir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
|
|
||||||
log := log.Logger{Logger: zerolog.New(os.Stdout)}
|
log := log.Logger{Logger: zerolog.New(os.Stdout)}
|
||||||
metrics := monitoring.NewMetricsServer(false, log)
|
metrics := monitoring.NewMetricsServer(false, log)
|
||||||
@@ -526,11 +496,7 @@ func TestNegativeCases(t *testing.T) {
|
|||||||
_, _, _, err := ilfs.GetImageManifest("test", "")
|
_, _, _, err := ilfs.GetImageManifest("test", "")
|
||||||
So(err, ShouldNotBeNil)
|
So(err, ShouldNotBeNil)
|
||||||
|
|
||||||
dir, err := ioutil.TempDir("", "oci-repo-test")
|
dir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
|
|
||||||
log := log.Logger{Logger: zerolog.New(os.Stdout)}
|
log := log.Logger{Logger: zerolog.New(os.Stdout)}
|
||||||
metrics := monitoring.NewMetricsServer(false, log)
|
metrics := monitoring.NewMetricsServer(false, log)
|
||||||
@@ -571,11 +537,7 @@ func TestNegativeCases(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
Convey("Invalid new blob upload", t, func(c C) {
|
Convey("Invalid new blob upload", t, func(c C) {
|
||||||
dir, err := ioutil.TempDir("", "oci-repo-test")
|
dir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
|
|
||||||
log := log.Logger{Logger: zerolog.New(os.Stdout)}
|
log := log.Logger{Logger: zerolog.New(os.Stdout)}
|
||||||
metrics := monitoring.NewMetricsServer(false, log)
|
metrics := monitoring.NewMetricsServer(false, log)
|
||||||
@@ -584,7 +546,7 @@ func TestNegativeCases(t *testing.T) {
|
|||||||
So(imgStore, ShouldNotBeNil)
|
So(imgStore, ShouldNotBeNil)
|
||||||
So(imgStore.InitRepo("test"), ShouldBeNil)
|
So(imgStore.InitRepo("test"), ShouldBeNil)
|
||||||
|
|
||||||
err = os.Chmod(path.Join(dir, "test", ".uploads"), 0o000)
|
err := os.Chmod(path.Join(dir, "test", ".uploads"), 0o000)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@@ -621,6 +583,12 @@ func TestNegativeCases(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
t.Cleanup(func() {
|
||||||
|
err = os.Chmod(path.Join(dir, "test", ".uploads"), 0o700)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
content := []byte("test-data3")
|
content := []byte("test-data3")
|
||||||
buf := bytes.NewBuffer(content)
|
buf := bytes.NewBuffer(content)
|
||||||
@@ -633,11 +601,7 @@ func TestNegativeCases(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
Convey("Invalid dedupe scenarios", t, func() {
|
Convey("Invalid dedupe scenarios", t, func() {
|
||||||
dir, err := ioutil.TempDir("", "oci-repo-test")
|
dir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
|
|
||||||
log := log.Logger{Logger: zerolog.New(os.Stdout)}
|
log := log.Logger{Logger: zerolog.New(os.Stdout)}
|
||||||
metrics := monitoring.NewMetricsServer(false, log)
|
metrics := monitoring.NewMetricsServer(false, log)
|
||||||
@@ -710,14 +674,10 @@ func TestNegativeCases(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
Convey("DirExists call with a filename as argument", t, func(c C) {
|
Convey("DirExists call with a filename as argument", t, func(c C) {
|
||||||
dir, err := ioutil.TempDir("", "oci-repo-test")
|
dir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
|
|
||||||
filePath := path.Join(dir, "file.txt")
|
filePath := path.Join(dir, "file.txt")
|
||||||
err = ioutil.WriteFile(filePath, []byte("some dummy file content"), 0o644) //nolint: gosec
|
err := ioutil.WriteFile(filePath, []byte("some dummy file content"), 0o644) //nolint: gosec
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@@ -748,14 +708,10 @@ func TestHardLink(t *testing.T) {
|
|||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
})
|
})
|
||||||
Convey("Test that ValidateHardLink returns error if rootDir is a file", t, func() {
|
Convey("Test that ValidateHardLink returns error if rootDir is a file", t, func() {
|
||||||
dir, err := ioutil.TempDir("", "storage-hard-test")
|
dir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
|
|
||||||
filePath := path.Join(dir, "file.txt")
|
filePath := path.Join(dir, "file.txt")
|
||||||
err = ioutil.WriteFile(filePath, []byte("some dummy file content"), 0o644) //nolint: gosec
|
err := ioutil.WriteFile(filePath, []byte("some dummy file content"), 0o644) //nolint: gosec
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@@ -764,13 +720,9 @@ func TestHardLink(t *testing.T) {
|
|||||||
So(err, ShouldNotBeNil)
|
So(err, ShouldNotBeNil)
|
||||||
})
|
})
|
||||||
Convey("Test if filesystem supports hardlink", t, func() {
|
Convey("Test if filesystem supports hardlink", t, func() {
|
||||||
dir, err := ioutil.TempDir("", "storage-hard-test")
|
dir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
|
|
||||||
err = storage.ValidateHardLink(dir)
|
err := storage.ValidateHardLink(dir)
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
err = ioutil.WriteFile(path.Join(dir, "hardtest.txt"), []byte("testing hard link code"), 0o644) //nolint: gosec
|
err = ioutil.WriteFile(path.Join(dir, "hardtest.txt"), []byte("testing hard link code"), 0o644) //nolint: gosec
|
||||||
@@ -782,6 +734,13 @@ func TestHardLink(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
// Allow hardtest.txt to be cleaned up by t.TempDir()
|
||||||
|
t.Cleanup(func() {
|
||||||
|
err = os.Chmod(dir, 0o700)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
err = os.Link(path.Join(dir, "hardtest.txt"), path.Join(dir, "duphardtest.txt"))
|
err = os.Link(path.Join(dir, "hardtest.txt"), path.Join(dir, "duphardtest.txt"))
|
||||||
So(err, ShouldNotBeNil)
|
So(err, ShouldNotBeNil)
|
||||||
@@ -795,9 +754,7 @@ func TestHardLink(t *testing.T) {
|
|||||||
|
|
||||||
func TestInjectWriteFile(t *testing.T) {
|
func TestInjectWriteFile(t *testing.T) {
|
||||||
Convey("writeFile with commit", t, func() {
|
Convey("writeFile with commit", t, func() {
|
||||||
dir, err := ioutil.TempDir("", "oci-repo-test")
|
dir := t.TempDir()
|
||||||
So(err, ShouldBeNil)
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
|
|
||||||
log := log.Logger{Logger: zerolog.New(os.Stdout)}
|
log := log.Logger{Logger: zerolog.New(os.Stdout)}
|
||||||
metrics := monitoring.NewMetricsServer(false, log)
|
metrics := monitoring.NewMetricsServer(false, log)
|
||||||
@@ -827,9 +784,7 @@ func TestInjectWriteFile(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
Convey("writeFile without commit", t, func() {
|
Convey("writeFile without commit", t, func() {
|
||||||
dir, err := ioutil.TempDir("", "oci-repo-test")
|
dir := t.TempDir()
|
||||||
So(err, ShouldBeNil)
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
|
|
||||||
log := log.Logger{Logger: zerolog.New(os.Stdout)}
|
log := log.Logger{Logger: zerolog.New(os.Stdout)}
|
||||||
metrics := monitoring.NewMetricsServer(false, log)
|
metrics := monitoring.NewMetricsServer(false, log)
|
||||||
@@ -844,12 +799,7 @@ func TestInjectWriteFile(t *testing.T) {
|
|||||||
|
|
||||||
func TestGarbageCollect(t *testing.T) {
|
func TestGarbageCollect(t *testing.T) {
|
||||||
Convey("Repo layout", t, func(c C) {
|
Convey("Repo layout", t, func(c C) {
|
||||||
dir, err := ioutil.TempDir("", "oci-gc-test")
|
dir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
|
|
||||||
log := log.Logger{Logger: zerolog.New(os.Stdout)}
|
log := log.Logger{Logger: zerolog.New(os.Stdout)}
|
||||||
metrics := monitoring.NewMetricsServer(false, log)
|
metrics := monitoring.NewMetricsServer(false, log)
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import (
|
|||||||
_ "crypto/sha256"
|
_ "crypto/sha256"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -111,12 +110,7 @@ func TestStorageAPIs(t *testing.T) {
|
|||||||
store, imgStore, _ = createObjectsStore(testDir)
|
store, imgStore, _ = createObjectsStore(testDir)
|
||||||
defer cleanupStorage(store, testDir)
|
defer cleanupStorage(store, testDir)
|
||||||
} else {
|
} else {
|
||||||
dir, err := ioutil.TempDir("", "oci-repo-test")
|
dir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
|
|
||||||
log := log.Logger{Logger: zerolog.New(os.Stdout)}
|
log := log.Logger{Logger: zerolog.New(os.Stdout)}
|
||||||
metrics := monitoring.NewMetricsServer(false, log)
|
metrics := monitoring.NewMetricsServer(false, log)
|
||||||
@@ -686,25 +680,9 @@ func TestStorageHandler(t *testing.T) {
|
|||||||
defer cleanupStorage(thirdStorageDriver, thirdRootDir)
|
defer cleanupStorage(thirdStorageDriver, thirdRootDir)
|
||||||
} else {
|
} else {
|
||||||
// Create temporary directory
|
// Create temporary directory
|
||||||
var err error
|
firstRootDir = t.TempDir()
|
||||||
|
secondRootDir = t.TempDir()
|
||||||
firstRootDir, err = ioutil.TempDir("", "util_test")
|
thirdRootDir = t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(firstRootDir)
|
|
||||||
|
|
||||||
secondRootDir, err = ioutil.TempDir("", "util_test")
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(secondRootDir)
|
|
||||||
|
|
||||||
thirdRootDir, err = ioutil.TempDir("", "util_test")
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(thirdRootDir)
|
|
||||||
|
|
||||||
log := log.NewLogger("debug", "")
|
log := log.NewLogger("debug", "")
|
||||||
|
|
||||||
|
|||||||
+9
-25
@@ -19,56 +19,40 @@ func TestCopyFiles(t *testing.T) {
|
|||||||
So(err, ShouldNotBeNil)
|
So(err, ShouldNotBeNil)
|
||||||
})
|
})
|
||||||
Convey("destDir is a file", t, func() {
|
Convey("destDir is a file", t, func() {
|
||||||
dir, err := ioutil.TempDir("", "copy-files-test")
|
dir := t.TempDir()
|
||||||
|
|
||||||
|
err := test.CopyFiles("../../test/data", dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = test.CopyFiles("../../test/data", dir)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
err = test.CopyFiles(dir, "/etc/passwd")
|
err = test.CopyFiles(dir, "/etc/passwd")
|
||||||
So(err, ShouldNotBeNil)
|
So(err, ShouldNotBeNil)
|
||||||
})
|
})
|
||||||
Convey("sourceDir does not have read permissions", t, func() {
|
Convey("sourceDir does not have read permissions", t, func() {
|
||||||
dir, err := ioutil.TempDir("", "copy-files-test")
|
dir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
|
|
||||||
err = os.Chmod(dir, 0o300)
|
err := os.Chmod(dir, 0o300)
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
err = test.CopyFiles(dir, os.TempDir())
|
err = test.CopyFiles(dir, os.TempDir())
|
||||||
So(err, ShouldNotBeNil)
|
So(err, ShouldNotBeNil)
|
||||||
})
|
})
|
||||||
Convey("sourceDir has a subfolder that does not have read permissions", t, func() {
|
Convey("sourceDir has a subfolder that does not have read permissions", t, func() {
|
||||||
dir, err := ioutil.TempDir("", "copy-files-test")
|
dir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
|
|
||||||
sdir := "subdir"
|
sdir := "subdir"
|
||||||
err = os.Mkdir(path.Join(dir, sdir), 0o300)
|
err := os.Mkdir(path.Join(dir, sdir), 0o300)
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
err = test.CopyFiles(dir, os.TempDir())
|
err = test.CopyFiles(dir, os.TempDir())
|
||||||
So(err, ShouldNotBeNil)
|
So(err, ShouldNotBeNil)
|
||||||
})
|
})
|
||||||
Convey("sourceDir has a file that does not have read permissions", t, func() {
|
Convey("sourceDir has a file that does not have read permissions", t, func() {
|
||||||
dir, err := ioutil.TempDir("", "copy-files-test")
|
dir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
|
|
||||||
filePath := path.Join(dir, "file.txt")
|
filePath := path.Join(dir, "file.txt")
|
||||||
err = ioutil.WriteFile(filePath, []byte("some dummy file content"), 0o644) //nolint: gosec
|
err := ioutil.WriteFile(filePath, []byte("some dummy file content"), 0o644) //nolint: gosec
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user