mirror of
https://github.com/project-zot/zot.git
synced 2024-12-30 22:34:13 -05:00
ci/cd: unit test hangs for a long time intermittently closes #286
Signed-off-by: Alexei Dodon <adodon@cisco.com>
This commit is contained in:
parent
fff6107310
commit
f99fa37623
6 changed files with 112 additions and 495 deletions
2
Makefile
2
Makefile
|
@ -32,7 +32,7 @@ test:
|
||||||
$(shell mkdir -p test/data; cd test/data; ../scripts/gen_certs.sh; cd ${TOP_LEVEL}; sudo skopeo --insecure-policy copy -q docker://public.ecr.aws/t0x7q1g8/centos:7 oci:${TOP_LEVEL}/test/data/zot-test:0.0.1;sudo skopeo --insecure-policy copy -q docker://public.ecr.aws/t0x7q1g8/centos:8 oci:${TOP_LEVEL}/test/data/zot-cve-test:0.0.1)
|
$(shell mkdir -p test/data; cd test/data; ../scripts/gen_certs.sh; cd ${TOP_LEVEL}; sudo skopeo --insecure-policy copy -q docker://public.ecr.aws/t0x7q1g8/centos:7 oci:${TOP_LEVEL}/test/data/zot-test:0.0.1;sudo skopeo --insecure-policy copy -q docker://public.ecr.aws/t0x7q1g8/centos:8 oci:${TOP_LEVEL}/test/data/zot-cve-test:0.0.1)
|
||||||
$(shell sudo mkdir -p /etc/containers/certs.d/127.0.0.1:8089/; sudo cp test/data/client.* /etc/containers/certs.d/127.0.0.1:8089/; sudo cp test/data/ca.* /etc/containers/certs.d/127.0.0.1:8089/;)
|
$(shell sudo mkdir -p /etc/containers/certs.d/127.0.0.1:8089/; sudo cp test/data/client.* /etc/containers/certs.d/127.0.0.1:8089/; sudo cp test/data/ca.* /etc/containers/certs.d/127.0.0.1:8089/;)
|
||||||
$(shell sudo chmod a=rwx /etc/containers/certs.d/127.0.0.1:8089/*.key)
|
$(shell sudo chmod a=rwx /etc/containers/certs.d/127.0.0.1:8089/*.key)
|
||||||
go test -tags extended,containers_image_openpgp -v -trimpath -race -cover -coverpkg ./... -coverprofile=coverage-extended.txt -covermode=atomic ./...
|
go test -tags extended,containers_image_openpgp -v -trimpath -race -timeout 15m -cover -coverpkg ./... -coverprofile=coverage-extended.txt -covermode=atomic ./...
|
||||||
go test -tags minimal,containers_image_openpgp -v -trimpath -race -cover -coverpkg ./... -coverprofile=coverage-minimal.txt -covermode=atomic ./...
|
go test -tags minimal,containers_image_openpgp -v -trimpath -race -cover -coverpkg ./... -coverprofile=coverage-minimal.txt -covermode=atomic ./...
|
||||||
|
|
||||||
.PHONY: test-clean
|
.PHONY: test-clean
|
||||||
|
|
|
@ -131,26 +131,9 @@ func TestObjectStorageController(t *testing.T) {
|
||||||
|
|
||||||
c.Config.Storage.RootDirectory = "/"
|
c.Config.Storage.RootDirectory = "/"
|
||||||
|
|
||||||
go func(controller *api.Controller) {
|
go startServer(c)
|
||||||
// this blocks
|
defer stopServer(c)
|
||||||
if err := controller.Run(); err != nil {
|
WaitTillServerReady(baseURL)
|
||||||
return
|
|
||||||
}
|
|
||||||
}(c)
|
|
||||||
|
|
||||||
// wait till ready
|
|
||||||
for {
|
|
||||||
_, err := resty.R().Get(baseURL)
|
|
||||||
if err == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
|
|
||||||
defer func(controller *api.Controller) {
|
|
||||||
ctx := context.Background()
|
|
||||||
_ = controller.Server.Shutdown(ctx)
|
|
||||||
}(c)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -186,24 +169,9 @@ func TestObjectStorageControllerSubPaths(t *testing.T) {
|
||||||
}
|
}
|
||||||
c.Config.Storage.SubPaths = subPathMap
|
c.Config.Storage.SubPaths = subPathMap
|
||||||
|
|
||||||
go func(controller *api.Controller) {
|
go startServer(c)
|
||||||
// this blocks
|
defer stopServer(c)
|
||||||
if err := controller.Run(); err != nil {
|
WaitTillServerReady(baseURL)
|
||||||
return
|
|
||||||
}
|
|
||||||
}(c)
|
|
||||||
|
|
||||||
for {
|
|
||||||
_, err := resty.R().Get(baseURL)
|
|
||||||
if err == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
defer func(controller *api.Controller) {
|
|
||||||
ctx := context.Background()
|
|
||||||
_ = controller.Server.Shutdown(ctx)
|
|
||||||
}(c)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,24 +204,11 @@ func TestHtpasswdSingleCred(t *testing.T) {
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
c.Config.Storage.RootDirectory = dir
|
c.Config.Storage.RootDirectory = dir
|
||||||
go func(controller *api.Controller) {
|
|
||||||
// this blocks
|
go startServer(c)
|
||||||
if err := controller.Run(); err != nil {
|
defer stopServer(c)
|
||||||
return
|
WaitTillServerReady(baseURL)
|
||||||
}
|
|
||||||
}(c)
|
|
||||||
// wait till ready
|
|
||||||
for {
|
|
||||||
_, err := resty.R().Get(baseURL)
|
|
||||||
if err == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
defer func(controller *api.Controller) {
|
|
||||||
ctx := context.Background()
|
|
||||||
_ = controller.Server.Shutdown(ctx)
|
|
||||||
}(c)
|
|
||||||
// with creds, should get expected status code
|
// with creds, should get expected status code
|
||||||
resp, _ := resty.R().SetBasicAuth(user, password).Get(baseURL + "/v2/")
|
resp, _ := resty.R().SetBasicAuth(user, password).Get(baseURL + "/v2/")
|
||||||
So(resp, ShouldNotBeNil)
|
So(resp, ShouldNotBeNil)
|
||||||
|
@ -304,25 +259,11 @@ func TestHtpasswdTwoCreds(t *testing.T) {
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
c.Config.Storage.RootDirectory = dir
|
c.Config.Storage.RootDirectory = dir
|
||||||
go func(controller *api.Controller) {
|
|
||||||
// this blocks
|
|
||||||
if err := controller.Run(); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}(c)
|
|
||||||
// wait till ready
|
|
||||||
for {
|
|
||||||
_, err := resty.R().Get(baseURL)
|
|
||||||
if err == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
|
|
||||||
defer func(controller *api.Controller) {
|
go startServer(c)
|
||||||
ctx := context.Background()
|
defer stopServer(c)
|
||||||
_ = controller.Server.Shutdown(ctx)
|
WaitTillServerReady(baseURL)
|
||||||
}(c)
|
|
||||||
// with creds, should get expected status code
|
// with creds, should get expected status code
|
||||||
resp, _ := resty.R().SetBasicAuth(user1, password1).Get(baseURL + "/v2/")
|
resp, _ := resty.R().SetBasicAuth(user1, password1).Get(baseURL + "/v2/")
|
||||||
So(resp, ShouldNotBeNil)
|
So(resp, ShouldNotBeNil)
|
||||||
|
@ -373,25 +314,11 @@ func TestHtpasswdFiveCreds(t *testing.T) {
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
c.Config.Storage.RootDirectory = dir
|
c.Config.Storage.RootDirectory = dir
|
||||||
go func(controller *api.Controller) {
|
|
||||||
// this blocks
|
|
||||||
if err := controller.Run(); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}(c)
|
|
||||||
// wait till ready
|
|
||||||
for {
|
|
||||||
_, err := resty.R().Get(baseURL)
|
|
||||||
if err == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
|
|
||||||
defer func(controller *api.Controller) {
|
go startServer(c)
|
||||||
ctx := context.Background()
|
defer stopServer(c)
|
||||||
_ = controller.Server.Shutdown(ctx)
|
WaitTillServerReady(baseURL)
|
||||||
}(c)
|
|
||||||
// with creds, should get expected status code
|
// with creds, should get expected status code
|
||||||
for key, val := range tests {
|
for key, val := range tests {
|
||||||
resp, _ := resty.R().SetBasicAuth(key, val).Get(baseURL + "/v2/")
|
resp, _ := resty.R().SetBasicAuth(key, val).Get(baseURL + "/v2/")
|
||||||
|
@ -427,26 +354,10 @@ func TestBasicAuth(t *testing.T) {
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
c.Config.Storage.RootDirectory = dir
|
c.Config.Storage.RootDirectory = dir
|
||||||
go func() {
|
|
||||||
// this blocks
|
|
||||||
if err := c.Run(); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// wait till ready
|
go startServer(c)
|
||||||
for {
|
defer stopServer(c)
|
||||||
_, err := resty.R().Get(baseURL)
|
WaitTillServerReady(baseURL)
|
||||||
if err == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
ctx := context.Background()
|
|
||||||
_ = c.Server.Shutdown(ctx)
|
|
||||||
}()
|
|
||||||
|
|
||||||
// without creds, should get access error
|
// without creds, should get access error
|
||||||
resp, err := resty.R().Get(baseURL + "/v2/")
|
resp, err := resty.R().Get(baseURL + "/v2/")
|
||||||
|
@ -483,31 +394,13 @@ func TestInterruptedBlobUpload(t *testing.T) {
|
||||||
|
|
||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
c.Config.Storage.RootDirectory = dir
|
c.Config.Storage.RootDirectory = dir
|
||||||
go func() {
|
|
||||||
// this blocks
|
go startServer(c)
|
||||||
if err := c.Run(); err != nil {
|
defer stopServer(c)
|
||||||
return
|
WaitTillServerReady(baseURL)
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
client := resty.New()
|
client := resty.New()
|
||||||
|
|
||||||
// wait till ready
|
|
||||||
for {
|
|
||||||
_, err := client.R().Get(baseURL)
|
|
||||||
if err == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
ctx := context.Background()
|
|
||||||
_ = c.Server.Shutdown(ctx)
|
|
||||||
}()
|
|
||||||
|
|
||||||
blob := make([]byte, 50*1024*1024)
|
blob := make([]byte, 50*1024*1024)
|
||||||
|
|
||||||
digest := godigest.FromBytes(blob).String()
|
digest := godigest.FromBytes(blob).String()
|
||||||
|
|
||||||
// nolint: dupl
|
// nolint: dupl
|
||||||
|
@ -743,25 +636,9 @@ func TestMultipleInstance(t *testing.T) {
|
||||||
|
|
||||||
subPathMap["/a"] = config.StorageConfig{RootDirectory: subDir}
|
subPathMap["/a"] = config.StorageConfig{RootDirectory: subDir}
|
||||||
|
|
||||||
go func() {
|
go startServer(c)
|
||||||
if err := c.Run(); err != nil {
|
defer stopServer(c)
|
||||||
return
|
WaitTillServerReady(baseURL)
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// wait till ready
|
|
||||||
for {
|
|
||||||
_, err := resty.R().Get(baseURL)
|
|
||||||
if err == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
ctx := context.Background()
|
|
||||||
_ = c.Server.Shutdown(ctx)
|
|
||||||
}()
|
|
||||||
|
|
||||||
client := resty.New()
|
client := resty.New()
|
||||||
|
|
||||||
|
@ -799,28 +676,11 @@ func TestMultipleInstance(t *testing.T) {
|
||||||
|
|
||||||
c.Config.Storage.RootDirectory = globalDir
|
c.Config.Storage.RootDirectory = globalDir
|
||||||
subPathMap := make(map[string]config.StorageConfig)
|
subPathMap := make(map[string]config.StorageConfig)
|
||||||
|
|
||||||
subPathMap["/a"] = config.StorageConfig{RootDirectory: subDir}
|
subPathMap["/a"] = config.StorageConfig{RootDirectory: subDir}
|
||||||
go func() {
|
|
||||||
// this blocks
|
|
||||||
if err := c.Run(); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// wait till ready
|
go startServer(c)
|
||||||
for {
|
defer stopServer(c)
|
||||||
_, err := resty.R().Get(baseURL)
|
WaitTillServerReady(baseURL)
|
||||||
if err == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
ctx := context.Background()
|
|
||||||
_ = c.Server.Shutdown(ctx)
|
|
||||||
}()
|
|
||||||
|
|
||||||
// without creds, should get access error
|
// without creds, should get access error
|
||||||
resp, err := resty.R().Get(baseURL + "/v2/")
|
resp, err := resty.R().Get(baseURL + "/v2/")
|
||||||
|
@ -876,26 +736,10 @@ func TestTLSWithBasicAuth(t *testing.T) {
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
c.Config.Storage.RootDirectory = dir
|
c.Config.Storage.RootDirectory = dir
|
||||||
go func() {
|
|
||||||
// this blocks
|
|
||||||
if err := c.Run(); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// wait till ready
|
go startServer(c)
|
||||||
for {
|
defer stopServer(c)
|
||||||
_, err := resty.R().Get(baseURL)
|
WaitTillServerReady(baseURL)
|
||||||
if err == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
ctx := context.Background()
|
|
||||||
_ = c.Server.Shutdown(ctx)
|
|
||||||
}()
|
|
||||||
|
|
||||||
// accessing insecure HTTP site should fail
|
// accessing insecure HTTP site should fail
|
||||||
resp, err := resty.R().Get(baseURL)
|
resp, err := resty.R().Get(baseURL)
|
||||||
|
@ -958,26 +802,10 @@ func TestTLSWithBasicAuthAllowReadAccess(t *testing.T) {
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
c.Config.Storage.RootDirectory = dir
|
c.Config.Storage.RootDirectory = dir
|
||||||
go func() {
|
|
||||||
// this blocks
|
|
||||||
if err := c.Run(); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// wait till ready
|
go startServer(c)
|
||||||
for {
|
defer stopServer(c)
|
||||||
_, err := resty.R().Get(baseURL)
|
WaitTillServerReady(baseURL)
|
||||||
if err == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
ctx := context.Background()
|
|
||||||
_ = c.Server.Shutdown(ctx)
|
|
||||||
}()
|
|
||||||
|
|
||||||
// accessing insecure HTTP site should fail
|
// accessing insecure HTTP site should fail
|
||||||
resp, err := resty.R().Get(baseURL)
|
resp, err := resty.R().Get(baseURL)
|
||||||
|
@ -1034,26 +862,10 @@ func TestTLSMutualAuth(t *testing.T) {
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
c.Config.Storage.RootDirectory = dir
|
c.Config.Storage.RootDirectory = dir
|
||||||
go func() {
|
|
||||||
// this blocks
|
|
||||||
if err := c.Run(); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// wait till ready
|
go startServer(c)
|
||||||
for {
|
defer stopServer(c)
|
||||||
_, err := resty.R().Get(baseURL)
|
WaitTillServerReady(baseURL)
|
||||||
if err == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
ctx := context.Background()
|
|
||||||
_ = c.Server.Shutdown(ctx)
|
|
||||||
}()
|
|
||||||
|
|
||||||
// accessing insecure HTTP site should fail
|
// accessing insecure HTTP site should fail
|
||||||
resp, err := resty.R().Get(baseURL)
|
resp, err := resty.R().Get(baseURL)
|
||||||
|
@ -1123,26 +935,10 @@ func TestTLSMutualAuthAllowReadAccess(t *testing.T) {
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
c.Config.Storage.RootDirectory = dir
|
c.Config.Storage.RootDirectory = dir
|
||||||
go func() {
|
|
||||||
// this blocks
|
|
||||||
if err := c.Run(); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// wait till ready
|
go startServer(c)
|
||||||
for {
|
defer stopServer(c)
|
||||||
_, err := resty.R().Get(baseURL)
|
WaitTillServerReady(baseURL)
|
||||||
if err == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
ctx := context.Background()
|
|
||||||
_ = c.Server.Shutdown(ctx)
|
|
||||||
}()
|
|
||||||
|
|
||||||
// accessing insecure HTTP site should fail
|
// accessing insecure HTTP site should fail
|
||||||
resp, err := resty.R().Get(baseURL)
|
resp, err := resty.R().Get(baseURL)
|
||||||
|
@ -1225,26 +1021,10 @@ func TestTLSMutualAndBasicAuth(t *testing.T) {
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
c.Config.Storage.RootDirectory = dir
|
c.Config.Storage.RootDirectory = dir
|
||||||
go func() {
|
|
||||||
// this blocks
|
|
||||||
if err := c.Run(); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// wait till ready
|
go startServer(c)
|
||||||
for {
|
defer stopServer(c)
|
||||||
_, err := resty.R().Get(baseURL)
|
WaitTillServerReady(baseURL)
|
||||||
if err == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
ctx := context.Background()
|
|
||||||
_ = c.Server.Shutdown(ctx)
|
|
||||||
}()
|
|
||||||
|
|
||||||
// accessing insecure HTTP site should fail
|
// accessing insecure HTTP site should fail
|
||||||
resp, err := resty.R().Get(baseURL)
|
resp, err := resty.R().Get(baseURL)
|
||||||
|
@ -1324,26 +1104,10 @@ func TestTLSMutualAndBasicAuthAllowReadAccess(t *testing.T) {
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
c.Config.Storage.RootDirectory = dir
|
c.Config.Storage.RootDirectory = dir
|
||||||
go func() {
|
|
||||||
// this blocks
|
|
||||||
if err := c.Run(); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// wait till ready
|
go startServer(c)
|
||||||
for {
|
defer stopServer(c)
|
||||||
_, err := resty.R().Get(baseURL)
|
WaitTillServerReady(baseURL)
|
||||||
if err == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
ctx := context.Background()
|
|
||||||
_ = c.Server.Shutdown(ctx)
|
|
||||||
}()
|
|
||||||
|
|
||||||
// accessing insecure HTTP site should fail
|
// accessing insecure HTTP site should fail
|
||||||
resp, err := resty.R().Get(baseURL)
|
resp, err := resty.R().Get(baseURL)
|
||||||
|
@ -1497,26 +1261,10 @@ func TestBasicAuthWithLDAP(t *testing.T) {
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
c.Config.Storage.RootDirectory = dir
|
c.Config.Storage.RootDirectory = dir
|
||||||
go func() {
|
|
||||||
// this blocks
|
|
||||||
if err := c.Run(); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// wait till ready
|
go startServer(c)
|
||||||
for {
|
defer stopServer(c)
|
||||||
_, err := resty.R().Get(baseURL)
|
WaitTillServerReady(baseURL)
|
||||||
if err == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
ctx := context.Background()
|
|
||||||
_ = c.Server.Shutdown(ctx)
|
|
||||||
}()
|
|
||||||
|
|
||||||
// without creds, should get access error
|
// without creds, should get access error
|
||||||
resp, err := resty.R().Get(baseURL + "/v2/")
|
resp, err := resty.R().Get(baseURL + "/v2/")
|
||||||
|
@ -1564,26 +1312,10 @@ func TestBearerAuth(t *testing.T) {
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
c.Config.Storage.RootDirectory = dir
|
c.Config.Storage.RootDirectory = dir
|
||||||
go func() {
|
|
||||||
// this blocks
|
|
||||||
if err := c.Run(); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// wait till ready
|
go startServer(c)
|
||||||
for {
|
defer stopServer(c)
|
||||||
_, err := resty.R().Get(baseURL)
|
WaitTillServerReady(baseURL)
|
||||||
if err == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
ctx := context.Background()
|
|
||||||
_ = c.Server.Shutdown(ctx)
|
|
||||||
}()
|
|
||||||
|
|
||||||
blob := []byte("hello, blob!")
|
blob := []byte("hello, blob!")
|
||||||
digest := godigest.FromBytes(blob).String()
|
digest := godigest.FromBytes(blob).String()
|
||||||
|
@ -1747,26 +1479,10 @@ func TestBearerAuthWithAllowReadAccess(t *testing.T) {
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
c.Config.Storage.RootDirectory = dir
|
c.Config.Storage.RootDirectory = dir
|
||||||
go func() {
|
|
||||||
// this blocks
|
|
||||||
if err := c.Run(); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// wait till ready
|
go startServer(c)
|
||||||
for {
|
defer stopServer(c)
|
||||||
_, err := resty.R().Get(baseURL)
|
WaitTillServerReady(baseURL)
|
||||||
if err == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
ctx := context.Background()
|
|
||||||
_ = c.Server.Shutdown(ctx)
|
|
||||||
}()
|
|
||||||
|
|
||||||
blob := []byte("hello, blob!")
|
blob := []byte("hello, blob!")
|
||||||
digest := godigest.FromBytes(blob).String()
|
digest := godigest.FromBytes(blob).String()
|
||||||
|
@ -2001,26 +1717,10 @@ func TestAuthorizationWithBasicAuth(t *testing.T) {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
c.Config.Storage.RootDirectory = dir
|
c.Config.Storage.RootDirectory = dir
|
||||||
go func() {
|
|
||||||
// this blocks
|
|
||||||
if err := c.Run(); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// wait till ready
|
go startServer(c)
|
||||||
for {
|
defer stopServer(c)
|
||||||
_, err := resty.R().Get(baseURL)
|
WaitTillServerReady(baseURL)
|
||||||
if err == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
ctx := context.Background()
|
|
||||||
_ = c.Server.Shutdown(ctx)
|
|
||||||
}()
|
|
||||||
|
|
||||||
blob := []byte("hello, blob!")
|
blob := []byte("hello, blob!")
|
||||||
digest := godigest.FromBytes(blob).String()
|
digest := godigest.FromBytes(blob).String()
|
||||||
|
@ -2370,26 +2070,21 @@ func TestInvalidCases(t *testing.T) {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
defer stopServer(c)
|
|
||||||
|
|
||||||
c.Config.Storage.RootDirectory = "oci-repo-test"
|
c.Config.Storage.RootDirectory = "oci-repo-test"
|
||||||
|
|
||||||
go func() {
|
go startServer(c)
|
||||||
// this blocks
|
defer func(ctrl *api.Controller) {
|
||||||
if err := c.Run(); err != nil {
|
err := ctrl.Server.Shutdown(context.Background())
|
||||||
return
|
if err != nil {
|
||||||
}
|
panic(err)
|
||||||
}()
|
|
||||||
|
|
||||||
// wait till ready
|
|
||||||
for {
|
|
||||||
_, err := resty.R().Get(baseURL)
|
|
||||||
if err == nil {
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
err = os.RemoveAll(ctrl.Config.Storage.RootDirectory)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
}
|
}
|
||||||
|
}(c)
|
||||||
|
WaitTillServerReady(baseURL)
|
||||||
|
|
||||||
digest := "sha256:8dd57e171a61368ffcfde38045ddb6ed74a32950c271c1da93eaddfb66a77e78"
|
digest := "sha256:8dd57e171a61368ffcfde38045ddb6ed74a32950c271c1da93eaddfb66a77e78"
|
||||||
name := "zot-c-test"
|
name := "zot-c-test"
|
||||||
|
@ -2439,25 +2134,10 @@ func TestHTTPReadOnly(t *testing.T) {
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
c.Config.Storage.RootDirectory = dir
|
c.Config.Storage.RootDirectory = dir
|
||||||
go func(controller *api.Controller) {
|
|
||||||
// this blocks
|
|
||||||
if err := controller.Run(); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}(c)
|
|
||||||
// wait till ready
|
|
||||||
for {
|
|
||||||
_, err := resty.R().Get(baseURL)
|
|
||||||
if err == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
|
|
||||||
defer func(controller *api.Controller) {
|
go startServer(c)
|
||||||
ctx := context.Background()
|
defer stopServer(c)
|
||||||
_ = controller.Server.Shutdown(ctx)
|
WaitTillServerReady(baseURL)
|
||||||
}(c)
|
|
||||||
|
|
||||||
// with creds, should get expected status code
|
// with creds, should get expected status code
|
||||||
resp, _ := resty.R().SetBasicAuth(user, password).Get(baseURL + "/v2/")
|
resp, _ := resty.R().SetBasicAuth(user, password).Get(baseURL + "/v2/")
|
||||||
|
@ -2508,36 +2188,17 @@ func TestCrossRepoMount(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
|
|
||||||
c.Config.Storage.RootDirectory = dir
|
c.Config.Storage.RootDirectory = dir
|
||||||
|
|
||||||
go func() {
|
go startServer(c)
|
||||||
// this blocks
|
defer stopServer(c)
|
||||||
if err := c.Run(); err != nil {
|
WaitTillServerReady(baseURL)
|
||||||
return
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// wait till ready
|
|
||||||
for {
|
|
||||||
_, err := resty.R().Get(baseURL)
|
|
||||||
if err == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
|
|
||||||
params := make(map[string]string)
|
params := make(map[string]string)
|
||||||
|
|
||||||
digest := "sha256:63a795ca90aa6e7cca60941e826810a4cd0a2e73ea02bf458241df2a5c973e29"
|
digest := "sha256:63a795ca90aa6e7cca60941e826810a4cd0a2e73ea02bf458241df2a5c973e29"
|
||||||
|
|
||||||
d := godigest.Digest(digest)
|
d := godigest.Digest(digest)
|
||||||
|
|
||||||
name := "zot-cve-test"
|
name := "zot-cve-test"
|
||||||
|
|
||||||
params["mount"] = digest
|
params["mount"] = digest
|
||||||
params["from"] = name
|
params["from"] = name
|
||||||
|
|
||||||
|
@ -2702,8 +2363,6 @@ func TestCrossRepoMount(t *testing.T) {
|
||||||
|
|
||||||
c := api.NewController(conf)
|
c := api.NewController(conf)
|
||||||
|
|
||||||
//defer stopServer(c)
|
|
||||||
|
|
||||||
dir, err := ioutil.TempDir("", "oci-repo-test")
|
dir, err := ioutil.TempDir("", "oci-repo-test")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -2719,26 +2378,12 @@ func TestCrossRepoMount(t *testing.T) {
|
||||||
c.Config.Storage.Dedupe = false
|
c.Config.Storage.Dedupe = false
|
||||||
c.Config.Storage.GC = false
|
c.Config.Storage.GC = false
|
||||||
|
|
||||||
go func() {
|
go startServer(c)
|
||||||
// this blocks
|
defer stopServer(c)
|
||||||
if err := c.Run(); err != nil {
|
WaitTillServerReady(baseURL)
|
||||||
return
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// wait till ready
|
|
||||||
for {
|
|
||||||
_, err := resty.R().Get(baseURL)
|
|
||||||
if err == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
|
|
||||||
digest := "sha256:7a0437f04f83f084b7ed68ad9c4a4947e12fc4e1b006b38129bac89114ec3621"
|
digest := "sha256:7a0437f04f83f084b7ed68ad9c4a4947e12fc4e1b006b38129bac89114ec3621"
|
||||||
name := "zot-c-test"
|
name := "zot-c-test"
|
||||||
|
|
||||||
client := resty.New()
|
client := resty.New()
|
||||||
headResponse, err := client.R().SetBasicAuth(username, passphrase).
|
headResponse, err := client.R().SetBasicAuth(username, passphrase).
|
||||||
Head(fmt.Sprintf("%s/v2/%s/blobs/%s", baseURL, name, digest))
|
Head(fmt.Sprintf("%s/v2/%s/blobs/%s", baseURL, name, digest))
|
||||||
|
@ -2879,25 +2524,10 @@ func TestParallelRequests(t *testing.T) {
|
||||||
subPaths["/b"] = config.StorageConfig{RootDirectory: secondSubDir}
|
subPaths["/b"] = config.StorageConfig{RootDirectory: secondSubDir}
|
||||||
|
|
||||||
c.Config.Storage.SubPaths = subPaths
|
c.Config.Storage.SubPaths = subPaths
|
||||||
|
|
||||||
c.Config.Storage.RootDirectory = dir
|
c.Config.Storage.RootDirectory = dir
|
||||||
|
|
||||||
go func() {
|
go startServer(c)
|
||||||
// this blocks
|
WaitTillServerReady(baseURL)
|
||||||
if err := c.Run(); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// wait till ready
|
|
||||||
for {
|
|
||||||
_, err := resty.R().Get(baseURL)
|
|
||||||
if err == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
|
|
||||||
// without creds, should get access error
|
// without creds, should get access error
|
||||||
for i, testcase := range testCases {
|
for i, testcase := range testCases {
|
||||||
|
@ -3067,15 +2697,6 @@ func TestParallelRequests(t *testing.T) {
|
||||||
|
|
||||||
assert.Equal(t, err, nil, "Should not be nil")
|
assert.Equal(t, err, nil, "Should not be nil")
|
||||||
assert.NotEqual(t, getResponse.StatusCode(), 500, "response should return success code")
|
assert.NotEqual(t, getResponse.StatusCode(), 500, "response should return success code")
|
||||||
|
|
||||||
if i < 5 { // nolint: scopelint
|
|
||||||
deleteResponse, err := client.R().
|
|
||||||
SetBasicAuth(username, passphrase).
|
|
||||||
Delete(baseURL + "/v2/" + testcase.destImageName + "/blobs/sha256:" + blob)
|
|
||||||
|
|
||||||
assert.Equal(t, err, nil, "Should not be nil")
|
|
||||||
assert.Equal(t, deleteResponse.StatusCode(), 202, "response should return success code")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tagResponse, err = client.R().SetBasicAuth(username, passphrase).
|
tagResponse, err = client.R().SetBasicAuth(username, passphrase).
|
||||||
|
@ -3134,27 +2755,11 @@ func TestHardLink(t *testing.T) {
|
||||||
subPaths := make(map[string]config.StorageConfig)
|
subPaths := make(map[string]config.StorageConfig)
|
||||||
|
|
||||||
subPaths["/a"] = config.StorageConfig{RootDirectory: subDir, Dedupe: true}
|
subPaths["/a"] = config.StorageConfig{RootDirectory: subDir, Dedupe: true}
|
||||||
|
|
||||||
c.Config.Storage.SubPaths = subPaths
|
c.Config.Storage.SubPaths = subPaths
|
||||||
|
|
||||||
go func() {
|
go startServer(c)
|
||||||
// this blocks
|
defer stopServer(c)
|
||||||
if err := c.Run(); err != nil {
|
WaitTillServerReady(baseURL)
|
||||||
return
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
time.Sleep(5 * time.Second)
|
|
||||||
|
|
||||||
// wait till ready
|
|
||||||
for {
|
|
||||||
_, err := resty.R().Get(baseURL)
|
|
||||||
if err == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
|
|
||||||
err = os.Chmod(dir, 0644)
|
err = os.Chmod(dir, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -3244,14 +2849,14 @@ func getAllManifests(imagePath string) []string {
|
||||||
return manifestList
|
return manifestList
|
||||||
}
|
}
|
||||||
|
|
||||||
func stopServer(ctrl *api.Controller) {
|
func startServer(c *api.Controller) {
|
||||||
err := ctrl.Server.Shutdown(context.Background())
|
// this blocks
|
||||||
if err != nil {
|
if err := c.Run(); err != nil {
|
||||||
panic(err)
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = os.RemoveAll(ctrl.Config.Storage.RootDirectory)
|
func stopServer(c *api.Controller) {
|
||||||
if err != nil {
|
ctx := context.Background()
|
||||||
panic(err)
|
_ = c.Server.Shutdown(ctx)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -330,7 +330,7 @@ func TestServerCVEResponse(t *testing.T) {
|
||||||
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
time.Sleep(100 * time.Millisecond)
|
||||||
}
|
}
|
||||||
time.Sleep(35 * time.Second)
|
time.Sleep(90 * time.Second)
|
||||||
|
|
||||||
defer func(controller *api.Controller) {
|
defer func(controller *api.Controller) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
|
@ -28,7 +28,6 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
SleepTime = 50 * time.Millisecond
|
|
||||||
SecondToNanoseconds = 1000000000
|
SecondToNanoseconds = 1000000000
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -418,7 +418,7 @@ func TestCVESearch(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait for trivy db to download
|
// Wait for trivy db to download
|
||||||
time.Sleep(45 * time.Second)
|
time.Sleep(90 * time.Second)
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/phayes/freeport"
|
"github.com/phayes/freeport"
|
||||||
"gopkg.in/resty.v1"
|
"gopkg.in/resty.v1"
|
||||||
|
@ -14,6 +15,7 @@ import (
|
||||||
const (
|
const (
|
||||||
BaseURL = "http://127.0.0.1:%s"
|
BaseURL = "http://127.0.0.1:%s"
|
||||||
BaseSecureURL = "https://127.0.0.1:%s"
|
BaseSecureURL = "https://127.0.0.1:%s"
|
||||||
|
SleepTime = 100 * time.Millisecond
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetFreePort() string {
|
func GetFreePort() string {
|
||||||
|
@ -108,3 +110,14 @@ func CopyFiles(sourceDir string, destDir string) error {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func WaitTillServerReady(url string) {
|
||||||
|
for {
|
||||||
|
_, err := resty.R().Get(url)
|
||||||
|
if err == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
time.Sleep(SleepTime)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue