@@ -52,16 +52,22 @@ func Test_UserDataList(t *testing.T) {
52
52
}))
53
53
}
54
54
55
- func Test_UserDataFileUpload (t * testing.T ) {
55
+ func Test_UserDataFileUploadOn (t * testing.T ) {
56
56
content := "cloud-init file content"
57
+ file , err := os .CreateTemp (t .TempDir (), "test" )
58
+ if err != nil {
59
+ t .Fatalf ("%s" , err )
60
+ }
61
+ _ , err = file .WriteString (content )
62
+ if err != nil {
63
+ t .Fatalf ("%s" , err )
64
+ }
57
65
58
- t .Run ("on- cloud-init" , core .Test (& core.TestConfig {
66
+ t .Run ("cloud-init" , core .Test (& core.TestConfig {
59
67
Commands : instance .GetCommands (),
60
68
BeforeFunc : core .BeforeFuncCombine (
61
69
core .ExecStoreBeforeCmd ("Server" , testServerCommand ("stopped=true" )),
62
70
func (ctx * core.BeforeFuncCtx ) error {
63
- file , _ := os .CreateTemp (t .TempDir (), "test" )
64
- _ , _ = file .WriteString (content )
65
71
ctx .Meta ["filePath" ] = file .Name ()
66
72
67
73
return nil
@@ -71,22 +77,40 @@ func Test_UserDataFileUpload(t *testing.T) {
71
77
Check : core .TestCheckCombine (
72
78
core .TestCheckGolden (),
73
79
),
74
- AfterFunc : core .AfterFuncCombine (
75
- func (ctx * core.AfterFuncCtx ) error {
76
- _ = os .RemoveAll (ctx .Meta ["filePath" ].(string ))
80
+ AfterFunc : func (_ * core.AfterFuncCtx ) error {
81
+ // We need to close this file explicitly because it is not closed by the os.Remove call on windows
82
+ // https://github.com/golang/go/issues/50510
83
+ err = file .Close ()
84
+ if err != nil {
85
+ return err
86
+ }
77
87
78
- return nil
79
- },
80
- ),
88
+ err = os .RemoveAll (file .Name ())
89
+ if err != nil {
90
+ return err
91
+ }
92
+
93
+ return nil
94
+ },
81
95
}))
96
+ }
82
97
83
- t .Run ("on-random-key" , core .Test (& core.TestConfig {
98
+ func Test_UserDataFileUploadOnRandom (t * testing.T ) {
99
+ content := "cloud-init file content"
100
+ file , err := os .CreateTemp (t .TempDir (), "test" )
101
+ if err != nil {
102
+ t .Fatalf ("%s" , err )
103
+ }
104
+ _ , err = file .WriteString (content )
105
+ if err != nil {
106
+ t .Fatalf ("%s" , err )
107
+ }
108
+
109
+ t .Run ("key" , core .Test (& core.TestConfig {
84
110
Commands : instance .GetCommands (),
85
111
BeforeFunc : core .BeforeFuncCombine (
86
112
core .ExecStoreBeforeCmd ("Server" , testServerCommand ("stopped=true" )),
87
113
func (ctx * core.BeforeFuncCtx ) error {
88
- file , _ := os .CreateTemp (t .TempDir (), "test" )
89
- _ , _ = file .WriteString (content )
90
114
ctx .Meta ["filePath" ] = file .Name ()
91
115
92
116
return nil
@@ -96,12 +120,20 @@ func Test_UserDataFileUpload(t *testing.T) {
96
120
Check : core .TestCheckCombine (
97
121
core .TestCheckGolden (),
98
122
),
99
- AfterFunc : core .AfterFuncCombine (
100
- func (ctx * core.AfterFuncCtx ) error {
101
- _ = os .RemoveAll (ctx .Meta ["filePath" ].(string ))
123
+ AfterFunc : func (_ * core.AfterFuncCtx ) error {
124
+ // We need to close this file explicitly because it is not closed by the os.Remove call on windows
125
+ // https://github.com/golang/go/issues/50510
126
+ err = file .Close ()
127
+ if err != nil {
128
+ return err
129
+ }
102
130
103
- return nil
104
- },
105
- ),
131
+ err = os .RemoveAll (file .Name ())
132
+ if err != nil {
133
+ return err
134
+ }
135
+
136
+ return nil
137
+ },
106
138
}))
107
139
}
0 commit comments