mirror of
https://github.com/project-zot/zot.git
synced 2025-03-25 02:32:57 -05:00
refactor: Cleanup/simplify testcases in /pkg/extensions (#1116)
Signed-off-by: Nicol Draghici <idraghic@cisco.com> fix: Increase coverage when copying files Signed-off-by: Nicol Draghici <idraghic@cisco.com>
This commit is contained in:
parent
b997176363
commit
70a60b4660
12 changed files with 224 additions and 719 deletions
|
@ -4,7 +4,6 @@
|
||||||
package extensions_test
|
package extensions_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -21,7 +20,6 @@ func TestEnableExtension(t *testing.T) {
|
||||||
Convey("Verify log if sync disabled in config", t, func() {
|
Convey("Verify log if sync disabled in config", t, func() {
|
||||||
globalDir := t.TempDir()
|
globalDir := t.TempDir()
|
||||||
port := test.GetFreePort()
|
port := test.GetFreePort()
|
||||||
baseURL := test.GetBaseURL(port)
|
|
||||||
conf := config.New()
|
conf := config.New()
|
||||||
falseValue := false
|
falseValue := false
|
||||||
|
|
||||||
|
@ -42,21 +40,13 @@ func TestEnableExtension(t *testing.T) {
|
||||||
defer os.Remove(logFile.Name()) // cleanup
|
defer os.Remove(logFile.Name()) // cleanup
|
||||||
|
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
|
ctlrManager := test.NewControllerManager(ctlr)
|
||||||
|
|
||||||
defer func() {
|
defer ctlrManager.StopServer()
|
||||||
ctx := context.Background()
|
|
||||||
_ = ctlr.Server.Shutdown(ctx)
|
|
||||||
}()
|
|
||||||
|
|
||||||
ctlr.Config.Storage.RootDirectory = globalDir
|
ctlr.Config.Storage.RootDirectory = globalDir
|
||||||
|
|
||||||
go func() {
|
ctlrManager.StartAndWait(port)
|
||||||
if err := ctlr.Run(context.Background()); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
test.WaitTillServerReady(baseURL)
|
|
||||||
|
|
||||||
data, err := os.ReadFile(logFile.Name())
|
data, err := os.ReadFile(logFile.Name())
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
@ -71,7 +61,6 @@ func TestMetricsExtension(t *testing.T) {
|
||||||
conf := config.New()
|
conf := config.New()
|
||||||
port := test.GetFreePort()
|
port := test.GetFreePort()
|
||||||
conf.HTTP.Port = port
|
conf.HTTP.Port = port
|
||||||
baseURL := test.GetBaseURL(port)
|
|
||||||
|
|
||||||
logFile, err := os.CreateTemp(globalDir, "zot-log*.txt")
|
logFile, err := os.CreateTemp(globalDir, "zot-log*.txt")
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
@ -87,6 +76,7 @@ func TestMetricsExtension(t *testing.T) {
|
||||||
defer os.Remove(logFile.Name()) // cleanup
|
defer os.Remove(logFile.Name()) // cleanup
|
||||||
|
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
|
ctlrManager := test.NewControllerManager(ctlr)
|
||||||
|
|
||||||
subPaths := make(map[string]config.StorageConfig)
|
subPaths := make(map[string]config.StorageConfig)
|
||||||
subPaths["/a"] = config.StorageConfig{}
|
subPaths["/a"] = config.StorageConfig{}
|
||||||
|
@ -94,12 +84,7 @@ func TestMetricsExtension(t *testing.T) {
|
||||||
ctlr.Config.Storage.RootDirectory = globalDir
|
ctlr.Config.Storage.RootDirectory = globalDir
|
||||||
ctlr.Config.Storage.SubPaths = subPaths
|
ctlr.Config.Storage.SubPaths = subPaths
|
||||||
|
|
||||||
go func() {
|
ctlrManager.StartAndWait(port)
|
||||||
if err := ctlr.Run(context.Background()); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
test.WaitTillServerReady(baseURL)
|
|
||||||
|
|
||||||
data, _ := os.ReadFile(logFile.Name())
|
data, _ := os.ReadFile(logFile.Name())
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package lint_test
|
package lint_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -56,16 +55,13 @@ func TestVerifyMandatoryAnnotations(t *testing.T) {
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
|
|
||||||
err := test.CopyFiles("../../../test/data", dir)
|
test.CopyTestFiles("../../../test/data", dir)
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
ctlr.Config.Storage.RootDirectory = dir
|
ctlr.Config.Storage.RootDirectory = dir
|
||||||
|
|
||||||
go startServer(ctlr)
|
cm := test.NewControllerManager(ctlr)
|
||||||
defer stopServer(ctlr)
|
cm.StartAndWait(port)
|
||||||
test.WaitTillServerReady(baseURL)
|
defer cm.StopServer()
|
||||||
|
|
||||||
resp, err := resty.R().SetBasicAuth(username, passphrase).
|
resp, err := resty.R().SetBasicAuth(username, passphrase).
|
||||||
Get(baseURL + "/v2/zot-test/manifests/0.0.1")
|
Get(baseURL + "/v2/zot-test/manifests/0.0.1")
|
||||||
|
@ -104,16 +100,13 @@ func TestVerifyMandatoryAnnotations(t *testing.T) {
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
|
|
||||||
err := test.CopyFiles("../../../test/data", dir)
|
test.CopyTestFiles("../../../test/data", dir)
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
ctlr.Config.Storage.RootDirectory = dir
|
ctlr.Config.Storage.RootDirectory = dir
|
||||||
|
|
||||||
go startServer(ctlr)
|
cm := test.NewControllerManager(ctlr)
|
||||||
defer stopServer(ctlr)
|
cm.StartAndWait(port)
|
||||||
test.WaitTillServerReady(baseURL)
|
defer cm.StopServer()
|
||||||
|
|
||||||
resp, err := resty.R().SetBasicAuth(username, passphrase).
|
resp, err := resty.R().SetBasicAuth(username, passphrase).
|
||||||
Get(baseURL + "/v2/zot-test/manifests/0.0.1")
|
Get(baseURL + "/v2/zot-test/manifests/0.0.1")
|
||||||
|
@ -152,16 +145,13 @@ func TestVerifyMandatoryAnnotations(t *testing.T) {
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
|
|
||||||
err := test.CopyFiles("../../../test/data", dir)
|
test.CopyTestFiles("../../../test/data", dir)
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
ctlr.Config.Storage.RootDirectory = dir
|
ctlr.Config.Storage.RootDirectory = dir
|
||||||
|
|
||||||
go startServer(ctlr)
|
cm := test.NewControllerManager(ctlr)
|
||||||
defer stopServer(ctlr)
|
cm.StartAndWait(port)
|
||||||
test.WaitTillServerReady(baseURL)
|
defer cm.StopServer()
|
||||||
|
|
||||||
resp, err := resty.R().SetBasicAuth(username, passphrase).
|
resp, err := resty.R().SetBasicAuth(username, passphrase).
|
||||||
Get(baseURL + "/v2/zot-test/manifests/0.0.1")
|
Get(baseURL + "/v2/zot-test/manifests/0.0.1")
|
||||||
|
@ -206,16 +196,13 @@ func TestVerifyMandatoryAnnotations(t *testing.T) {
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
|
|
||||||
err := test.CopyFiles("../../../test/data", dir)
|
test.CopyTestFiles("../../../test/data", dir)
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
ctlr.Config.Storage.RootDirectory = dir
|
ctlr.Config.Storage.RootDirectory = dir
|
||||||
|
|
||||||
go startServer(ctlr)
|
cm := test.NewControllerManager(ctlr)
|
||||||
defer stopServer(ctlr)
|
cm.StartAndWait(port)
|
||||||
test.WaitTillServerReady(baseURL)
|
defer cm.StopServer()
|
||||||
|
|
||||||
resp, err := resty.R().SetBasicAuth(username, passphrase).
|
resp, err := resty.R().SetBasicAuth(username, passphrase).
|
||||||
Get(baseURL + "/v2/zot-test/manifests/0.0.1")
|
Get(baseURL + "/v2/zot-test/manifests/0.0.1")
|
||||||
|
@ -295,16 +282,13 @@ func TestVerifyMandatoryAnnotations(t *testing.T) {
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
|
|
||||||
err := test.CopyFiles("../../../test/data", dir)
|
test.CopyTestFiles("../../../test/data", dir)
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
ctlr.Config.Storage.RootDirectory = dir
|
ctlr.Config.Storage.RootDirectory = dir
|
||||||
|
|
||||||
go startServer(ctlr)
|
cm := test.NewControllerManager(ctlr)
|
||||||
defer stopServer(ctlr)
|
cm.StartAndWait(port)
|
||||||
test.WaitTillServerReady(baseURL)
|
defer cm.StopServer()
|
||||||
|
|
||||||
resp, err := resty.R().SetBasicAuth(username, passphrase).
|
resp, err := resty.R().SetBasicAuth(username, passphrase).
|
||||||
Get(baseURL + "/v2/zot-test/manifests/0.0.1")
|
Get(baseURL + "/v2/zot-test/manifests/0.0.1")
|
||||||
|
@ -383,16 +367,13 @@ func TestVerifyMandatoryAnnotations(t *testing.T) {
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
|
|
||||||
err := test.CopyFiles("../../../test/data", dir)
|
test.CopyTestFiles("../../../test/data", dir)
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
ctlr.Config.Storage.RootDirectory = dir
|
ctlr.Config.Storage.RootDirectory = dir
|
||||||
|
|
||||||
go startServer(ctlr)
|
cm := test.NewControllerManager(ctlr)
|
||||||
defer stopServer(ctlr)
|
cm.StartAndWait(port)
|
||||||
test.WaitTillServerReady(baseURL)
|
defer cm.StopServer()
|
||||||
|
|
||||||
resp, err := resty.R().SetBasicAuth(username, passphrase).
|
resp, err := resty.R().SetBasicAuth(username, passphrase).
|
||||||
Get(baseURL + "/v2/zot-test/manifests/0.0.1")
|
Get(baseURL + "/v2/zot-test/manifests/0.0.1")
|
||||||
|
@ -435,16 +416,13 @@ func TestVerifyMandatoryAnnotations(t *testing.T) {
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
|
|
||||||
err := test.CopyFiles("../../../test/data", dir)
|
test.CopyTestFiles("../../../test/data", dir)
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
ctlr.Config.Storage.RootDirectory = dir
|
ctlr.Config.Storage.RootDirectory = dir
|
||||||
|
cm := test.NewControllerManager(ctlr)
|
||||||
|
|
||||||
go startServer(ctlr)
|
cm.StartAndWait(port)
|
||||||
defer stopServer(ctlr)
|
defer cm.StopServer()
|
||||||
test.WaitTillServerReady(baseURL)
|
|
||||||
|
|
||||||
resp, err := resty.R().SetBasicAuth(username, passphrase).
|
resp, err := resty.R().SetBasicAuth(username, passphrase).
|
||||||
Get(baseURL + "/v2/zot-test/manifests/0.0.1")
|
Get(baseURL + "/v2/zot-test/manifests/0.0.1")
|
||||||
|
@ -486,10 +464,7 @@ func TestVerifyMandatoryAnnotationsFunction(t *testing.T) {
|
||||||
|
|
||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
|
|
||||||
err := test.CopyFiles("../../../test/data", dir)
|
test.CopyTestFiles("../../../test/data", dir)
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
var index ispec.Index
|
var index ispec.Index
|
||||||
|
|
||||||
|
@ -519,10 +494,7 @@ func TestVerifyMandatoryAnnotationsFunction(t *testing.T) {
|
||||||
|
|
||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
|
|
||||||
err := test.CopyFiles("../../../test/data", dir)
|
test.CopyTestFiles("../../../test/data", dir)
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
var index ispec.Index
|
var index ispec.Index
|
||||||
|
|
||||||
|
@ -552,10 +524,7 @@ func TestVerifyMandatoryAnnotationsFunction(t *testing.T) {
|
||||||
|
|
||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
|
|
||||||
err := test.CopyFiles("../../../test/data", dir)
|
test.CopyTestFiles("../../../test/data", dir)
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
var index ispec.Index
|
var index ispec.Index
|
||||||
buf, err := os.ReadFile(path.Join(dir, "zot-test", "index.json"))
|
buf, err := os.ReadFile(path.Join(dir, "zot-test", "index.json"))
|
||||||
|
@ -616,10 +585,7 @@ func TestVerifyMandatoryAnnotationsFunction(t *testing.T) {
|
||||||
|
|
||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
|
|
||||||
err := test.CopyFiles("../../../test/data", dir)
|
test.CopyTestFiles("../../../test/data", dir)
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
var index ispec.Index
|
var index ispec.Index
|
||||||
buf, err := os.ReadFile(path.Join(dir, "zot-test", "index.json"))
|
buf, err := os.ReadFile(path.Join(dir, "zot-test", "index.json"))
|
||||||
|
@ -679,10 +645,7 @@ func TestVerifyMandatoryAnnotationsFunction(t *testing.T) {
|
||||||
|
|
||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
|
|
||||||
err := test.CopyFiles("../../../test/data", dir)
|
test.CopyTestFiles("../../../test/data", dir)
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
var index ispec.Index
|
var index ispec.Index
|
||||||
buf, err := os.ReadFile(path.Join(dir, "zot-test", "index.json"))
|
buf, err := os.ReadFile(path.Join(dir, "zot-test", "index.json"))
|
||||||
|
@ -744,10 +707,7 @@ func TestVerifyMandatoryAnnotationsFunction(t *testing.T) {
|
||||||
|
|
||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
|
|
||||||
err := test.CopyFiles("../../../test/data", dir)
|
test.CopyTestFiles("../../../test/data", dir)
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
var index ispec.Index
|
var index ispec.Index
|
||||||
buf, err := os.ReadFile(path.Join(dir, "zot-test", "index.json"))
|
buf, err := os.ReadFile(path.Join(dir, "zot-test", "index.json"))
|
||||||
|
@ -818,10 +778,7 @@ func TestVerifyMandatoryAnnotationsFunction(t *testing.T) {
|
||||||
|
|
||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
|
|
||||||
err := test.CopyFiles("../../../test/data", dir)
|
test.CopyTestFiles("../../../test/data", dir)
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
var index ispec.Index
|
var index ispec.Index
|
||||||
buf, err := os.ReadFile(path.Join(dir, "zot-test", "index.json"))
|
buf, err := os.ReadFile(path.Join(dir, "zot-test", "index.json"))
|
||||||
|
@ -907,16 +864,3 @@ func TestVerifyMandatoryAnnotationsFunction(t *testing.T) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func startServer(c *api.Controller) {
|
|
||||||
// this blocks
|
|
||||||
ctx := context.Background()
|
|
||||||
if err := c.Run(ctx); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func stopServer(c *api.Controller) {
|
|
||||||
ctx := context.Background()
|
|
||||||
_ = c.Server.Shutdown(ctx)
|
|
||||||
}
|
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package monitoring_test
|
package monitoring_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"path"
|
"path"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -40,9 +39,9 @@ func TestExtensionMetrics(t *testing.T) {
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
So(ctlr, ShouldNotBeNil)
|
So(ctlr, ShouldNotBeNil)
|
||||||
|
|
||||||
go startServer(ctlr)
|
cm := test.NewControllerManager(ctlr)
|
||||||
defer stopServer(ctlr)
|
cm.StartAndWait(port)
|
||||||
test.WaitTillServerReady(baseURL)
|
defer cm.StopServer()
|
||||||
|
|
||||||
// improve code coverage
|
// improve code coverage
|
||||||
ctlr.Metrics.SendMetric(baseURL)
|
ctlr.Metrics.SendMetric(baseURL)
|
||||||
|
@ -56,10 +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"))
|
test.CopyTestFiles("../../../test/data/zot-test", path.Join(rootDir, "alpine"))
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
monitoring.SetStorageUsage(ctlr.Metrics, rootDir, "alpine")
|
monitoring.SetStorageUsage(ctlr.Metrics, rootDir, "alpine")
|
||||||
|
|
||||||
monitoring.ObserveStorageLockLatency(ctlr.Metrics, time.Millisecond, rootDir, "RWLock")
|
monitoring.ObserveStorageLockLatency(ctlr.Metrics, time.Millisecond, rootDir, "RWLock")
|
||||||
|
@ -91,9 +87,9 @@ func TestExtensionMetrics(t *testing.T) {
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
So(ctlr, ShouldNotBeNil)
|
So(ctlr, ShouldNotBeNil)
|
||||||
|
|
||||||
go startServer(ctlr)
|
cm := test.NewControllerManager(ctlr)
|
||||||
defer stopServer(ctlr)
|
cm.StartAndWait(port)
|
||||||
test.WaitTillServerReady(baseURL)
|
defer cm.StopServer()
|
||||||
|
|
||||||
So(ctlr.Metrics.IsEnabled(), ShouldBeFalse)
|
So(ctlr.Metrics.IsEnabled(), ShouldBeFalse)
|
||||||
|
|
||||||
|
@ -103,15 +99,3 @@ func TestExtensionMetrics(t *testing.T) {
|
||||||
So(resp.StatusCode(), ShouldEqual, http.StatusNotFound)
|
So(resp.StatusCode(), ShouldEqual, http.StatusNotFound)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func startServer(c *api.Controller) {
|
|
||||||
// this blocks
|
|
||||||
if err := c.Run(context.Background()); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func stopServer(c *api.Controller) {
|
|
||||||
ctx := context.Background()
|
|
||||||
_ = c.Server.Shutdown(ctx)
|
|
||||||
}
|
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package scrub_test
|
package scrub_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
@ -13,7 +12,6 @@ import (
|
||||||
|
|
||||||
godigest "github.com/opencontainers/go-digest"
|
godigest "github.com/opencontainers/go-digest"
|
||||||
. "github.com/smartystreets/goconvey/convey"
|
. "github.com/smartystreets/goconvey/convey"
|
||||||
"gopkg.in/resty.v1"
|
|
||||||
|
|
||||||
"zotregistry.io/zot/pkg/api"
|
"zotregistry.io/zot/pkg/api"
|
||||||
"zotregistry.io/zot/pkg/api/config"
|
"zotregistry.io/zot/pkg/api/config"
|
||||||
|
@ -34,7 +32,6 @@ const (
|
||||||
func TestScrubExtension(t *testing.T) {
|
func TestScrubExtension(t *testing.T) {
|
||||||
Convey("Blobs integrity not affected", t, func(c C) {
|
Convey("Blobs integrity not affected", t, func(c C) {
|
||||||
port := test.GetFreePort()
|
port := test.GetFreePort()
|
||||||
url := test.GetBaseURL(port)
|
|
||||||
|
|
||||||
logFile, err := os.CreateTemp("", "zot-log*.txt")
|
logFile, err := os.CreateTemp("", "zot-log*.txt")
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
@ -62,33 +59,13 @@ func TestScrubExtension(t *testing.T) {
|
||||||
|
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
|
|
||||||
err = test.CopyFiles("../../../test/data/zot-test", path.Join(dir, repoName))
|
test.CopyTestFiles("../../../test/data/zot-test", path.Join(dir, repoName))
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
go func(controller *api.Controller) {
|
cm := test.NewControllerManager(ctlr)
|
||||||
// this blocks
|
cm.StartAndWait(port)
|
||||||
if err := controller.Run(context.Background()); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}(ctlr)
|
|
||||||
|
|
||||||
// wait till ready
|
|
||||||
for {
|
|
||||||
_, err := resty.R().Get(url)
|
|
||||||
if err == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
time.Sleep(6 * time.Second)
|
time.Sleep(6 * time.Second)
|
||||||
|
|
||||||
defer func(controller *api.Controller) {
|
defer cm.StopServer()
|
||||||
ctx := context.Background()
|
|
||||||
_ = controller.Server.Shutdown(ctx)
|
|
||||||
}(ctlr)
|
|
||||||
|
|
||||||
data, err := os.ReadFile(logFile.Name())
|
data, err := os.ReadFile(logFile.Name())
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
@ -97,7 +74,6 @@ func TestScrubExtension(t *testing.T) {
|
||||||
|
|
||||||
Convey("Blobs integrity affected", t, func(c C) {
|
Convey("Blobs integrity affected", t, func(c C) {
|
||||||
port := test.GetFreePort()
|
port := test.GetFreePort()
|
||||||
url := test.GetBaseURL(port)
|
|
||||||
|
|
||||||
logFile, err := os.CreateTemp("", "zot-log*.txt")
|
logFile, err := os.CreateTemp("", "zot-log*.txt")
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
@ -122,10 +98,7 @@ func TestScrubExtension(t *testing.T) {
|
||||||
|
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
|
|
||||||
err = test.CopyFiles("../../../test/data/zot-test", path.Join(dir, repoName))
|
test.CopyTestFiles("../../../test/data/zot-test", path.Join(dir, repoName))
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
var manifestDigest godigest.Digest
|
var manifestDigest godigest.Digest
|
||||||
manifestDigest, _, _ = test.GetOciLayoutDigests("../../../test/data/zot-test")
|
manifestDigest, _, _ = test.GetOciLayoutDigests("../../../test/data/zot-test")
|
||||||
|
|
||||||
|
@ -134,28 +107,11 @@ func TestScrubExtension(t *testing.T) {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
go func(controller *api.Controller) {
|
cm := test.NewControllerManager(ctlr)
|
||||||
// this blocks
|
cm.StartAndWait(port)
|
||||||
if err := controller.Run(context.Background()); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}(ctlr)
|
|
||||||
|
|
||||||
// wait till ready
|
|
||||||
for {
|
|
||||||
_, err := resty.R().Get(url)
|
|
||||||
if err == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
time.Sleep(6 * time.Second)
|
time.Sleep(6 * time.Second)
|
||||||
|
|
||||||
defer func(controller *api.Controller) {
|
defer cm.StopServer()
|
||||||
ctx := context.Background()
|
|
||||||
_ = controller.Server.Shutdown(ctx)
|
|
||||||
}(ctlr)
|
|
||||||
|
|
||||||
data, err := os.ReadFile(logFile.Name())
|
data, err := os.ReadFile(logFile.Name())
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
@ -164,7 +120,6 @@ func TestScrubExtension(t *testing.T) {
|
||||||
|
|
||||||
Convey("Generator error - not enough permissions to access root directory", t, func(c C) {
|
Convey("Generator error - not enough permissions to access root directory", t, func(c C) {
|
||||||
port := test.GetFreePort()
|
port := test.GetFreePort()
|
||||||
url := test.GetBaseURL(port)
|
|
||||||
|
|
||||||
logFile, err := os.CreateTemp("", "zot-log*.txt")
|
logFile, err := os.CreateTemp("", "zot-log*.txt")
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
@ -189,35 +144,15 @@ func TestScrubExtension(t *testing.T) {
|
||||||
|
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
|
|
||||||
err = test.CopyFiles("../../../test/data/zot-test", path.Join(dir, repoName))
|
test.CopyTestFiles("../../../test/data/zot-test", path.Join(dir, repoName))
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
So(os.Chmod(path.Join(dir, repoName), 0o000), ShouldBeNil)
|
So(os.Chmod(path.Join(dir, repoName), 0o000), ShouldBeNil)
|
||||||
|
|
||||||
go func(controller *api.Controller) {
|
cm := test.NewControllerManager(ctlr)
|
||||||
// this blocks
|
cm.StartAndWait(port)
|
||||||
if err := controller.Run(context.Background()); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}(ctlr)
|
|
||||||
|
|
||||||
// wait till ready
|
|
||||||
for {
|
|
||||||
_, err := resty.R().Get(url)
|
|
||||||
if err == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
time.Sleep(6 * time.Second)
|
time.Sleep(6 * time.Second)
|
||||||
|
|
||||||
defer func(controller *api.Controller) {
|
defer cm.StopServer()
|
||||||
ctx := context.Background()
|
|
||||||
_ = controller.Server.Shutdown(ctx)
|
|
||||||
}(ctlr)
|
|
||||||
|
|
||||||
data, err := os.ReadFile(logFile.Name())
|
data, err := os.ReadFile(logFile.Name())
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
@ -249,10 +184,7 @@ func TestRunScrubRepo(t *testing.T) {
|
||||||
imgStore := local.NewImageStore(dir, true, 1*time.Second, true,
|
imgStore := local.NewImageStore(dir, true, 1*time.Second, true,
|
||||||
true, log, metrics, nil, cacheDriver)
|
true, log, metrics, nil, cacheDriver)
|
||||||
|
|
||||||
err = test.CopyFiles("../../../test/data/zot-test", path.Join(dir, repoName))
|
test.CopyTestFiles("../../../test/data/zot-test", path.Join(dir, repoName))
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
err = scrub.RunScrubRepo(imgStore, repoName, log)
|
err = scrub.RunScrubRepo(imgStore, repoName, log)
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
@ -284,10 +216,7 @@ func TestRunScrubRepo(t *testing.T) {
|
||||||
imgStore := local.NewImageStore(dir, true, 1*time.Second, true,
|
imgStore := local.NewImageStore(dir, true, 1*time.Second, true,
|
||||||
true, log, metrics, nil, cacheDriver)
|
true, log, metrics, nil, cacheDriver)
|
||||||
|
|
||||||
err = test.CopyFiles("../../../test/data/zot-test", path.Join(dir, repoName))
|
test.CopyTestFiles("../../../test/data/zot-test", path.Join(dir, repoName))
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
var manifestDigest godigest.Digest
|
var manifestDigest godigest.Digest
|
||||||
manifestDigest, _, _ = test.GetOciLayoutDigests("../../../test/data/zot-test")
|
manifestDigest, _, _ = test.GetOciLayoutDigests("../../../test/data/zot-test")
|
||||||
|
|
||||||
|
@ -326,10 +255,7 @@ func TestRunScrubRepo(t *testing.T) {
|
||||||
true, true, log, metrics, nil, cacheDriver,
|
true, true, log, metrics, nil, cacheDriver,
|
||||||
)
|
)
|
||||||
|
|
||||||
err = test.CopyFiles("../../../test/data/zot-test", path.Join(dir, repoName))
|
test.CopyTestFiles("../../../test/data/zot-test", path.Join(dir, repoName))
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
So(os.Chmod(path.Join(dir, repoName), 0o000), ShouldBeNil)
|
So(os.Chmod(path.Join(dir, repoName), 0o000), ShouldBeNil)
|
||||||
|
|
||||||
|
|
|
@ -156,10 +156,7 @@ func testSetup(t *testing.T, subpath string) error { //nolint:unparam
|
||||||
|
|
||||||
subRootDir = subDir
|
subRootDir = subDir
|
||||||
|
|
||||||
err := CopyFiles("../../../../test/data", rootDir)
|
CopyTestFiles("../../../../test/data", rootDir)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return CopyFiles("../../../../test/data", path.Join(subDir, subpath))
|
return CopyFiles("../../../../test/data", path.Join(subDir, subpath))
|
||||||
}
|
}
|
||||||
|
@ -324,9 +321,9 @@ func TestRepoListWithNewestImage(t *testing.T) {
|
||||||
|
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
|
|
||||||
go startServer(ctlr)
|
ctlrManager := NewControllerManager(ctlr)
|
||||||
defer stopServer(ctlr)
|
ctlrManager.StartAndWait(port)
|
||||||
WaitTillServerReady(baseURL)
|
defer ctlrManager.StopServer()
|
||||||
|
|
||||||
resp, err := resty.R().Get(baseURL + "/v2/")
|
resp, err := resty.R().Get(baseURL + "/v2/")
|
||||||
So(resp, ShouldNotBeNil)
|
So(resp, ShouldNotBeNil)
|
||||||
|
@ -618,9 +615,9 @@ func TestRepoListWithNewestImage(t *testing.T) {
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
ctlr.Log.Logger = ctlr.Log.Output(writers)
|
ctlr.Log.Logger = ctlr.Log.Output(writers)
|
||||||
|
|
||||||
go startServer(ctlr)
|
ctlrManager := NewControllerManager(ctlr)
|
||||||
defer stopServer(ctlr)
|
ctlrManager.StartAndWait(port)
|
||||||
WaitTillServerReady(baseURL)
|
defer ctlrManager.StopServer()
|
||||||
|
|
||||||
substring := "{\"Search\":{\"Enable\":true,\"CVE\":{\"UpdateInterval\":3600000000000,\"Trivy\":{\"DBRepository\":\"ghcr.io/project-zot/trivy-db\"}}}" //nolint: lll
|
substring := "{\"Search\":{\"Enable\":true,\"CVE\":{\"UpdateInterval\":3600000000000,\"Trivy\":{\"DBRepository\":\"ghcr.io/project-zot/trivy-db\"}}}" //nolint: lll
|
||||||
found, err := readFileAndSearchString(logPath, substring, 2*time.Minute)
|
found, err := readFileAndSearchString(logPath, substring, 2*time.Minute)
|
||||||
|
@ -717,11 +714,9 @@ func TestGetReferrersGQL(t *testing.T) {
|
||||||
conf.Extensions.Search.CVE = nil
|
conf.Extensions.Search.CVE = nil
|
||||||
|
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
|
ctlrManager := NewControllerManager(ctlr)
|
||||||
go startServer(ctlr)
|
ctlrManager.StartAndWait(port)
|
||||||
defer stopServer(ctlr)
|
defer ctlrManager.StopServer()
|
||||||
|
|
||||||
WaitTillServerReady(baseURL)
|
|
||||||
|
|
||||||
// =======================
|
// =======================
|
||||||
|
|
||||||
|
@ -893,9 +888,9 @@ func TestExpandedRepoInfo(t *testing.T) {
|
||||||
err = os.WriteFile(indexPath, buf, 0o600)
|
err = os.WriteFile(indexPath, buf, 0o600)
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
go startServer(ctlr)
|
ctlrManager := NewControllerManager(ctlr)
|
||||||
defer stopServer(ctlr)
|
ctlrManager.StartAndWait(port)
|
||||||
WaitTillServerReady(baseURL)
|
defer ctlrManager.StopServer()
|
||||||
|
|
||||||
query := "{ExpandedRepoInfo(repo:\"test1\"){Summary%20{Name%20LastUpdated%20Size%20Platforms%20{Os%20Arch}%20Vendors%20Score}%20Images%20{Digest%20IsSigned%20Tag%20Layers%20{Size%20Digest}}}}" //nolint: lll
|
query := "{ExpandedRepoInfo(repo:\"test1\"){Summary%20{Name%20LastUpdated%20Size%20Platforms%20{Os%20Arch}%20Vendors%20Score}%20Images%20{Digest%20IsSigned%20Tag%20Layers%20{Size%20Digest}}}}" //nolint: lll
|
||||||
|
|
||||||
|
@ -934,10 +929,9 @@ func TestExpandedRepoInfo(t *testing.T) {
|
||||||
conf.Extensions.Search.CVE = nil
|
conf.Extensions.Search.CVE = nil
|
||||||
|
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
|
ctlrManager := NewControllerManager(ctlr)
|
||||||
go startServer(ctlr)
|
ctlrManager.StartAndWait(port)
|
||||||
defer stopServer(ctlr)
|
defer ctlrManager.StopServer()
|
||||||
WaitTillServerReady(baseURL)
|
|
||||||
|
|
||||||
log := log.NewLogger("debug", "")
|
log := log.NewLogger("debug", "")
|
||||||
metrics := monitoring.NewMetricsServer(false, log)
|
metrics := monitoring.NewMetricsServer(false, log)
|
||||||
|
@ -1232,30 +1226,10 @@ func TestDerivedImageList(t *testing.T) {
|
||||||
conf.Extensions.Search.CVE = nil
|
conf.Extensions.Search.CVE = nil
|
||||||
|
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
|
ctlrManager := NewControllerManager(ctlr)
|
||||||
|
|
||||||
go func() {
|
ctlrManager.StartAndWait(port)
|
||||||
// this blocks
|
defer ctlrManager.StopServer()
|
||||||
if err := ctlr.Run(context.Background()); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// wait till ready
|
|
||||||
for {
|
|
||||||
_, err := resty.R().Get(baseURL)
|
|
||||||
if err == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
|
|
||||||
// shut down server
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
ctx := context.Background()
|
|
||||||
_ = ctlr.Server.Shutdown(ctx)
|
|
||||||
}()
|
|
||||||
|
|
||||||
Convey("Test dependency list for image working", t, func() {
|
Convey("Test dependency list for image working", t, func() {
|
||||||
// create test images
|
// create test images
|
||||||
|
@ -1583,9 +1557,9 @@ func TestDerivedImageListNoRepos(t *testing.T) {
|
||||||
|
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
|
|
||||||
go startServer(ctlr)
|
ctlrManager := NewControllerManager(ctlr)
|
||||||
defer stopServer(ctlr)
|
ctlrManager.StartAndWait(port)
|
||||||
WaitTillServerReady(baseURL)
|
defer ctlrManager.StopServer()
|
||||||
|
|
||||||
query := `
|
query := `
|
||||||
{
|
{
|
||||||
|
@ -1659,30 +1633,10 @@ func TestBaseImageList(t *testing.T) {
|
||||||
conf.Extensions.Search.CVE = nil
|
conf.Extensions.Search.CVE = nil
|
||||||
|
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
|
ctlrManager := NewControllerManager(ctlr)
|
||||||
|
|
||||||
go func() {
|
ctlrManager.StartAndWait(port)
|
||||||
// this blocks
|
defer ctlrManager.StopServer()
|
||||||
if err := ctlr.Run(context.Background()); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// wait till ready
|
|
||||||
for {
|
|
||||||
_, err := resty.R().Get(baseURL)
|
|
||||||
if err == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
|
|
||||||
// shut down server
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
ctx := context.Background()
|
|
||||||
_ = ctlr.Server.Shutdown(ctx)
|
|
||||||
}()
|
|
||||||
|
|
||||||
Convey("Test base image list for image working", t, func() {
|
Convey("Test base image list for image working", t, func() {
|
||||||
// create test images
|
// create test images
|
||||||
|
@ -2110,9 +2064,9 @@ func TestBaseImageListNoRepos(t *testing.T) {
|
||||||
|
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
|
|
||||||
go startServer(ctlr)
|
ctlrManager := NewControllerManager(ctlr)
|
||||||
defer stopServer(ctlr)
|
ctlrManager.StartAndWait(port)
|
||||||
WaitTillServerReady(baseURL)
|
defer ctlrManager.StopServer()
|
||||||
|
|
||||||
query := `
|
query := `
|
||||||
{
|
{
|
||||||
|
@ -2179,10 +2133,10 @@ func TestGlobalSearchImageAuthor(t *testing.T) {
|
||||||
conf.Extensions.Search.CVE = nil
|
conf.Extensions.Search.CVE = nil
|
||||||
|
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
|
ctlrManager := NewControllerManager(ctlr)
|
||||||
|
|
||||||
go startServer(ctlr)
|
ctlrManager.StartAndWait(port)
|
||||||
defer stopServer(ctlr)
|
defer ctlrManager.StopServer()
|
||||||
WaitTillServerReady(baseURL)
|
|
||||||
|
|
||||||
Convey("Test global search with author in manifest's annotations", t, func() {
|
Convey("Test global search with author in manifest's annotations", t, func() {
|
||||||
cfg, layers, manifest, err := GetImageComponents(10000)
|
cfg, layers, manifest, err := GetImageComponents(10000)
|
||||||
|
@ -2342,9 +2296,9 @@ func TestGlobalSearch(t *testing.T) {
|
||||||
|
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
|
|
||||||
go startServer(ctlr)
|
ctlrManager := NewControllerManager(ctlr)
|
||||||
defer stopServer(ctlr)
|
ctlrManager.StartAndWait(port)
|
||||||
WaitTillServerReady(baseURL)
|
defer ctlrManager.StopServer()
|
||||||
|
|
||||||
// push test images to repo 1 image 1
|
// push test images to repo 1 image 1
|
||||||
config1, layers1, manifest1, err := GetImageComponents(100)
|
config1, layers1, manifest1, err := GetImageComponents(100)
|
||||||
|
@ -2662,9 +2616,9 @@ func TestGlobalSearch(t *testing.T) {
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
ctlr.Log.Logger = ctlr.Log.Output(writers)
|
ctlr.Log.Logger = ctlr.Log.Output(writers)
|
||||||
|
|
||||||
go startServer(ctlr)
|
ctlrManager := NewControllerManager(ctlr)
|
||||||
defer stopServer(ctlr)
|
ctlrManager.StartAndWait(port)
|
||||||
WaitTillServerReady(baseURL)
|
defer ctlrManager.StopServer()
|
||||||
|
|
||||||
// Wait for trivy db to download
|
// Wait for trivy db to download
|
||||||
substring := "{\"Search\":{\"Enable\":true,\"CVE\":{\"UpdateInterval\":3600000000000,\"Trivy\":{\"DBRepository\":\"ghcr.io/project-zot/trivy-db\"}}}" //nolint: lll
|
substring := "{\"Search\":{\"Enable\":true,\"CVE\":{\"UpdateInterval\":3600000000000,\"Trivy\":{\"DBRepository\":\"ghcr.io/project-zot/trivy-db\"}}}" //nolint: lll
|
||||||
|
@ -2934,9 +2888,9 @@ func TestCleaningFilteringParamsGlobalSearch(t *testing.T) {
|
||||||
|
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
|
|
||||||
go startServer(ctlr)
|
ctlrManager := NewControllerManager(ctlr)
|
||||||
defer stopServer(ctlr)
|
ctlrManager.StartAndWait(port)
|
||||||
WaitTillServerReady(baseURL)
|
defer ctlrManager.StopServer()
|
||||||
|
|
||||||
config, layers, manifest, err := GetImageWithConfig(ispec.Image{
|
config, layers, manifest, err := GetImageWithConfig(ispec.Image{
|
||||||
Platform: ispec.Platform{
|
Platform: ispec.Platform{
|
||||||
|
@ -3016,9 +2970,9 @@ func TestGlobalSearchFiltering(t *testing.T) {
|
||||||
|
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
|
|
||||||
go startServer(ctlr)
|
ctlrManager := NewControllerManager(ctlr)
|
||||||
defer stopServer(ctlr)
|
ctlrManager.StartAndWait(port)
|
||||||
WaitTillServerReady(baseURL)
|
defer ctlrManager.StopServer()
|
||||||
|
|
||||||
config, layers, manifest, err := GetRandomImageComponents(100)
|
config, layers, manifest, err := GetRandomImageComponents(100)
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
@ -3093,9 +3047,9 @@ func TestGlobalSearchWithInvalidInput(t *testing.T) {
|
||||||
|
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
|
|
||||||
go startServer(ctlr)
|
ctlrManager := NewControllerManager(ctlr)
|
||||||
defer stopServer(ctlr)
|
ctlrManager.StartAndWait(port)
|
||||||
WaitTillServerReady(baseURL)
|
defer ctlrManager.StopServer()
|
||||||
|
|
||||||
longString := RandomString(1000)
|
longString := RandomString(1000)
|
||||||
|
|
||||||
|
@ -3191,9 +3145,9 @@ func TestImageList(t *testing.T) {
|
||||||
|
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
|
|
||||||
go startServer(ctlr)
|
ctlrManager := NewControllerManager(ctlr)
|
||||||
defer stopServer(ctlr)
|
ctlrManager.StartAndWait(port)
|
||||||
WaitTillServerReady(baseURL)
|
defer ctlrManager.StopServer()
|
||||||
|
|
||||||
imageStore := ctlr.StoreController.DefaultStore
|
imageStore := ctlr.StoreController.DefaultStore
|
||||||
|
|
||||||
|
@ -3263,9 +3217,9 @@ func TestImageList(t *testing.T) {
|
||||||
|
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
|
|
||||||
go startServer(ctlr)
|
ctlrManager := NewControllerManager(ctlr)
|
||||||
defer stopServer(ctlr)
|
ctlrManager.StartAndWait(port)
|
||||||
WaitTillServerReady(baseURL)
|
defer ctlrManager.StopServer()
|
||||||
|
|
||||||
config := ispec.Image{
|
config := ispec.Image{
|
||||||
Platform: ispec.Platform{
|
Platform: ispec.Platform{
|
||||||
|
@ -3374,9 +3328,9 @@ func TestGlobalSearchPagination(t *testing.T) {
|
||||||
|
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
|
|
||||||
go startServer(ctlr)
|
ctlrManager := NewControllerManager(ctlr)
|
||||||
defer stopServer(ctlr)
|
ctlrManager.StartAndWait(port)
|
||||||
WaitTillServerReady(baseURL)
|
defer ctlrManager.StopServer()
|
||||||
|
|
||||||
for i := 0; i < 3; i++ {
|
for i := 0; i < 3; i++ {
|
||||||
config, layers, manifest, err := GetImageComponents(10)
|
config, layers, manifest, err := GetImageComponents(10)
|
||||||
|
@ -3569,9 +3523,9 @@ func TestBuildImageInfo(t *testing.T) {
|
||||||
|
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
|
|
||||||
go startServer(ctlr)
|
ctlrManager := NewControllerManager(ctlr)
|
||||||
defer stopServer(ctlr)
|
ctlrManager.StartAndWait(port)
|
||||||
WaitTillServerReady(baseURL)
|
defer ctlrManager.StopServer()
|
||||||
|
|
||||||
olu := &common.BaseOciLayoutUtils{
|
olu := &common.BaseOciLayoutUtils{
|
||||||
StoreController: ctlr.StoreController,
|
StoreController: ctlr.StoreController,
|
||||||
|
@ -3683,9 +3637,9 @@ func TestRepoDBWhenSigningImages(t *testing.T) {
|
||||||
|
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
|
|
||||||
go startServer(ctlr)
|
ctlrManager := NewControllerManager(ctlr)
|
||||||
defer stopServer(ctlr)
|
ctlrManager.StartAndWait(port)
|
||||||
WaitTillServerReady(baseURL)
|
defer ctlrManager.StopServer()
|
||||||
|
|
||||||
// push test images to repo 1 image 1
|
// push test images to repo 1 image 1
|
||||||
config1, layers1, manifest1, err := GetImageComponents(100)
|
config1, layers1, manifest1, err := GetImageComponents(100)
|
||||||
|
@ -3868,9 +3822,9 @@ func TestRepoDBWhenPushingImages(t *testing.T) {
|
||||||
|
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
|
|
||||||
go startServer(ctlr)
|
ctlrManager := NewControllerManager(ctlr)
|
||||||
defer stopServer(ctlr)
|
ctlrManager.StartAndWait(port)
|
||||||
WaitTillServerReady(baseURL)
|
defer ctlrManager.StopServer()
|
||||||
|
|
||||||
Convey("SetManifestMeta fails", func() {
|
Convey("SetManifestMeta fails", func() {
|
||||||
ctlr.RepoDB = mocks.RepoDBMock{
|
ctlr.RepoDB = mocks.RepoDBMock{
|
||||||
|
@ -3960,9 +3914,9 @@ func TestRepoDBWhenReadingImages(t *testing.T) {
|
||||||
|
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
|
|
||||||
go startServer(ctlr)
|
ctlrManager := NewControllerManager(ctlr)
|
||||||
defer stopServer(ctlr)
|
ctlrManager.StartAndWait(port)
|
||||||
WaitTillServerReady(baseURL)
|
defer ctlrManager.StopServer()
|
||||||
|
|
||||||
config1, layers1, manifest1, err := GetImageComponents(100)
|
config1, layers1, manifest1, err := GetImageComponents(100)
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
@ -4053,9 +4007,9 @@ func TestRepoDBWhenDeletingImages(t *testing.T) {
|
||||||
|
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
|
|
||||||
go startServer(ctlr)
|
ctlrManager := NewControllerManager(ctlr)
|
||||||
defer stopServer(ctlr)
|
ctlrManager.StartAndWait(port)
|
||||||
WaitTillServerReady(baseURL)
|
defer ctlrManager.StopServer()
|
||||||
|
|
||||||
// push test images to repo 1 image 1
|
// push test images to repo 1 image 1
|
||||||
config1, layers1, manifest1, err := GetImageComponents(100)
|
config1, layers1, manifest1, err := GetImageComponents(100)
|
||||||
|
@ -4634,9 +4588,9 @@ func TestSearchSize(t *testing.T) {
|
||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
ctlr.Config.Storage.RootDirectory = dir
|
ctlr.Config.Storage.RootDirectory = dir
|
||||||
|
|
||||||
go startServer(ctlr)
|
ctlrManager := NewControllerManager(ctlr)
|
||||||
defer stopServer(ctlr)
|
ctlrManager.StartAndWait(port)
|
||||||
WaitTillServerReady(baseURL)
|
defer ctlrManager.StopServer()
|
||||||
|
|
||||||
repoName := "testrepo"
|
repoName := "testrepo"
|
||||||
config, layers, manifest, err := GetImageComponents(10000)
|
config, layers, manifest, err := GetImageComponents(10000)
|
||||||
|
@ -4855,9 +4809,9 @@ func TestImageSummary(t *testing.T) {
|
||||||
configBlob, errConfig := json.Marshal(config)
|
configBlob, errConfig := json.Marshal(config)
|
||||||
configDigest := godigest.FromBytes(configBlob)
|
configDigest := godigest.FromBytes(configBlob)
|
||||||
So(errConfig, ShouldBeNil) // marshall success, config is valid JSON
|
So(errConfig, ShouldBeNil) // marshall success, config is valid JSON
|
||||||
go startServer(ctlr)
|
ctlrManager := NewControllerManager(ctlr)
|
||||||
defer stopServer(ctlr)
|
ctlrManager.StartAndWait(port)
|
||||||
WaitTillServerReady(baseURL)
|
defer ctlrManager.StopServer()
|
||||||
|
|
||||||
manifestBlob, errMarsal := json.Marshal(manifest)
|
manifestBlob, errMarsal := json.Marshal(manifest)
|
||||||
So(errMarsal, ShouldBeNil)
|
So(errMarsal, ShouldBeNil)
|
||||||
|
@ -5037,9 +4991,9 @@ func TestImageSummary(t *testing.T) {
|
||||||
configBlob, errConfig := json.Marshal(config)
|
configBlob, errConfig := json.Marshal(config)
|
||||||
configDigest := godigest.FromBytes(configBlob)
|
configDigest := godigest.FromBytes(configBlob)
|
||||||
So(errConfig, ShouldBeNil) // marshall success, config is valid JSON
|
So(errConfig, ShouldBeNil) // marshall success, config is valid JSON
|
||||||
go startServer(ctlr)
|
ctlrManager := NewControllerManager(ctlr)
|
||||||
defer stopServer(ctlr)
|
ctlrManager.StartAndWait(port)
|
||||||
WaitTillServerReady(baseURL)
|
defer ctlrManager.StopServer()
|
||||||
|
|
||||||
manifestBlob, errMarsal := json.Marshal(manifest)
|
manifestBlob, errMarsal := json.Marshal(manifest)
|
||||||
So(errMarsal, ShouldBeNil)
|
So(errMarsal, ShouldBeNil)
|
||||||
|
@ -5102,16 +5056,3 @@ func TestImageSummary(t *testing.T) {
|
||||||
So(imgSummary.Vulnerabilities.MaxSeverity, ShouldEqual, "NONE")
|
So(imgSummary.Vulnerabilities.MaxSeverity, ShouldEqual, "NONE")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func startServer(c *api.Controller) {
|
|
||||||
// this blocks
|
|
||||||
ctx := context.Background()
|
|
||||||
if err := c.Run(ctx); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func stopServer(c *api.Controller) {
|
|
||||||
ctx := context.Background()
|
|
||||||
_ = c.Server.Shutdown(ctx)
|
|
||||||
}
|
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
package cveinfo_test
|
package cveinfo_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
@ -410,22 +409,9 @@ func TestCVESearchDisabled(t *testing.T) {
|
||||||
|
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
ctlr.Log.Logger = ctlr.Log.Output(writers)
|
ctlr.Log.Logger = ctlr.Log.Output(writers)
|
||||||
|
ctrlManager := NewControllerManager(ctlr)
|
||||||
|
|
||||||
go func() {
|
ctrlManager.StartAndWait(port)
|
||||||
// this blocks
|
|
||||||
if err := ctlr.Run(context.Background()); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// wait till ready
|
|
||||||
for {
|
|
||||||
_, err := resty.R().Get(baseURL)
|
|
||||||
if err == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wait for trivy db to download
|
// Wait for trivy db to download
|
||||||
_, err = ReadLogFileAndSearchString(logPath, "DB update completed, next update scheduled", 90*time.Second)
|
_, err = ReadLogFileAndSearchString(logPath, "DB update completed, next update scheduled", 90*time.Second)
|
||||||
|
@ -433,10 +419,7 @@ func TestCVESearchDisabled(t *testing.T) {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer ctrlManager.StopServer()
|
||||||
ctx := context.Background()
|
|
||||||
_ = ctlr.Server.Shutdown(ctx)
|
|
||||||
}()
|
|
||||||
|
|
||||||
resp, _ := resty.R().SetBasicAuth(username, passphrase).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-test\"){Tag%20CVEList{Id%20Description%20Severity%20PackageList{Name%20InstalledVersion%20FixedVersion}}}}")
|
resp, _ := resty.R().SetBasicAuth(username, passphrase).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-test\"){Tag%20CVEList{Id%20Description%20Severity%20PackageList{Name%20InstalledVersion%20FixedVersion}}}}")
|
||||||
So(string(resp.Body()), ShouldContainSubstring, "search: CVE search is disabled")
|
So(string(resp.Body()), ShouldContainSubstring, "search: CVE search is disabled")
|
||||||
|
@ -502,22 +485,9 @@ func TestCVESearch(t *testing.T) {
|
||||||
|
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
ctlr.Log.Logger = ctlr.Log.Output(writers)
|
ctlr.Log.Logger = ctlr.Log.Output(writers)
|
||||||
|
ctrlManager := NewControllerManager(ctlr)
|
||||||
|
|
||||||
go func() {
|
ctrlManager.StartAndWait(port)
|
||||||
// this blocks
|
|
||||||
if err := ctlr.Run(context.Background()); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// wait till ready
|
|
||||||
for {
|
|
||||||
_, err := resty.R().Get(baseURL)
|
|
||||||
if err == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wait for trivy db to download
|
// Wait for trivy db to download
|
||||||
_, err = ReadLogFileAndSearchString(logPath, "DB update completed, next update scheduled", 90*time.Second)
|
_, err = ReadLogFileAndSearchString(logPath, "DB update completed, next update scheduled", 90*time.Second)
|
||||||
|
@ -525,10 +495,7 @@ func TestCVESearch(t *testing.T) {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer ctrlManager.StopServer()
|
||||||
ctx := context.Background()
|
|
||||||
_ = ctlr.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/")
|
||||||
|
@ -740,10 +707,7 @@ func TestCVEConfig(t *testing.T) {
|
||||||
|
|
||||||
secondDir := t.TempDir()
|
secondDir := t.TempDir()
|
||||||
|
|
||||||
err := CopyFiles("../../../../test/data", path.Join(secondDir, "a"))
|
CopyTestFiles("../../../../test/data", path.Join(secondDir, "a"))
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
ctlr.Config.Storage.RootDirectory = firstDir
|
ctlr.Config.Storage.RootDirectory = firstDir
|
||||||
subPaths := make(map[string]config.StorageConfig)
|
subPaths := make(map[string]config.StorageConfig)
|
||||||
|
@ -752,22 +716,9 @@ func TestCVEConfig(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ctlr.Config.Storage.SubPaths = subPaths
|
ctlr.Config.Storage.SubPaths = subPaths
|
||||||
|
ctrlManager := NewControllerManager(ctlr)
|
||||||
|
|
||||||
go func() {
|
ctrlManager.StartAndWait(port)
|
||||||
// this blocks
|
|
||||||
if err := ctlr.Run(context.Background()); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// wait till ready
|
|
||||||
for {
|
|
||||||
_, err := resty.R().Get(baseURL)
|
|
||||||
if err == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp, _ := resty.R().SetBasicAuth(username, passphrase).Get(baseURL + constants.RoutePrefix + "/")
|
resp, _ := resty.R().SetBasicAuth(username, passphrase).Get(baseURL + constants.RoutePrefix + "/")
|
||||||
So(resp, ShouldNotBeNil)
|
So(resp, ShouldNotBeNil)
|
||||||
|
@ -785,10 +736,7 @@ func TestCVEConfig(t *testing.T) {
|
||||||
So(resp, ShouldNotBeNil)
|
So(resp, ShouldNotBeNil)
|
||||||
So(resp.StatusCode(), ShouldEqual, 404)
|
So(resp.StatusCode(), ShouldEqual, 404)
|
||||||
|
|
||||||
defer func() {
|
defer ctrlManager.StopServer()
|
||||||
ctx := context.Background()
|
|
||||||
_ = ctlr.Server.Shutdown(ctx)
|
|
||||||
}()
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -813,10 +761,7 @@ func TestHTTPOptionsResponse(t *testing.T) {
|
||||||
defer os.RemoveAll(firstDir)
|
defer os.RemoveAll(firstDir)
|
||||||
defer os.RemoveAll(secondDir)
|
defer os.RemoveAll(secondDir)
|
||||||
|
|
||||||
err = CopyFiles("../../../../test/data", path.Join(secondDir, "a"))
|
CopyTestFiles("../../../../test/data", path.Join(secondDir, "a"))
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
ctlr.Config.Storage.RootDirectory = firstDir
|
ctlr.Config.Storage.RootDirectory = firstDir
|
||||||
subPaths := make(map[string]config.StorageConfig)
|
subPaths := make(map[string]config.StorageConfig)
|
||||||
|
@ -825,31 +770,15 @@ func TestHTTPOptionsResponse(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ctlr.Config.Storage.SubPaths = subPaths
|
ctlr.Config.Storage.SubPaths = subPaths
|
||||||
|
ctrlManager := NewControllerManager(ctlr)
|
||||||
|
|
||||||
go func() {
|
ctrlManager.StartAndWait(port)
|
||||||
// this blocks
|
|
||||||
if err := ctlr.Run(context.Background()); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// wait till ready
|
|
||||||
for {
|
|
||||||
_, err := resty.R().Get(baseURL)
|
|
||||||
if err == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp, _ := resty.R().Options(baseURL + constants.RoutePrefix + constants.ExtCatalogPrefix)
|
resp, _ := resty.R().Options(baseURL + constants.RoutePrefix + constants.ExtCatalogPrefix)
|
||||||
So(resp, ShouldNotBeNil)
|
So(resp, ShouldNotBeNil)
|
||||||
So(resp.StatusCode(), ShouldEqual, http.StatusNoContent)
|
So(resp.StatusCode(), ShouldEqual, http.StatusNoContent)
|
||||||
|
|
||||||
defer func() {
|
defer ctrlManager.StopServer()
|
||||||
ctx := context.Background()
|
|
||||||
_ = ctlr.Server.Shutdown(ctx)
|
|
||||||
}()
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,12 +5,10 @@
|
||||||
package digestinfo_test
|
package digestinfo_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
|
||||||
|
|
||||||
. "github.com/smartystreets/goconvey/convey"
|
. "github.com/smartystreets/goconvey/convey"
|
||||||
"gopkg.in/resty.v1"
|
"gopkg.in/resty.v1"
|
||||||
|
@ -72,15 +70,9 @@ func testSetup(t *testing.T) (string, string, *digestinfo.DigestInfo) {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = CopyFiles("../../../../test/data", rootDir)
|
CopyTestFiles("../../../../test/data", rootDir)
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
err = CopyFiles("../../../../test/data", subDir+"/a/")
|
CopyTestFiles("../../../../test/data", subDir+"/a/")
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
log := log.NewLogger("debug", "")
|
log := log.NewLogger("debug", "")
|
||||||
metrics := monitoring.NewMetricsServer(false, log)
|
metrics := monitoring.NewMetricsServer(false, log)
|
||||||
|
@ -143,28 +135,12 @@ func TestDigestSearchHTTP(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
|
ctrlManager := NewControllerManager(ctlr)
|
||||||
|
|
||||||
go func() {
|
ctrlManager.StartAndWait(port)
|
||||||
// this blocks
|
|
||||||
if err := ctlr.Run(context.Background()); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// wait till ready
|
|
||||||
for {
|
|
||||||
_, err := resty.R().Get(baseURL)
|
|
||||||
if err == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
|
|
||||||
// shut down server
|
// shut down server
|
||||||
defer func() {
|
defer ctrlManager.StopServer()
|
||||||
ctx := context.Background()
|
|
||||||
_ = ctlr.Server.Shutdown(ctx)
|
|
||||||
}()
|
|
||||||
|
|
||||||
resp, err := resty.R().Get(baseURL + "/v2/")
|
resp, err := resty.R().Get(baseURL + "/v2/")
|
||||||
So(resp, ShouldNotBeNil)
|
So(resp, ShouldNotBeNil)
|
||||||
|
@ -310,28 +286,12 @@ func TestDigestSearchHTTPSubPaths(t *testing.T) {
|
||||||
subPathMap["/a"] = config.StorageConfig{RootDirectory: subRootDir}
|
subPathMap["/a"] = config.StorageConfig{RootDirectory: subRootDir}
|
||||||
|
|
||||||
ctlr.Config.Storage.SubPaths = subPathMap
|
ctlr.Config.Storage.SubPaths = subPathMap
|
||||||
|
ctrlManager := NewControllerManager(ctlr)
|
||||||
|
|
||||||
go func() {
|
ctrlManager.StartAndWait(port)
|
||||||
// this blocks
|
|
||||||
if err := ctlr.Run(context.Background()); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// wait till ready
|
|
||||||
for {
|
|
||||||
_, err := resty.R().Get(baseURL)
|
|
||||||
if err == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
|
|
||||||
// shut down server
|
// shut down server
|
||||||
defer func() {
|
defer ctrlManager.StopServer()
|
||||||
ctx := context.Background()
|
|
||||||
_ = ctlr.Server.Shutdown(ctx)
|
|
||||||
}()
|
|
||||||
|
|
||||||
resp, err := resty.R().Get(baseURL + "/v2/")
|
resp, err := resty.R().Get(baseURL + "/v2/")
|
||||||
So(resp, ShouldNotBeNil)
|
So(resp, ShouldNotBeNil)
|
||||||
|
@ -372,28 +332,12 @@ func TestDigestSearchDisabled(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
|
ctrlManager := NewControllerManager(ctlr)
|
||||||
|
|
||||||
go func() {
|
ctrlManager.StartAndWait(port)
|
||||||
// this blocks
|
|
||||||
if err := ctlr.Run(context.Background()); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// wait till ready
|
|
||||||
for {
|
|
||||||
_, err := resty.R().Get(baseURL)
|
|
||||||
if err == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
|
|
||||||
// shut down server
|
// shut down server
|
||||||
defer func() {
|
defer ctrlManager.StopServer()
|
||||||
ctx := context.Background()
|
|
||||||
_ = ctlr.Server.Shutdown(ctx)
|
|
||||||
}()
|
|
||||||
|
|
||||||
resp, err := resty.R().Get(baseURL + "/v2/")
|
resp, err := resty.R().Get(baseURL + "/v2/")
|
||||||
So(resp, ShouldNotBeNil)
|
So(resp, ShouldNotBeNil)
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package sync_test
|
package sync_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -42,17 +41,10 @@ func TestSyncExtension(t *testing.T) {
|
||||||
conf.Log.Output = logFile.Name()
|
conf.Log.Output = logFile.Name()
|
||||||
|
|
||||||
ctlr := api.NewController(conf)
|
ctlr := api.NewController(conf)
|
||||||
|
ctlrManager := test.NewControllerManager(ctlr)
|
||||||
|
|
||||||
go func() {
|
ctlrManager.StartAndWait(port)
|
||||||
if err := ctlr.Run(context.Background()); err != nil {
|
defer ctlrManager.StopServer()
|
||||||
return
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
_ = ctlr.Server.Shutdown(context.Background())
|
|
||||||
}()
|
|
||||||
test.WaitTillServerReady(baseURL)
|
|
||||||
|
|
||||||
Convey("verify sync is skipped when binary doesn't include it", func() {
|
Convey("verify sync is skipped when binary doesn't include it", func() {
|
||||||
resp, err := resty.R().
|
resp, err := resty.R().
|
||||||
|
|
|
@ -390,10 +390,7 @@ func TestSyncInternal(t *testing.T) {
|
||||||
Convey("Test canSkipImage()", t, func() {
|
Convey("Test canSkipImage()", t, func() {
|
||||||
storageDir := t.TempDir()
|
storageDir := t.TempDir()
|
||||||
|
|
||||||
err := test.CopyFiles("../../../test/data", storageDir)
|
test.CopyTestFiles("../../../test/data", storageDir)
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
||||||
|
@ -407,7 +404,7 @@ func TestSyncInternal(t *testing.T) {
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
|
|
||||||
err = os.Chmod(path.Join(imageStore.RootDir(), testImage, "index.json"), 0o000)
|
err := os.Chmod(path.Join(imageStore.RootDir(), testImage, "index.json"), 0o000)
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
canBeSkipped, err := canSkipImage(testImage, testImageTag, "fakeDigest", imageStore, log)
|
canBeSkipped, err := canSkipImage(testImage, testImageTag, "fakeDigest", imageStore, log)
|
||||||
|
@ -520,10 +517,7 @@ func TestSyncInternal(t *testing.T) {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = test.CopyFiles("../../../test/data", testRootDir)
|
test.CopyTestFiles("../../../test/data", testRootDir)
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
testImageStore := local.NewImageStore(testRootDir, false,
|
testImageStore := local.NewImageStore(testRootDir, false,
|
||||||
storage.DefaultGCDelay, false, false, log, metrics, nil, nil)
|
storage.DefaultGCDelay, false, false, log, metrics, nil, nil)
|
||||||
|
|
|
@ -154,31 +154,14 @@ func startUpstreamServer(
|
||||||
|
|
||||||
srcDir := t.TempDir()
|
srcDir := t.TempDir()
|
||||||
|
|
||||||
err := test.CopyFiles("../../../test/data", srcDir)
|
test.CopyTestFiles("../../../test/data", srcDir)
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
srcConfig.Storage.RootDirectory = srcDir
|
srcConfig.Storage.RootDirectory = srcDir
|
||||||
|
|
||||||
sctlr := api.NewController(srcConfig)
|
sctlr := api.NewController(srcConfig)
|
||||||
|
|
||||||
go func() {
|
scm := test.NewControllerManager(sctlr)
|
||||||
// this blocks
|
scm.StartAndWait(srcPort)
|
||||||
if err := sctlr.Run(context.Background()); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// wait till ready
|
|
||||||
for {
|
|
||||||
_, err := client.R().Get(srcBaseURL)
|
|
||||||
if err == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
|
|
||||||
return sctlr, srcBaseURL, srcDir, htpasswdPath, client
|
return sctlr, srcBaseURL, srcDir, htpasswdPath, client
|
||||||
}
|
}
|
||||||
|
@ -236,22 +219,8 @@ func startDownstreamServer(
|
||||||
|
|
||||||
dctlr := api.NewController(destConfig)
|
dctlr := api.NewController(destConfig)
|
||||||
|
|
||||||
go func() {
|
dcm := test.NewControllerManager(dctlr)
|
||||||
// this blocks
|
dcm.StartAndWait(destPort)
|
||||||
if err := dctlr.Run(context.Background()); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// wait till ready
|
|
||||||
for {
|
|
||||||
_, err := client.R().Get(destBaseURL)
|
|
||||||
if err == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
|
|
||||||
return dctlr, destBaseURL, destDir, client
|
return dctlr, destBaseURL, destDir, client
|
||||||
}
|
}
|
||||||
|
@ -710,10 +679,9 @@ func TestOnDemandPermsDenied(t *testing.T) {
|
||||||
destConfig.Extensions.Sync = syncConfig
|
destConfig.Extensions.Sync = syncConfig
|
||||||
|
|
||||||
dctlr := api.NewController(destConfig)
|
dctlr := api.NewController(destConfig)
|
||||||
|
dcm := test.NewControllerManager(dctlr)
|
||||||
|
|
||||||
defer func() {
|
defer dcm.StopServer()
|
||||||
dctlr.Shutdown()
|
|
||||||
}()
|
|
||||||
|
|
||||||
syncSubDir := path.Join(destDir, testImage, sync.SyncBlobUploadDir)
|
syncSubDir := path.Join(destDir, testImage, sync.SyncBlobUploadDir)
|
||||||
|
|
||||||
|
@ -723,14 +691,7 @@ func TestOnDemandPermsDenied(t *testing.T) {
|
||||||
err = os.Chmod(syncSubDir, 0o000)
|
err = os.Chmod(syncSubDir, 0o000)
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
go func() {
|
dcm.StartAndWait(destPort)
|
||||||
// this blocks
|
|
||||||
if err := dctlr.Run(context.Background()); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
test.WaitTillServerReady(destBaseURL)
|
|
||||||
|
|
||||||
resp, err := resty.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag)
|
resp, err := resty.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag)
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
@ -802,10 +763,9 @@ func TestConfigReloader(t *testing.T) {
|
||||||
destConfig.Log.Output = logFile.Name()
|
destConfig.Log.Output = logFile.Name()
|
||||||
|
|
||||||
dctlr := api.NewController(destConfig)
|
dctlr := api.NewController(destConfig)
|
||||||
|
dcm := test.NewControllerManager(dctlr)
|
||||||
|
|
||||||
defer func() {
|
defer dcm.StopServer()
|
||||||
dctlr.Shutdown()
|
|
||||||
}()
|
|
||||||
|
|
||||||
content := fmt.Sprintf(`{"distSpecVersion": "0.1.0-dev", "storage": {"rootDirectory": "%s"},
|
content := fmt.Sprintf(`{"distSpecVersion": "0.1.0-dev", "storage": {"rootDirectory": "%s"},
|
||||||
"http": {"address": "127.0.0.1", "port": "%s"},
|
"http": {"address": "127.0.0.1", "port": "%s"},
|
||||||
|
@ -926,27 +886,11 @@ func TestMandatoryAnnotations(t *testing.T) {
|
||||||
destConfig.Extensions.Lint.MandatoryAnnotations = []string{"annot1", "annot2", "annot3"}
|
destConfig.Extensions.Lint.MandatoryAnnotations = []string{"annot1", "annot2", "annot3"}
|
||||||
|
|
||||||
dctlr := api.NewController(destConfig)
|
dctlr := api.NewController(destConfig)
|
||||||
|
dcm := test.NewControllerManager(dctlr)
|
||||||
|
|
||||||
go func() {
|
dcm.StartAndWait(destPort)
|
||||||
// this blocks
|
|
||||||
if err := dctlr.Run(context.Background()); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// wait till ready
|
defer dcm.StopServer()
|
||||||
for {
|
|
||||||
_, err := destClient.R().Get(destBaseURL)
|
|
||||||
if err == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
dctlr.Shutdown()
|
|
||||||
}()
|
|
||||||
|
|
||||||
// give it time to set up sync
|
// give it time to set up sync
|
||||||
time.Sleep(5 * time.Second)
|
time.Sleep(5 * time.Second)
|
||||||
|
@ -1260,19 +1204,9 @@ func TestBasicAuth(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
dctlr := api.NewController(destConfig)
|
dctlr := api.NewController(destConfig)
|
||||||
|
dcm := test.NewControllerManager(dctlr)
|
||||||
go func() {
|
dcm.StartAndWait(destPort)
|
||||||
// this blocks
|
defer dcm.StopServer()
|
||||||
if err := dctlr.Run(context.Background()); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
dctlr.Shutdown()
|
|
||||||
}()
|
|
||||||
|
|
||||||
test.WaitTillServerReady(destBaseURL)
|
|
||||||
|
|
||||||
time.Sleep(3 * time.Second)
|
time.Sleep(3 * time.Second)
|
||||||
|
|
||||||
|
@ -1977,27 +1911,15 @@ func TestSubPaths(t *testing.T) {
|
||||||
|
|
||||||
subpath := "/subpath"
|
subpath := "/subpath"
|
||||||
|
|
||||||
err := test.CopyFiles("../../../test/data", path.Join(srcDir, subpath))
|
test.CopyTestFiles("../../../test/data", path.Join(srcDir, subpath))
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
srcConfig.Storage.RootDirectory = srcDir
|
srcConfig.Storage.RootDirectory = srcDir
|
||||||
|
|
||||||
sctlr := api.NewController(srcConfig)
|
sctlr := api.NewController(srcConfig)
|
||||||
|
|
||||||
go func() {
|
scm := test.NewControllerManager(sctlr)
|
||||||
// this blocks
|
scm.StartAndWait(srcPort)
|
||||||
if err := sctlr.Run(context.Background()); err != nil {
|
defer scm.StopServer()
|
||||||
return
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
test.WaitTillServerReady(srcBaseURL)
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
sctlr.Shutdown()
|
|
||||||
}()
|
|
||||||
|
|
||||||
regex := ".*"
|
regex := ".*"
|
||||||
var semver bool
|
var semver bool
|
||||||
|
@ -2053,18 +1975,9 @@ func TestSubPaths(t *testing.T) {
|
||||||
|
|
||||||
dctlr := api.NewController(destConfig)
|
dctlr := api.NewController(destConfig)
|
||||||
|
|
||||||
go func() {
|
dcm := test.NewControllerManager(dctlr)
|
||||||
// this blocks
|
dcm.StartAndWait(destPort)
|
||||||
if err := dctlr.Run(context.Background()); err != nil {
|
defer dcm.StopServer()
|
||||||
return
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
test.WaitTillServerReady(destBaseURL)
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
dctlr.Shutdown()
|
|
||||||
}()
|
|
||||||
|
|
||||||
var destTagsList TagsList
|
var destTagsList TagsList
|
||||||
|
|
||||||
|
@ -3096,14 +3009,12 @@ func TestOnDemandRetryGoroutine(t *testing.T) {
|
||||||
|
|
||||||
srcDir := t.TempDir()
|
srcDir := t.TempDir()
|
||||||
|
|
||||||
err := test.CopyFiles("../../../test/data", srcDir)
|
test.CopyTestFiles("../../../test/data", srcDir)
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
srcConfig.Storage.RootDirectory = srcDir
|
srcConfig.Storage.RootDirectory = srcDir
|
||||||
|
|
||||||
sctlr := api.NewController(srcConfig)
|
sctlr := api.NewController(srcConfig)
|
||||||
|
scm := test.NewControllerManager(sctlr)
|
||||||
|
|
||||||
regex := ".*"
|
regex := ".*"
|
||||||
semver := true
|
semver := true
|
||||||
|
@ -3147,17 +3058,9 @@ func TestOnDemandRetryGoroutine(t *testing.T) {
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
So(resp.StatusCode(), ShouldEqual, 404)
|
So(resp.StatusCode(), ShouldEqual, 404)
|
||||||
|
|
||||||
// start upstream server
|
scm.StartServer()
|
||||||
go func() {
|
|
||||||
// this blocks
|
|
||||||
if err := sctlr.Run(context.Background()); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
defer func() {
|
defer scm.StopServer()
|
||||||
sctlr.Shutdown()
|
|
||||||
}()
|
|
||||||
|
|
||||||
// in the meantime ondemand should retry syncing
|
// in the meantime ondemand should retry syncing
|
||||||
time.Sleep(15 * time.Second)
|
time.Sleep(15 * time.Second)
|
||||||
|
@ -3287,14 +3190,12 @@ func TestOnDemandMultipleRetries(t *testing.T) {
|
||||||
|
|
||||||
srcDir := t.TempDir()
|
srcDir := t.TempDir()
|
||||||
|
|
||||||
err := test.CopyFiles("../../../test/data", srcDir)
|
test.CopyTestFiles("../../../test/data", srcDir)
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
srcConfig.Storage.RootDirectory = srcDir
|
srcConfig.Storage.RootDirectory = srcDir
|
||||||
|
|
||||||
sctlr := api.NewController(srcConfig)
|
sctlr := api.NewController(srcConfig)
|
||||||
|
scm := test.NewControllerManager(sctlr)
|
||||||
|
|
||||||
var tlsVerify bool
|
var tlsVerify bool
|
||||||
|
|
||||||
|
@ -3356,18 +3257,9 @@ func TestOnDemandMultipleRetries(t *testing.T) {
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// start upstream server
|
// start upstream server
|
||||||
go func() {
|
scm.StartAndWait(srcPort)
|
||||||
// this blocks
|
|
||||||
if err := sctlr.Run(context.Background()); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
test.WaitTillServerReady(srcBaseURL)
|
defer scm.StopServer()
|
||||||
|
|
||||||
defer func() {
|
|
||||||
sctlr.Shutdown()
|
|
||||||
}()
|
|
||||||
|
|
||||||
// wait sync
|
// wait sync
|
||||||
for {
|
for {
|
||||||
|
@ -3840,10 +3732,7 @@ func TestSyncOnlyDiff(t *testing.T) {
|
||||||
destDir := t.TempDir()
|
destDir := t.TempDir()
|
||||||
|
|
||||||
// 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)
|
test.CopyTestFiles("../../../test/data", destDir)
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
destConfig.Storage.RootDirectory = destDir
|
destConfig.Storage.RootDirectory = destDir
|
||||||
destConfig.Storage.Dedupe = false
|
destConfig.Storage.Dedupe = false
|
||||||
|
@ -3855,19 +3744,11 @@ func TestSyncOnlyDiff(t *testing.T) {
|
||||||
destConfig.Log.Output = path.Join(destDir, "sync.log")
|
destConfig.Log.Output = path.Join(destDir, "sync.log")
|
||||||
|
|
||||||
dctlr := api.NewController(destConfig)
|
dctlr := api.NewController(destConfig)
|
||||||
|
dcm := test.NewControllerManager(dctlr)
|
||||||
|
|
||||||
go func() {
|
dcm.StartAndWait(destPort)
|
||||||
// this blocks
|
|
||||||
if err := dctlr.Run(context.Background()); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
test.WaitTillServerReady(destBaseURL)
|
defer dcm.StopServer()
|
||||||
|
|
||||||
defer func() {
|
|
||||||
dctlr.Shutdown()
|
|
||||||
}()
|
|
||||||
|
|
||||||
resp, err := resty.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag)
|
resp, err := resty.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag)
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
@ -3923,10 +3804,7 @@ func TestSyncWithDiffDigest(t *testing.T) {
|
||||||
destDir := t.TempDir()
|
destDir := t.TempDir()
|
||||||
|
|
||||||
// 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)
|
test.CopyTestFiles("../../../test/data", destDir)
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
destConfig.Storage.RootDirectory = destDir
|
destConfig.Storage.RootDirectory = destDir
|
||||||
destConfig.Storage.Dedupe = false
|
destConfig.Storage.Dedupe = false
|
||||||
|
@ -3937,6 +3815,7 @@ func TestSyncWithDiffDigest(t *testing.T) {
|
||||||
destConfig.Extensions.Sync = syncConfig
|
destConfig.Extensions.Sync = syncConfig
|
||||||
|
|
||||||
dctlr := api.NewController(destConfig)
|
dctlr := api.NewController(destConfig)
|
||||||
|
dcm := test.NewControllerManager(dctlr)
|
||||||
|
|
||||||
// before starting downstream server, let's modify an image manifest so that sync should pull it
|
// before starting downstream server, let's modify an image manifest so that sync should pull it
|
||||||
// change digest of the manifest so that sync should happen
|
// change digest of the manifest so that sync should happen
|
||||||
|
@ -3991,12 +3870,7 @@ func TestSyncWithDiffDigest(t *testing.T) {
|
||||||
So(resp, ShouldNotBeNil)
|
So(resp, ShouldNotBeNil)
|
||||||
So(resp.StatusCode(), ShouldEqual, 201)
|
So(resp.StatusCode(), ShouldEqual, 201)
|
||||||
|
|
||||||
go func() {
|
dcm.StartServer()
|
||||||
// this blocks
|
|
||||||
if err := dctlr.Run(context.Background()); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// watch .sync subdir, should be populated
|
// watch .sync subdir, should be populated
|
||||||
done := make(chan bool)
|
done := make(chan bool)
|
||||||
|
@ -4016,9 +3890,7 @@ func TestSyncWithDiffDigest(t *testing.T) {
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
defer func() {
|
defer dcm.StopServer()
|
||||||
dctlr.Shutdown()
|
|
||||||
}()
|
|
||||||
|
|
||||||
test.WaitTillServerReady(destBaseURL)
|
test.WaitTillServerReady(destBaseURL)
|
||||||
|
|
||||||
|
@ -4815,31 +4687,15 @@ func TestSyncOCIArtifactsWithTag(t *testing.T) {
|
||||||
destConfig.Extensions.Sync = syncConfig
|
destConfig.Extensions.Sync = syncConfig
|
||||||
|
|
||||||
dctlr := api.NewController(destConfig)
|
dctlr := api.NewController(destConfig)
|
||||||
|
dcm := test.NewControllerManager(dctlr)
|
||||||
|
|
||||||
manifestPath := path.Join(destDir, repoName, "blobs", "sha256", artifactDigest.Encoded())
|
manifestPath := path.Join(destDir, repoName, "blobs", "sha256", artifactDigest.Encoded())
|
||||||
So(os.MkdirAll(manifestPath, 0o755), ShouldBeNil)
|
So(os.MkdirAll(manifestPath, 0o755), ShouldBeNil)
|
||||||
So(os.Chmod(manifestPath, 0o000), ShouldBeNil)
|
So(os.Chmod(manifestPath, 0o000), ShouldBeNil)
|
||||||
|
|
||||||
go func() {
|
dcm.StartAndWait(destConfig.HTTP.Port)
|
||||||
// this blocks
|
|
||||||
if err := dctlr.Run(context.Background()); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// wait till ready
|
defer dcm.StopServer()
|
||||||
for {
|
|
||||||
_, err := resty.R().Get(destBaseURL)
|
|
||||||
if err == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
dctlr.Shutdown()
|
|
||||||
}()
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
err := os.Chmod(manifestPath, 0o755)
|
err := os.Chmod(manifestPath, 0o755)
|
||||||
|
|
|
@ -179,6 +179,13 @@ func CopyFiles(sourceDir, destDir string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CopyTestFiles(sourceDir, destDir string) {
|
||||||
|
err := CopyFiles(sourceDir, destDir)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type Controller interface {
|
type Controller interface {
|
||||||
Run(ctx context.Context) error
|
Run(ctx context.Context) error
|
||||||
Shutdown()
|
Shutdown()
|
||||||
|
|
|
@ -113,6 +113,9 @@ func TestCopyFiles(t *testing.T) {
|
||||||
_, err = os.Stat(path.Join(dstDir, "test-index", "index.json"))
|
_, err = os.Stat(path.Join(dstDir, "test-index", "index.json"))
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
})
|
})
|
||||||
|
Convey("panic when sourceDir does not exist", t, func() {
|
||||||
|
So(func() { test.CopyTestFiles("/path/to/some/unexisting/directory", os.TempDir()) }, ShouldPanic)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetOciLayoutDigests(t *testing.T) {
|
func TestGetOciLayoutDigests(t *testing.T) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue