f571290b25
* refactor: remove `gotest.tools` * remove all references to `gotest.tools` and replace it with `github.com/stretchr/testify` which was originally used for tests * bump `golangci-lint` version * add `depguard` and `importas` to prevent import of unwanted packages * add custom schema and information about config since schemastore.org has broken schema for `golangci-lint` config * fix: handle more error cases
46 lines
1.2 KiB
Go
46 lines
1.2 KiB
Go
package container
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
assert "github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func init() {
|
|
log.SetLevel(log.DebugLevel)
|
|
}
|
|
|
|
func TestCleanImage(t *testing.T) {
|
|
tables := []struct {
|
|
imageIn string
|
|
imageOut string
|
|
}{
|
|
{"myhost.com/foo/bar", "myhost.com/foo/bar"},
|
|
{"ubuntu", "docker.io/library/ubuntu"},
|
|
{"ubuntu:18.04", "docker.io/library/ubuntu:18.04"},
|
|
{"cibuilds/hugo:0.53", "docker.io/cibuilds/hugo:0.53"},
|
|
}
|
|
|
|
for _, table := range tables {
|
|
imageOut := cleanImage(table.imageIn)
|
|
assert.Equal(t, table.imageOut, imageOut)
|
|
}
|
|
}
|
|
|
|
func TestGetImagePullOptions(t *testing.T) {
|
|
ctx := context.Background()
|
|
|
|
options, err := getImagePullOptions(ctx, NewDockerPullExecutorInput{})
|
|
assert.Nil(t, err, "Failed to create ImagePullOptions")
|
|
assert.Equal(t, options.RegistryAuth, "", "RegistryAuth should be empty if no username or password is set")
|
|
|
|
options, err = getImagePullOptions(ctx, NewDockerPullExecutorInput{
|
|
Image: "",
|
|
Username: "username",
|
|
Password: "password",
|
|
})
|
|
assert.Nil(t, err, "Failed to create ImagePullOptions")
|
|
assert.Equal(t, options.RegistryAuth, "eyJ1c2VybmFtZSI6InVzZXJuYW1lIiwicGFzc3dvcmQiOiJwYXNzd29yZCJ9", "Username and Password should be provided")
|
|
}
|