@@ -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,23 @@ func TestGitCommit_GenerateFullyQualifiedImageName(t *testing.T) {
341
361
}
342
362
}
343
363
364
+ func TestSanitizeTag (t * testing.T ) {
365
+ testutil .Run (t , "valid tags" , func (t * testutil.T ) {
366
+ t .CheckDeepEqual ("abcdefghijklmnopqrstuvwxyz" , sanitizeTag ("abcdefghijklmnopqrstuvwxyz" ))
367
+ t .CheckDeepEqual ("ABCDEFGHIJKLMNOPQRSTUVWXYZ" , sanitizeTag ("ABCDEFGHIJKLMNOPQRSTUVWXYZ" ))
368
+ t .CheckDeepEqual ("0123456789-_." , sanitizeTag ("0123456789-_." ))
369
+ t .CheckDeepEqual ("_v1" , sanitizeTag ("_v1" ))
370
+ })
371
+
372
+ testutil .Run (t , "sanitized tags" , func (t * testutil.T ) {
373
+ t .CheckDeepEqual ("v_1" , sanitizeTag ("v/1" ))
374
+ t .CheckDeepEqual ("v____1" , sanitizeTag ("v%$@!1" ))
375
+ t .CheckDeepEqual ("__v1" , sanitizeTag ("--v1" ))
376
+ t .CheckDeepEqual ("__v1" , sanitizeTag ("..v1" ))
377
+ t .CheckDeepEqual (128 , len (sanitizeTag (strings .Repeat ("0123456789" , 20 ))))
378
+ })
379
+ }
380
+
344
381
// gitRepo deals with test git repositories
345
382
type gitRepo struct {
346
383
dir string
0 commit comments