mirror of
https://github.com/project-zot/zot.git
synced 2026-06-16 04:17:55 +08:00
test(refactor): refactor tests that use zot-test to use smaller images (#1690)
Signed-off-by: Laurentiu Niculae <niculae.laurentiu1@gmail.com>
This commit is contained in:
@@ -85,7 +85,9 @@ func TestTLSWithAuth(t *testing.T) {
|
||||
|
||||
home := os.Getenv("HOME")
|
||||
destCertsDir := filepath.Join(home, certsDir1)
|
||||
test.CopyTestFiles(sourceCertsDir, destCertsDir)
|
||||
err := test.CopyTestKeysAndCerts(destCertsDir)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
defer os.RemoveAll(destCertsDir)
|
||||
|
||||
args := []string{"imagetest", "--name", "dummyImageName", "--url", HOST1}
|
||||
@@ -94,7 +96,7 @@ func TestTLSWithAuth(t *testing.T) {
|
||||
imageCmd.SetOut(imageBuff)
|
||||
imageCmd.SetErr(imageBuff)
|
||||
imageCmd.SetArgs(args)
|
||||
err := imageCmd.Execute()
|
||||
err = imageCmd.Execute()
|
||||
So(err, ShouldNotBeNil)
|
||||
So(imageBuff.String(), ShouldContainSubstring, "invalid URL format")
|
||||
|
||||
|
||||
@@ -398,7 +398,9 @@ func TestNegativeServerResponse(t *testing.T) {
|
||||
|
||||
dir := t.TempDir()
|
||||
|
||||
test.CopyTestFiles("../../test/data/zot-cve-test", path.Join(dir, "zot-cve-test"))
|
||||
srcStorageCtlr := test.GetDefaultStoreController(dir, log.NewLogger("debug", ""))
|
||||
err := test.WriteImageToFileSystem(test.CreateDefaultVulnerableImage(), "zot-cve-test", "0.0.1", srcStorageCtlr)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
conf.Storage.RootDirectory = dir
|
||||
trivyConfig := &extconf.TrivyConfig{
|
||||
|
||||
@@ -31,6 +31,7 @@ import (
|
||||
"zotregistry.io/zot/pkg/api/config"
|
||||
"zotregistry.io/zot/pkg/common"
|
||||
extconf "zotregistry.io/zot/pkg/extensions/config"
|
||||
zlog "zotregistry.io/zot/pkg/log"
|
||||
"zotregistry.io/zot/pkg/test"
|
||||
)
|
||||
|
||||
@@ -1419,9 +1420,11 @@ func TestServerResponseGQLWithoutPermissions(t *testing.T) {
|
||||
|
||||
dir := t.TempDir()
|
||||
|
||||
test.CopyTestFiles("../../test/data/zot-test", path.Join(dir, "zot-test"))
|
||||
srcStorageCtlr := test.GetDefaultStoreController(dir, zlog.NewLogger("debug", ""))
|
||||
err := test.WriteImageToFileSystem(test.CreateDefaultImage(), "zot-test", "0.0.1", srcStorageCtlr)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
err := os.Chmod(path.Join(dir, "zot-test", "blobs"), 0o000)
|
||||
err = os.Chmod(path.Join(dir, "zot-test", "blobs"), 0o000)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
+5
-5
@@ -407,7 +407,7 @@ func (search cveByImageSearcherGQL) search(config searchConfig) (bool, error) {
|
||||
}
|
||||
|
||||
if len(cveList.Data.CVEListForImage.CVEList) > 0 &&
|
||||
(*config.outputFormat == defaultOutoutFormat || *config.outputFormat == "") {
|
||||
(*config.outputFormat == defaultOutputFormat || *config.outputFormat == "") {
|
||||
printCVETableHeader(&builder, *config.verbose, 0, 0, 0)
|
||||
fmt.Fprint(config.resultWriter, builder.String())
|
||||
}
|
||||
@@ -799,7 +799,7 @@ func collectResults(config searchConfig, wg *sync.WaitGroup, imageErr chan strin
|
||||
return
|
||||
}
|
||||
|
||||
if !foundResult && (*config.outputFormat == defaultOutoutFormat || *config.outputFormat == "") {
|
||||
if !foundResult && (*config.outputFormat == defaultOutputFormat || *config.outputFormat == "") {
|
||||
var builder strings.Builder
|
||||
|
||||
printHeader(&builder, *config.verbose, 0, 0, 0)
|
||||
@@ -970,7 +970,7 @@ func printCVETableHeader(writer io.Writer, verbose bool, maxImgLen, maxTagLen, m
|
||||
}
|
||||
|
||||
func printReferrersTableHeader(config searchConfig, writer io.Writer, maxArtifactTypeLen int) {
|
||||
if *config.outputFormat != "" && *config.outputFormat != defaultOutoutFormat {
|
||||
if *config.outputFormat != "" && *config.outputFormat != defaultOutputFormat {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1081,7 +1081,7 @@ func printImageResult(config searchConfig, imageList []imageStruct) error {
|
||||
}
|
||||
}
|
||||
|
||||
if *config.outputFormat == defaultOutoutFormat || *config.outputFormat == "" {
|
||||
if *config.outputFormat == defaultOutputFormat || *config.outputFormat == "" {
|
||||
printImageTableHeader(&builder, *config.verbose, maxImgNameLen, maxTagLen, maxPlatformLen)
|
||||
}
|
||||
|
||||
@@ -1117,7 +1117,7 @@ func printRepoResults(config searchConfig, repoList []repoStruct) error {
|
||||
}
|
||||
}
|
||||
|
||||
if len(repoList) > 0 && (*config.outputFormat == defaultOutoutFormat || *config.outputFormat == "") {
|
||||
if len(repoList) > 0 && (*config.outputFormat == defaultOutputFormat || *config.outputFormat == "") {
|
||||
printRepoTableHeader(config.resultWriter, maxRepoNameLen, maxTimeLen, *config.verbose)
|
||||
}
|
||||
|
||||
|
||||
+16
-16
@@ -57,17 +57,17 @@ type SearchService interface { //nolint:interfacebloat
|
||||
channel chan stringResult, wtgrp *sync.WaitGroup)
|
||||
getCveByImage(ctx context.Context, config searchConfig, username, password, imageName, searchedCVE string,
|
||||
channel chan stringResult, wtgrp *sync.WaitGroup)
|
||||
getImagesByCveID(ctx context.Context, config searchConfig, username, password, cvid string,
|
||||
getImagesByCveID(ctx context.Context, config searchConfig, username, password, cveid string,
|
||||
channel chan stringResult, wtgrp *sync.WaitGroup)
|
||||
getImagesByDigest(ctx context.Context, config searchConfig, username, password, digest string,
|
||||
channel chan stringResult, wtgrp *sync.WaitGroup)
|
||||
getFixedTagsForCVE(ctx context.Context, config searchConfig, username, password, imageName, cvid string,
|
||||
getFixedTagsForCVE(ctx context.Context, config searchConfig, username, password, imageName, cveid string,
|
||||
channel chan stringResult, wtgrp *sync.WaitGroup)
|
||||
getRepos(ctx context.Context, config searchConfig, username, password string,
|
||||
channel chan stringResult, wtgrp *sync.WaitGroup)
|
||||
getImageByName(ctx context.Context, config searchConfig, username, password, imageName string,
|
||||
channel chan stringResult, wtgrp *sync.WaitGroup)
|
||||
getImageByNameAndCVEID(ctx context.Context, config searchConfig, username, password, imageName, cvid string,
|
||||
getImageByNameAndCVEID(ctx context.Context, config searchConfig, username, password, imageName, cveid string,
|
||||
channel chan stringResult, wtgrp *sync.WaitGroup)
|
||||
getReferrers(ctx context.Context, config searchConfig, username, password string, repo, digest string,
|
||||
) (referrersResult, error)
|
||||
@@ -577,7 +577,7 @@ func getImage(ctx context.Context, config searchConfig, username, password, imag
|
||||
}
|
||||
|
||||
func (service searchService) getImagesByCveID(ctx context.Context, config searchConfig, username,
|
||||
password, cvid string, rch chan stringResult, wtgrp *sync.WaitGroup,
|
||||
password, cveid string, rch chan stringResult, wtgrp *sync.WaitGroup,
|
||||
) {
|
||||
defer wtgrp.Done()
|
||||
defer close(rch)
|
||||
@@ -604,7 +604,7 @@ func (service searchService) getImagesByCveID(ctx context.Context, config search
|
||||
}
|
||||
}
|
||||
}`,
|
||||
cvid)
|
||||
cveid)
|
||||
|
||||
result := &common.ImagesForCve{}
|
||||
|
||||
@@ -723,7 +723,7 @@ func (service searchService) getImagesByDigest(ctx context.Context, config searc
|
||||
}
|
||||
|
||||
func (service searchService) getImageByNameAndCVEID(ctx context.Context, config searchConfig, username,
|
||||
password, imageName, cvid string, rch chan stringResult, wtgrp *sync.WaitGroup,
|
||||
password, imageName, cveid string, rch chan stringResult, wtgrp *sync.WaitGroup,
|
||||
) {
|
||||
defer wtgrp.Done()
|
||||
defer close(rch)
|
||||
@@ -750,7 +750,7 @@ func (service searchService) getImageByNameAndCVEID(ctx context.Context, config
|
||||
}
|
||||
}
|
||||
}`,
|
||||
cvid)
|
||||
cveid)
|
||||
|
||||
result := &common.ImagesForCve{}
|
||||
|
||||
@@ -854,7 +854,7 @@ func (service searchService) getCveByImage(ctx context.Context, config searchCon
|
||||
}
|
||||
|
||||
func (service searchService) getFixedTagsForCVE(ctx context.Context, config searchConfig,
|
||||
username, password, imageName, cvid string, rch chan stringResult, wtgrp *sync.WaitGroup,
|
||||
username, password, imageName, cveid string, rch chan stringResult, wtgrp *sync.WaitGroup,
|
||||
) {
|
||||
defer wtgrp.Done()
|
||||
defer close(rch)
|
||||
@@ -880,7 +880,7 @@ func (service searchService) getFixedTagsForCVE(ctx context.Context, config sear
|
||||
IsSigned
|
||||
}
|
||||
}
|
||||
}`, cvid, imageName)
|
||||
}`, cveid, imageName)
|
||||
|
||||
result := &common.ImageListWithCVEFixedResponse{}
|
||||
|
||||
@@ -1092,7 +1092,7 @@ type cveData struct {
|
||||
|
||||
func (cve cveResult) string(format string) (string, error) {
|
||||
switch strings.ToLower(format) {
|
||||
case "", defaultOutoutFormat:
|
||||
case "", defaultOutputFormat:
|
||||
return cve.stringPlainText()
|
||||
case jsonFormat:
|
||||
return cve.stringJSON()
|
||||
@@ -1151,7 +1151,7 @@ type referrersResult []common.Referrer
|
||||
|
||||
func (ref referrersResult) string(format string, maxArtifactTypeLen int) (string, error) {
|
||||
switch strings.ToLower(format) {
|
||||
case "", defaultOutoutFormat:
|
||||
case "", defaultOutputFormat:
|
||||
return ref.stringPlainText(maxArtifactTypeLen)
|
||||
case jsonFormat:
|
||||
return ref.stringJSON()
|
||||
@@ -1215,7 +1215,7 @@ type repoStruct common.RepoSummary
|
||||
|
||||
func (repo repoStruct) string(format string, maxImgNameLen, maxTimeLen int, verbose bool) (string, error) { //nolint: lll
|
||||
switch strings.ToLower(format) {
|
||||
case "", defaultOutoutFormat:
|
||||
case "", defaultOutputFormat:
|
||||
return repo.stringPlainText(maxImgNameLen, maxTimeLen, verbose)
|
||||
case jsonFormat:
|
||||
return repo.stringJSON()
|
||||
@@ -1234,7 +1234,7 @@ func (repo repoStruct) stringPlainText(repoMaxLen, maxTimeLen int, verbose bool)
|
||||
table.SetColMinWidth(repoNameIndex, repoMaxLen)
|
||||
table.SetColMinWidth(repoSizeIndex, sizeWidth)
|
||||
table.SetColMinWidth(repoLastUpdatedIndex, maxTimeLen)
|
||||
table.SetColMinWidth(repoDownloadsIndex, dounloadsWidth)
|
||||
table.SetColMinWidth(repoDownloadsIndex, downloadsWidth)
|
||||
table.SetColMinWidth(repoStarsIndex, signedWidth)
|
||||
|
||||
if verbose {
|
||||
@@ -1307,7 +1307,7 @@ type imageStruct common.ImageSummary
|
||||
|
||||
func (img imageStruct) string(format string, maxImgNameLen, maxTagLen, maxPlatformLen int, verbose bool) (string, error) { //nolint: lll
|
||||
switch strings.ToLower(format) {
|
||||
case "", defaultOutoutFormat:
|
||||
case "", defaultOutputFormat:
|
||||
return img.stringPlainText(maxImgNameLen, maxTagLen, maxPlatformLen, verbose)
|
||||
case jsonFormat:
|
||||
return img.stringJSON()
|
||||
@@ -1677,7 +1677,7 @@ const (
|
||||
platformWidth = 14
|
||||
sizeWidth = 10
|
||||
isSignedWidth = 8
|
||||
dounloadsWidth = 10
|
||||
downloadsWidth = 10
|
||||
signedWidth = 10
|
||||
lastUpdatedWidth = 14
|
||||
configWidth = 8
|
||||
@@ -1692,7 +1692,7 @@ const (
|
||||
colCVESeverityIndex = 1
|
||||
colCVETitleIndex = 2
|
||||
|
||||
defaultOutoutFormat = "text"
|
||||
defaultOutputFormat = "text"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
Reference in New Issue
Block a user