github.com/nektos/act@v0.2.63-0.20240520024548-8acde99bfa9c/pkg/container/docker_pull_test.go (about) 1 package container 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/docker/cli/cli/config" 8 9 log "github.com/sirupsen/logrus" 10 assert "github.com/stretchr/testify/assert" 11 ) 12 13 func init() { 14 log.SetLevel(log.DebugLevel) 15 } 16 17 func TestCleanImage(t *testing.T) { 18 tables := []struct { 19 imageIn string 20 imageOut string 21 }{ 22 {"myhost.com/foo/bar", "myhost.com/foo/bar"}, 23 {"localhost:8000/canonical/ubuntu", "localhost:8000/canonical/ubuntu"}, 24 {"localhost/canonical/ubuntu:latest", "localhost/canonical/ubuntu:latest"}, 25 {"localhost:8000/canonical/ubuntu:latest", "localhost:8000/canonical/ubuntu:latest"}, 26 {"ubuntu", "docker.io/library/ubuntu"}, 27 {"ubuntu:18.04", "docker.io/library/ubuntu:18.04"}, 28 {"cibuilds/hugo:0.53", "docker.io/cibuilds/hugo:0.53"}, 29 } 30 31 for _, table := range tables { 32 imageOut := cleanImage(context.Background(), table.imageIn) 33 assert.Equal(t, table.imageOut, imageOut) 34 } 35 } 36 37 func TestGetImagePullOptions(t *testing.T) { 38 ctx := context.Background() 39 40 config.SetDir("/non-existent/docker") 41 42 options, err := getImagePullOptions(ctx, NewDockerPullExecutorInput{}) 43 assert.Nil(t, err, "Failed to create ImagePullOptions") 44 assert.Equal(t, "", options.RegistryAuth, "RegistryAuth should be empty if no username or password is set") 45 46 options, err = getImagePullOptions(ctx, NewDockerPullExecutorInput{ 47 Image: "", 48 Username: "username", 49 Password: "password", 50 }) 51 assert.Nil(t, err, "Failed to create ImagePullOptions") 52 assert.Equal(t, "eyJ1c2VybmFtZSI6InVzZXJuYW1lIiwicGFzc3dvcmQiOiJwYXNzd29yZCJ9", options.RegistryAuth, "Username and Password should be provided") 53 54 config.SetDir("testdata/docker-pull-options") 55 56 options, err = getImagePullOptions(ctx, NewDockerPullExecutorInput{ 57 Image: "nektos/act", 58 }) 59 assert.Nil(t, err, "Failed to create ImagePullOptions") 60 assert.Equal(t, "eyJ1c2VybmFtZSI6InVzZXJuYW1lIiwicGFzc3dvcmQiOiJwYXNzd29yZFxuIiwic2VydmVyYWRkcmVzcyI6Imh0dHBzOi8vaW5kZXguZG9ja2VyLmlvL3YxLyJ9", options.RegistryAuth, "RegistryAuth should be taken from local docker config") 61 }