@@ -22,6 +22,7 @@ import (
22
22
"io/ioutil"
23
23
"os"
24
24
"path/filepath"
25
+ "strings"
25
26
"testing"
26
27
"time"
27
28
@@ -59,6 +60,25 @@ func TestGitCommit_GenerateFullyQualifiedImageName(t *testing.T) {
59
60
commit ("initial" )
60
61
},
61
62
},
63
+ {
64
+ description : "clean worktree with tag containing a slash" ,
65
+ variantTags : "test:v_2" ,
66
+ variantCommitSha : "test:aea33bcc86b5af8c8570ff45d8a643202d63c808" ,
67
+ variantAbbrevCommitSha : "test:aea33bc" ,
68
+ variantTreeSha : "test:bc69d50cda6897a6f2054e64b9059f038dc6fb0e" ,
69
+ variantAbbrevTreeSha : "test:bc69d50" ,
70
+ createGitRepo : func (dir string ) {
71
+ gitInit (t , dir ).
72
+ write ("source.go" , "code" ).
73
+ add ("source.go" ).
74
+ commit ("initial" ).
75
+ tag ("v/1" ).
76
+ write ("other.go" , "other" ).
77
+ add ("other.go" ).
78
+ commit ("second commit" ).
79
+ tag ("v/2" )
80
+ },
81
+ },
62
82
{
63
83
description : "clean worktree with tags" ,
64
84
variantTags : "test:v2" ,
@@ -341,6 +361,19 @@ func TestGitCommit_GenerateFullyQualifiedImageName(t *testing.T) {
341
361
}
342
362
}
343
363
364
+ func TestGitTagToDockerTag (t * testing.T ) {
365
+ testutil .CheckDeepEqual (t , "" , gitTagToDockerTag ("" ))
366
+ testutil .CheckDeepEqual (t , "abcdefghijklmnopqrstuvwxyz" , gitTagToDockerTag ("abcdefghijklmnopqrstuvwxyz" ))
367
+ testutil .CheckDeepEqual (t , "ABCDEFGHIJKLMNOPQRSTUVWXYZ" , gitTagToDockerTag ("ABCDEFGHIJKLMNOPQRSTUVWXYZ" ))
368
+ testutil .CheckDeepEqual (t , "0123456789-_." , gitTagToDockerTag ("0123456789-_." ))
369
+ testutil .CheckDeepEqual (t , "v_1" , gitTagToDockerTag ("v/1" ))
370
+ testutil .CheckDeepEqual (t , "v____1" , gitTagToDockerTag ("v%$@!1" ))
371
+ testutil .CheckDeepEqual (t , "_v1" , gitTagToDockerTag ("_v1" ))
372
+ testutil .CheckDeepEqual (t , "__v1" , gitTagToDockerTag ("--v1" ))
373
+ testutil .CheckDeepEqual (t , "__v1" , gitTagToDockerTag ("..v1" ))
374
+ testutil .CheckDeepEqual (t , 128 , len (gitTagToDockerTag (strings .Repeat ("0123456789" , 20 ))))
375
+ }
376
+
344
377
// gitRepo deals with test git repositories
345
378
type gitRepo struct {
346
379
dir string
0 commit comments