github.com/hazelops/ize@v1.1.12-0.20230915191306-97d7c0e48f11/internal/commands/ci_test.go (about) 1 package commands 2 3 import ( 4 _ "embed" 5 "os" 6 "path/filepath" 7 "testing" 8 "text/template" 9 10 "github.com/hazelops/ize/internal/config" 11 "github.com/hazelops/ize/tests/data" 12 ) 13 14 func TestTemplate_Execute(t *testing.T) { 15 tempDir, _ := os.MkdirTemp("", "test") 16 err := copyEmbedData(data.TestData, "boilerplate-template", filepath.Join(tempDir, "template")) 17 if err != nil { 18 t.Error(err) 19 return 20 } 21 22 type fields struct { 23 Path string 24 FuncMap template.FuncMap 25 Data interface{} 26 } 27 type args struct { 28 dir string 29 } 30 tests := []struct { 31 name string 32 fields fields 33 args args 34 wantErr bool 35 }{ 36 {name: "success", fields: fields{ 37 Path: filepath.Join(tempDir, "template"), 38 FuncMap: map[string]any{ 39 "env": func() string { return "dev" }, 40 "namespace": func() string { return "testnut" }, 41 }, 42 Data: config.Project{ 43 Env: "dev", 44 Namespace: "testnut", 45 AwsProfile: "default", 46 AwsRegion: "us-east-2", 47 }, 48 }, args: args{dir: filepath.Join(tempDir, "target")}, wantErr: false}, 49 } 50 for _, tt := range tests { 51 t.Run(tt.name, func(t1 *testing.T) { 52 tmpl := &Template{ 53 Path: tt.fields.Path, 54 FuncMap: tt.fields.FuncMap, 55 Data: tt.fields.Data, 56 } 57 if err := tmpl.Execute(tt.args.dir); (err != nil) != tt.wantErr { 58 t1.Errorf("Execute() error = %v, wantErr %v", err, tt.wantErr) 59 } 60 }) 61 } 62 }