github.com/saucelabs/saucectl@v0.175.1/internal/yaml/file_test.go (about) 1 package yaml 2 3 import ( 4 "os" 5 "path/filepath" 6 "testing" 7 ) 8 9 func TestWriteFile(t *testing.T) { 10 type sample struct { 11 Msg string `yaml:"msg"` 12 } 13 14 type args struct { 15 name string 16 v interface{} 17 mode os.FileMode 18 } 19 tests := []struct { 20 name string 21 args args 22 wantErr bool 23 }{ 24 { 25 name: "happy path", 26 args: args{ 27 name: filepath.Join(os.TempDir(), "saucy.yml"), 28 v: sample{Msg: "hello world!"}, 29 mode: 0777, 30 }, 31 wantErr: false, 32 }, 33 } 34 for _, tt := range tests { 35 t.Run(tt.name, func(t *testing.T) { 36 if err := WriteFile(tt.args.name, tt.args.v, tt.args.mode); (err != nil) != tt.wantErr { 37 t.Errorf("WriteFile() error = %v, wantErr %v", err, tt.wantErr) 38 } 39 }) 40 } 41 }