mirror of
https://github.com/project-zot/zot.git
synced 2025-01-06 22:40:28 -05:00
19003e8a71
Periodically poll registries and pull images according to sync's config Added sync on demand, syncing when clients asks for an image which zot doesn't have. Signed-off-by: Petu Eusebiu <peusebiu@cisco.com>
109 lines
3 KiB
Go
109 lines
3 KiB
Go
package sync
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"io/ioutil"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/anuvu/zot/errors"
|
|
"github.com/anuvu/zot/pkg/log"
|
|
"github.com/containers/image/v5/docker"
|
|
"github.com/containers/image/v5/docker/reference"
|
|
"github.com/containers/image/v5/types"
|
|
. "github.com/smartystreets/goconvey/convey"
|
|
)
|
|
|
|
const (
|
|
BaseURL = "http://127.0.0.1:5001"
|
|
ServerCert = "../../../test/data/server.cert"
|
|
ServerKey = "../../../test/data/server.key"
|
|
CACert = "../../../test/data/ca.crt"
|
|
|
|
testImage = "zot-test"
|
|
testImageTag = "0.0.1"
|
|
|
|
host = "127.0.0.1:45117"
|
|
)
|
|
|
|
func TestSyncInternal(t *testing.T) {
|
|
Convey("test parseRepositoryReference func", t, func() {
|
|
repositoryReference := fmt.Sprintf("%s/%s", host, testImage)
|
|
ref, err := parseRepositoryReference(repositoryReference)
|
|
So(err, ShouldBeNil)
|
|
So(ref.Name(), ShouldEqual, repositoryReference)
|
|
|
|
repositoryReference = fmt.Sprintf("%s/%s:tagged", host, testImage)
|
|
_, err = parseRepositoryReference(repositoryReference)
|
|
So(err, ShouldEqual, errors.ErrInvalidRepositoryName)
|
|
|
|
repositoryReference = fmt.Sprintf("http://%s/%s", host, testImage)
|
|
_, err = parseRepositoryReference(repositoryReference)
|
|
So(err, ShouldNotBeNil)
|
|
|
|
repositoryReference = fmt.Sprintf("docker://%s/%s", host, testImage)
|
|
_, err = parseRepositoryReference(repositoryReference)
|
|
So(err, ShouldNotBeNil)
|
|
|
|
_, err = getFileCredentials("/path/to/inexistent/file")
|
|
So(err, ShouldNotBeNil)
|
|
|
|
f, err := ioutil.TempFile("", "sync-credentials-")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
content := []byte(`{`)
|
|
if err := ioutil.WriteFile(f.Name(), content, 0600); err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
_, err = getFileCredentials(f.Name())
|
|
So(err, ShouldNotBeNil)
|
|
|
|
srcCtx := &types.SystemContext{}
|
|
_, err = getImageTags(context.Background(), srcCtx, ref)
|
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
_, _, err = getLocalContexts("inexistent.cert", "inexistent.key", "inexistent.crt", log.NewLogger("", ""))
|
|
So(err, ShouldNotBeNil)
|
|
|
|
_, _, err = getLocalContexts(ServerCert, "inexistent.key", "inexistent.crt", log.NewLogger("", ""))
|
|
So(err, ShouldNotBeNil)
|
|
|
|
_, _, err = getLocalContexts(ServerCert, ServerKey, "inexistent.crt", log.NewLogger("", ""))
|
|
So(err, ShouldNotBeNil)
|
|
|
|
taggedRef, err := reference.WithTag(ref, testImageTag)
|
|
So(err, ShouldBeNil)
|
|
|
|
dockerRef, err := docker.NewReference(taggedRef)
|
|
So(err, ShouldBeNil)
|
|
|
|
So(getTagFromRef(dockerRef, log.NewLogger("", "")), ShouldNotBeNil)
|
|
|
|
var tlsVerify bool
|
|
updateDuration := time.Microsecond
|
|
syncRegistryConfig := RegistryConfig{
|
|
Content: []Content{
|
|
{
|
|
Prefix: testImage,
|
|
},
|
|
},
|
|
URL: BaseURL,
|
|
PollInterval: updateDuration,
|
|
TLSVerify: &tlsVerify,
|
|
CertDir: "",
|
|
}
|
|
|
|
cfg := Config{Registries: []RegistryConfig{syncRegistryConfig}, CredentialsFile: "/invalid/path/to/file"}
|
|
|
|
So(Run(cfg, log.NewLogger("", ""),
|
|
"127.0.0.1", "5000", ServerCert, ServerKey, CACert), ShouldNotBeNil)
|
|
|
|
_, err = getFileCredentials("/invalid/path/to/file")
|
|
So(err, ShouldNotBeNil)
|
|
})
|
|
}
|