@@ -22,7 +22,7 @@ func Test_templatePull(t *testing.T) {
2222 faasCmd .SetArgs ([]string {"template" , "pull" , localTemplateRepository })
2323 err := faasCmd .Execute ()
2424 if err != nil {
25- t .Errorf ("unexpected error while puling valid repo: %s" , err .Error ())
25+ t .Fatalf ("unexpected error while puling valid repo (%q) : %s" , localTemplateRepository , err .Error ())
2626 }
2727
2828 // Verify created directories
@@ -33,33 +33,31 @@ func Test_templatePull(t *testing.T) {
3333
3434 t .Run ("WithOverwriting" , func (t * testing.T ) {
3535 defer tearDownFetchTemplates (t )
36-
37- faasCmd .SetArgs ([]string {"template" , "pull" , localTemplateRepository })
38- err := faasCmd .Execute ()
39- if err != nil {
40- t .Errorf ("unexpected error while executing template pull: %s" , err .Error ())
36+ faasCmd .SetArgs ([]string {"template" , "pull" , "--overwrite=false" , localTemplateRepository })
37+ if err := faasCmd .Execute (); err != nil {
38+ t .Errorf ("unexpected error while executing initial template pull: %s" , err .Error ())
4139 }
4240
4341 var buf bytes.Buffer
4442 log .SetOutput (& buf )
4543
46- r := regexp .MustCompile (`(?m:Cannot overwrite the following \d+ template\(s\):)` )
47-
48- faasCmd .SetArgs ([]string {"template" , "pull" , localTemplateRepository })
49- err = faasCmd .Execute ()
50- if err != nil {
44+ overwrite = false
45+ faasCmd .SetArgs ([]string {"template" , "pull" , "--overwrite=false" , localTemplateRepository })
46+ if err := faasCmd .Execute (); err != nil {
5147 t .Errorf ("unexpected error while executing template pull: %s" , err .Error ())
5248 }
5349
50+ r := regexp .MustCompile (`(?m:Cannot overwrite the following \d+ template\(s\):)` )
5451 if ! r .MatchString (buf .String ()) {
55- t .Fatal ( buf .String ())
52+ t .Fatalf ( "Output from stdio didn't match expression: %s \n vs: %s" , buf . String (), r .String ())
5653 }
5754
5855 buf .Reset ()
5956
57+ overwrite = true
58+
6059 faasCmd .SetArgs ([]string {"template" , "pull" , localTemplateRepository , "--overwrite" })
61- err = faasCmd .Execute ()
62- if err != nil {
60+ if err := faasCmd .Execute (); err != nil {
6361 t .Errorf ("unexpected error while executing template pull with --overwrite: %s" , err .Error ())
6462 }
6563
@@ -80,10 +78,11 @@ func Test_templatePull(t *testing.T) {
8078 want := "the repository URL must be a valid git repo uri"
8179 got := err .Error ()
8280 if ! strings .Contains (err .Error (), want ) {
83- t .Errorf ("The error should contain:\n %q\n , but was:\n %q" , want , got )
81+ t .Fatalf ("The error should contain:\n %q\n , but was:\n %q" , want , got )
8482 }
8583 })
8684}
85+
8786func Test_templatePullPriority (t * testing.T ) {
8887 templateURLs := []struct {
8988 name string
@@ -113,7 +112,7 @@ func Test_templatePullPriority(t *testing.T) {
113112 },
114113 }
115114 for _ , scenario := range templateURLs {
116- t .Run (fmt . Sprintf ( "%s" , scenario .name ) , func (t * testing.T ) {
115+ t .Run (scenario .name , func (t * testing.T ) {
117116 repository = getTemplateURL (scenario .cliURL , scenario .envURL , DefaultTemplateRepository )
118117 if repository != scenario .resultURL {
119118 t .Errorf ("result URL, want %s got %s" , scenario .resultURL , repository )
0 commit comments