mirror of
https://github.com/project-zot/zot.git
synced 2024-12-16 21:56:37 -05:00
refactor(test): remove unnecessary usage of images copied from under test/data (#1217)
Signed-off-by: Nicol Draghici <idraghic@cisco.com>
This commit is contained in:
parent
792f3f55b3
commit
a561d0bad5
2 changed files with 150 additions and 49 deletions
|
@ -54,12 +54,6 @@ var (
|
||||||
ErrPutManifest = errors.New("can't put manifest")
|
ErrPutManifest = errors.New("can't put manifest")
|
||||||
)
|
)
|
||||||
|
|
||||||
//nolint:gochecknoglobals
|
|
||||||
var (
|
|
||||||
rootDir string
|
|
||||||
subRootDir string
|
|
||||||
)
|
|
||||||
|
|
||||||
type RepoWithNewestImageResponse struct {
|
type RepoWithNewestImageResponse struct {
|
||||||
RepoListWithNewestImage RepoListWithNewestImage `json:"data"`
|
RepoListWithNewestImage RepoListWithNewestImage `json:"data"`
|
||||||
Errors []ErrorGQL `json:"errors"`
|
Errors []ErrorGQL `json:"errors"`
|
||||||
|
@ -152,21 +146,6 @@ type ImageSummaryResult struct {
|
||||||
Errors []ErrorGQL `json:"errors"`
|
Errors []ErrorGQL `json:"errors"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func testSetup(t *testing.T, subpath string) error { //nolint:unparam
|
|
||||||
t.Helper()
|
|
||||||
dir := t.TempDir()
|
|
||||||
|
|
||||||
subDir := t.TempDir()
|
|
||||||
|
|
||||||
rootDir = dir
|
|
||||||
|
|
||||||
subRootDir = subDir
|
|
||||||
|
|
||||||
CopyTestFiles("../../../../test/data", rootDir)
|
|
||||||
|
|
||||||
return CopyFiles("../../../../test/data", path.Join(subDir, subpath))
|
|
||||||
}
|
|
||||||
|
|
||||||
func getTags() ([]common.TagInfo, []common.TagInfo) {
|
func getTags() ([]common.TagInfo, []common.TagInfo) {
|
||||||
tags := make([]common.TagInfo, 0)
|
tags := make([]common.TagInfo, 0)
|
||||||
|
|
||||||
|
@ -508,14 +487,12 @@ func getMockCveInfo(repoDB repodb.RepoDB, log log.Logger) cveinfo.CveInfo {
|
||||||
func TestRepoListWithNewestImage(t *testing.T) {
|
func TestRepoListWithNewestImage(t *testing.T) {
|
||||||
Convey("Test repoListWithNewestImage by tag with HTTP", t, func() {
|
Convey("Test repoListWithNewestImage by tag with HTTP", t, func() {
|
||||||
subpath := "/a"
|
subpath := "/a"
|
||||||
err := testSetup(t, subpath)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
port := GetFreePort()
|
port := GetFreePort()
|
||||||
baseURL := GetBaseURL(port)
|
baseURL := GetBaseURL(port)
|
||||||
conf := config.New()
|
conf := config.New()
|
||||||
conf.HTTP.Port = port
|
conf.HTTP.Port = port
|
||||||
|
rootDir := t.TempDir()
|
||||||
|
subRootDir := t.TempDir()
|
||||||
conf.Storage.RootDirectory = rootDir
|
conf.Storage.RootDirectory = rootDir
|
||||||
conf.Storage.SubPaths = make(map[string]config.StorageConfig)
|
conf.Storage.SubPaths = make(map[string]config.StorageConfig)
|
||||||
conf.Storage.SubPaths[subpath] = config.StorageConfig{RootDirectory: subRootDir}
|
conf.Storage.SubPaths[subpath] = config.StorageConfig{RootDirectory: subRootDir}
|
||||||
|
@ -532,6 +509,25 @@ func TestRepoListWithNewestImage(t *testing.T) {
|
||||||
ctlrManager.StartAndWait(port)
|
ctlrManager.StartAndWait(port)
|
||||||
defer ctlrManager.StopServer()
|
defer ctlrManager.StopServer()
|
||||||
|
|
||||||
|
config, layers, manifest, err := GetImageComponents(100)
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
|
err = PushTestImage("zot-cve-test", "0.0.1", baseURL,
|
||||||
|
manifest, config, layers)
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
|
err = PushTestImage("a/zot-cve-test", "0.0.1", baseURL,
|
||||||
|
manifest, config, layers)
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
|
err = PushTestImage("zot-test", "0.0.1", baseURL,
|
||||||
|
manifest, config, layers)
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
|
err = PushTestImage("a/zot-test", "0.0.1", baseURL,
|
||||||
|
manifest, config, layers)
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
resp, err := resty.R().Get(baseURL + "/v2/")
|
resp, err := resty.R().Get(baseURL + "/v2/")
|
||||||
So(resp, ShouldNotBeNil)
|
So(resp, ShouldNotBeNil)
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
@ -728,7 +724,7 @@ func TestRepoListWithNewestImage(t *testing.T) {
|
||||||
|
|
||||||
var manifestDigest godigest.Digest
|
var manifestDigest godigest.Digest
|
||||||
var configDigest godigest.Digest
|
var configDigest godigest.Digest
|
||||||
manifestDigest, configDigest, _ = GetOciLayoutDigests("../../../../test/data/zot-test")
|
manifestDigest, configDigest, _ = GetOciLayoutDigests(path.Join(subRootDir, "a/zot-test"))
|
||||||
|
|
||||||
// Delete config blob and try.
|
// Delete config blob and try.
|
||||||
err = os.Remove(path.Join(subRootDir, "a/zot-test/blobs/sha256", configDigest.Encoded()))
|
err = os.Remove(path.Join(subRootDir, "a/zot-test/blobs/sha256", configDigest.Encoded()))
|
||||||
|
@ -781,14 +777,12 @@ func TestRepoListWithNewestImage(t *testing.T) {
|
||||||
|
|
||||||
Convey("Test repoListWithNewestImage with vulnerability scan enabled", t, func() {
|
Convey("Test repoListWithNewestImage with vulnerability scan enabled", t, func() {
|
||||||
subpath := "/a"
|
subpath := "/a"
|
||||||
err := testSetup(t, subpath)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
port := GetFreePort()
|
port := GetFreePort()
|
||||||
baseURL := GetBaseURL(port)
|
baseURL := GetBaseURL(port)
|
||||||
conf := config.New()
|
conf := config.New()
|
||||||
conf.HTTP.Port = port
|
conf.HTTP.Port = port
|
||||||
|
rootDir := t.TempDir()
|
||||||
|
subRootDir := t.TempDir()
|
||||||
conf.Storage.RootDirectory = rootDir
|
conf.Storage.RootDirectory = rootDir
|
||||||
conf.Storage.SubPaths = make(map[string]config.StorageConfig)
|
conf.Storage.SubPaths = make(map[string]config.StorageConfig)
|
||||||
conf.Storage.SubPaths[subpath] = config.StorageConfig{RootDirectory: subRootDir}
|
conf.Storage.SubPaths[subpath] = config.StorageConfig{RootDirectory: subRootDir}
|
||||||
|
@ -858,6 +852,25 @@ func TestRepoListWithNewestImage(t *testing.T) {
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
So(resp.StatusCode(), ShouldEqual, 422)
|
So(resp.StatusCode(), ShouldEqual, 422)
|
||||||
|
|
||||||
|
config, layers, manifest, err := GetImageComponents(100)
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
|
err = PushTestImage("zot-cve-test", "0.0.1", baseURL,
|
||||||
|
manifest, config, layers)
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
|
err = PushTestImage("a/zot-cve-test", "0.0.1", baseURL,
|
||||||
|
manifest, config, layers)
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
|
err = PushTestImage("zot-test", "0.0.1", baseURL,
|
||||||
|
manifest, config, layers)
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
|
err = PushTestImage("a/zot-test", "0.0.1", baseURL,
|
||||||
|
manifest, config, layers)
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
query := `{
|
query := `{
|
||||||
RepoListWithNewestImage{
|
RepoListWithNewestImage{
|
||||||
Results{
|
Results{
|
||||||
|
@ -1126,10 +1139,8 @@ func TestExpandedRepoInfo(t *testing.T) {
|
||||||
|
|
||||||
Convey("Test expanded repo info", t, func() {
|
Convey("Test expanded repo info", t, func() {
|
||||||
subpath := "/a"
|
subpath := "/a"
|
||||||
err := testSetup(t, subpath)
|
rootDir := t.TempDir()
|
||||||
if err != nil {
|
subRootDir := t.TempDir()
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
port := GetFreePort()
|
port := GetFreePort()
|
||||||
baseURL := GetBaseURL(port)
|
baseURL := GetBaseURL(port)
|
||||||
conf := config.New()
|
conf := config.New()
|
||||||
|
@ -1149,9 +1160,31 @@ func TestExpandedRepoInfo(t *testing.T) {
|
||||||
ctlrManager.StartAndWait(port)
|
ctlrManager.StartAndWait(port)
|
||||||
defer ctlrManager.StopServer()
|
defer ctlrManager.StopServer()
|
||||||
|
|
||||||
|
config, layers, manifest, err := GetImageComponents(100)
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
|
manifest.Annotations = make(map[string]string)
|
||||||
|
manifest.Annotations["org.opencontainers.image.vendor"] = "zot"
|
||||||
|
|
||||||
|
err = PushTestImage("zot-cve-test", "0.0.1", baseURL,
|
||||||
|
manifest, config, layers)
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
|
err = PushTestImage("a/zot-cve-test", "0.0.1", baseURL,
|
||||||
|
manifest, config, layers)
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
|
err = PushTestImage("zot-test", "0.0.1", baseURL,
|
||||||
|
manifest, config, layers)
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
|
err = PushTestImage("a/zot-test", "0.0.1", baseURL,
|
||||||
|
manifest, config, layers)
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
log := log.NewLogger("debug", "")
|
log := log.NewLogger("debug", "")
|
||||||
metrics := monitoring.NewMetricsServer(false, log)
|
metrics := monitoring.NewMetricsServer(false, log)
|
||||||
testStorage := local.NewImageStore("../../../../test/data", false, storage.DefaultGCDelay,
|
testStorage := local.NewImageStore(rootDir, false, storage.DefaultGCDelay,
|
||||||
false, false, log, metrics, nil, nil)
|
false, false, log, metrics, nil, nil)
|
||||||
|
|
||||||
resp, err := resty.R().Get(baseURL + "/v2/")
|
resp, err := resty.R().Get(baseURL + "/v2/")
|
||||||
|
@ -1285,7 +1318,7 @@ func TestExpandedRepoInfo(t *testing.T) {
|
||||||
So(found, ShouldEqual, true)
|
So(found, ShouldEqual, true)
|
||||||
|
|
||||||
var manifestDigest godigest.Digest
|
var manifestDigest godigest.Digest
|
||||||
manifestDigest, _, _ = GetOciLayoutDigests("../../../../test/data/zot-test")
|
manifestDigest, _, _ = GetOciLayoutDigests(path.Join(rootDir, "zot-test"))
|
||||||
|
|
||||||
err = os.Remove(path.Join(rootDir, "zot-test/blobs/sha256", manifestDigest.Encoded()))
|
err = os.Remove(path.Join(rootDir, "zot-test/blobs/sha256", manifestDigest.Encoded()))
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
@ -1482,7 +1515,7 @@ func TestUtilsMethod(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDerivedImageList(t *testing.T) {
|
func TestDerivedImageList(t *testing.T) {
|
||||||
rootDir = t.TempDir()
|
rootDir := t.TempDir()
|
||||||
|
|
||||||
port := GetFreePort()
|
port := GetFreePort()
|
||||||
baseURL := GetBaseURL(port)
|
baseURL := GetBaseURL(port)
|
||||||
|
@ -1959,7 +1992,7 @@ func TestGetImageManifest(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBaseImageList(t *testing.T) {
|
func TestBaseImageList(t *testing.T) {
|
||||||
rootDir = t.TempDir()
|
rootDir := t.TempDir()
|
||||||
|
|
||||||
port := GetFreePort()
|
port := GetFreePort()
|
||||||
baseURL := GetBaseURL(port)
|
baseURL := GetBaseURL(port)
|
||||||
|
@ -2674,7 +2707,7 @@ func TestGlobalSearch(t *testing.T) {
|
||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
subDir := t.TempDir()
|
subDir := t.TempDir()
|
||||||
|
|
||||||
subRootDir = path.Join(subDir, subpath)
|
subRootDir := path.Join(subDir, subpath)
|
||||||
|
|
||||||
port := GetFreePort()
|
port := GetFreePort()
|
||||||
baseURL := GetBaseURL(port)
|
baseURL := GetBaseURL(port)
|
||||||
|
@ -2697,10 +2730,24 @@ func TestGlobalSearch(t *testing.T) {
|
||||||
defer ctlrManager.StopServer()
|
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)
|
_, layers1, manifest1, err := GetImageComponents(100)
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
createdTime := time.Date(2010, 1, 1, 12, 0, 0, 0, time.UTC)
|
createdTime := time.Date(2010, 1, 1, 12, 0, 0, 0, time.UTC)
|
||||||
createdTimeL2 := time.Date(2010, 2, 1, 12, 0, 0, 0, time.UTC)
|
createdTimeL2 := time.Date(2010, 2, 1, 12, 0, 0, 0, time.UTC)
|
||||||
|
config1 := ispec.Image{
|
||||||
|
Created: &createdTimeL2,
|
||||||
|
Platform: ispec.Platform{
|
||||||
|
Architecture: "amd64",
|
||||||
|
OS: "linux",
|
||||||
|
},
|
||||||
|
RootFS: ispec.RootFS{
|
||||||
|
Type: "layers",
|
||||||
|
DiffIDs: []godigest.Digest{},
|
||||||
|
},
|
||||||
|
Author: "ZotUser",
|
||||||
|
}
|
||||||
|
|
||||||
config1.History = append(
|
config1.History = append(
|
||||||
config1.History,
|
config1.History,
|
||||||
ispec.History{
|
ispec.History{
|
||||||
|
@ -2973,7 +3020,7 @@ func TestGlobalSearch(t *testing.T) {
|
||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
subDir := t.TempDir()
|
subDir := t.TempDir()
|
||||||
|
|
||||||
subRootDir = path.Join(subDir, subpath)
|
subRootDir := path.Join(subDir, subpath)
|
||||||
|
|
||||||
port := GetFreePort()
|
port := GetFreePort()
|
||||||
baseURL := GetBaseURL(port)
|
baseURL := GetBaseURL(port)
|
||||||
|
@ -3533,12 +3580,7 @@ func TestGlobalSearchWithInvalidInput(t *testing.T) {
|
||||||
|
|
||||||
func TestImageList(t *testing.T) {
|
func TestImageList(t *testing.T) {
|
||||||
Convey("Test ImageList", t, func() {
|
Convey("Test ImageList", t, func() {
|
||||||
subpath := "/a"
|
rootDir := t.TempDir()
|
||||||
|
|
||||||
err := testSetup(t, subpath)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
port := GetFreePort()
|
port := GetFreePort()
|
||||||
baseURL := GetBaseURL(port)
|
baseURL := GetBaseURL(port)
|
||||||
|
@ -3559,6 +3601,47 @@ func TestImageList(t *testing.T) {
|
||||||
ctlrManager.StartAndWait(port)
|
ctlrManager.StartAndWait(port)
|
||||||
defer ctlrManager.StopServer()
|
defer ctlrManager.StopServer()
|
||||||
|
|
||||||
|
config, layers, manifest, err := GetImageComponents(100)
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
|
createdTime := time.Date(2010, 1, 1, 12, 0, 0, 0, time.UTC)
|
||||||
|
createdTimeL2 := time.Date(2010, 2, 1, 12, 0, 0, 0, time.UTC)
|
||||||
|
config.History = append(
|
||||||
|
config.History,
|
||||||
|
ispec.History{
|
||||||
|
Created: &createdTime,
|
||||||
|
CreatedBy: "go test data",
|
||||||
|
Author: "ZotUser",
|
||||||
|
Comment: "Test history comment",
|
||||||
|
EmptyLayer: true,
|
||||||
|
},
|
||||||
|
ispec.History{
|
||||||
|
Created: &createdTimeL2,
|
||||||
|
CreatedBy: "go test data 2",
|
||||||
|
Author: "ZotUser",
|
||||||
|
Comment: "Test history comment2",
|
||||||
|
EmptyLayer: false,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
manifest, err = updateManifestConfig(manifest, config)
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
|
err = PushTestImage("zot-cve-test", "0.0.1", baseURL,
|
||||||
|
manifest, config, layers)
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
|
err = PushTestImage("a/zot-cve-test", "0.0.1", baseURL,
|
||||||
|
manifest, config, layers)
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
|
err = PushTestImage("zot-test", "0.0.1", baseURL,
|
||||||
|
manifest, config, layers)
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
|
err = PushTestImage("a/zot-test", "0.0.1", baseURL,
|
||||||
|
manifest, config, layers)
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
imageStore := ctlr.StoreController.DefaultStore
|
imageStore := ctlr.StoreController.DefaultStore
|
||||||
|
|
||||||
repos, err := imageStore.GetRepositories()
|
repos, err := imageStore.GetRepositories()
|
||||||
|
@ -3848,7 +3931,7 @@ func TestRepoDBWhenSigningImages(t *testing.T) {
|
||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
subDir := t.TempDir()
|
subDir := t.TempDir()
|
||||||
|
|
||||||
subRootDir = path.Join(subDir, subpath)
|
subRootDir := path.Join(subDir, subpath)
|
||||||
|
|
||||||
port := GetFreePort()
|
port := GetFreePort()
|
||||||
baseURL := GetBaseURL(port)
|
baseURL := GetBaseURL(port)
|
||||||
|
@ -4218,7 +4301,7 @@ func TestRepoDBWhenDeletingImages(t *testing.T) {
|
||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
subDir := t.TempDir()
|
subDir := t.TempDir()
|
||||||
|
|
||||||
subRootDir = path.Join(subDir, subpath)
|
subRootDir := path.Join(subDir, subpath)
|
||||||
|
|
||||||
port := GetFreePort()
|
port := GetFreePort()
|
||||||
baseURL := GetBaseURL(port)
|
baseURL := GetBaseURL(port)
|
||||||
|
|
|
@ -750,6 +750,24 @@ func UploadBlob(baseURL, repo string, blob []byte, artifactBlobMediaType string)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func PushTestImage(repoName string, tag string, //nolint:unparam
|
||||||
|
baseURL string, manifest ispec.Manifest,
|
||||||
|
config ispec.Image, layers [][]byte,
|
||||||
|
) error {
|
||||||
|
err := UploadImage(
|
||||||
|
Image{
|
||||||
|
Manifest: manifest,
|
||||||
|
Config: config,
|
||||||
|
Layers: layers,
|
||||||
|
Tag: tag,
|
||||||
|
},
|
||||||
|
baseURL,
|
||||||
|
repoName,
|
||||||
|
)
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
func ReadLogFileAndSearchString(logPath string, stringToMatch string, timeout time.Duration) (bool, error) {
|
func ReadLogFileAndSearchString(logPath string, stringToMatch string, timeout time.Duration) (bool, error) {
|
||||||
ctx, cancelFunc := context.WithTimeout(context.Background(), timeout)
|
ctx, cancelFunc := context.WithTimeout(context.Background(), timeout)
|
||||||
defer cancelFunc()
|
defer cancelFunc()
|
||||||
|
|
Loading…
Reference in a new issue