Use uniuri to generate temporary tag

This commit is contained in:
Rutvij Mehta
2023-05-16 10:14:18 -07:00
parent 47e09cf885
commit a38298c4f2
4 changed files with 23 additions and 29 deletions
+15 -12
View File
@@ -1,12 +1,15 @@
package docker
import (
"github.com/dchest/uniuri"
"os/exec"
"reflect"
"strings"
"testing"
)
func TestCommandBuild(t *testing.T) {
tempTag := strings.ToLower(uniuri.New())
tcs := []struct {
name string
build Build
@@ -16,7 +19,7 @@ func TestCommandBuild(t *testing.T) {
name: "secret from env var",
build: Build{
Name: "plugins/drone-docker:latest",
TempTag: "abcdefgh",
TempTag: tempTag,
Dockerfile: "Dockerfile",
Context: ".",
SecretEnvs: []string{
@@ -30,7 +33,7 @@ func TestCommandBuild(t *testing.T) {
"-f",
"Dockerfile",
"-t",
"abcdefgh",
tempTag,
".",
"--secret id=foo_secret,env=FOO_SECRET_ENV_VAR",
),
@@ -39,7 +42,7 @@ func TestCommandBuild(t *testing.T) {
name: "secret from file",
build: Build{
Name: "plugins/drone-docker:latest",
TempTag: "abcdefgh",
TempTag: tempTag,
Dockerfile: "Dockerfile",
Context: ".",
SecretFiles: []string{
@@ -53,7 +56,7 @@ func TestCommandBuild(t *testing.T) {
"-f",
"Dockerfile",
"-t",
"abcdefgh",
tempTag,
".",
"--secret id=foo_secret,src=/path/to/foo_secret",
),
@@ -62,7 +65,7 @@ func TestCommandBuild(t *testing.T) {
name: "multiple mixed secrets",
build: Build{
Name: "plugins/drone-docker:latest",
TempTag: "abcdefgh",
TempTag: tempTag,
Dockerfile: "Dockerfile",
Context: ".",
SecretEnvs: []string{
@@ -81,7 +84,7 @@ func TestCommandBuild(t *testing.T) {
"-f",
"Dockerfile",
"-t",
"abcdefgh",
tempTag,
".",
"--secret id=foo_secret,env=FOO_SECRET_ENV_VAR",
"--secret id=bar_secret,env=BAR_SECRET_ENV_VAR",
@@ -93,7 +96,7 @@ func TestCommandBuild(t *testing.T) {
name: "invalid mixed secrets",
build: Build{
Name: "plugins/drone-docker:latest",
TempTag: "abcdefgh",
TempTag: tempTag,
Dockerfile: "Dockerfile",
Context: ".",
SecretEnvs: []string{
@@ -114,7 +117,7 @@ func TestCommandBuild(t *testing.T) {
"-f",
"Dockerfile",
"-t",
"abcdefgh",
tempTag,
".",
),
},
@@ -122,7 +125,7 @@ func TestCommandBuild(t *testing.T) {
name: "platform argument",
build: Build{
Name: "plugins/drone-docker:latest",
TempTag: "abcdefgh",
TempTag: tempTag,
Dockerfile: "Dockerfile",
Context: ".",
Platform: "test/platform",
@@ -134,7 +137,7 @@ func TestCommandBuild(t *testing.T) {
"-f",
"Dockerfile",
"-t",
"abcdefgh",
tempTag,
".",
"--platform",
"test/platform",
@@ -144,7 +147,7 @@ func TestCommandBuild(t *testing.T) {
name: "ssh agent",
build: Build{
Name: "plugins/drone-docker:latest",
TempTag: "abcdefgh",
TempTag: tempTag,
Dockerfile: "Dockerfile",
Context: ".",
SSHKeyPath: "id_rsa=/root/.ssh/id_rsa",
@@ -156,7 +159,7 @@ func TestCommandBuild(t *testing.T) {
"-f",
"Dockerfile",
"-t",
"abcdefgh",
tempTag,
".",
"--ssh id_rsa=/root/.ssh/id_rsa",
),