@@ -186,13 +186,34 @@ func TestImportProfile(t *testing.T) {
186186
187187func TestExportProfile (t * testing.T ) {
188188 // Create directory where the export configs should be stored
189- testDir , err := os .MkdirTemp ("." , "stackit-cli-test" )
189+ testDir , err := os .MkdirTemp (os . TempDir () , "stackit-cli-test" )
190190 if err != nil {
191191 t .Fatal (err )
192192 }
193- defer func (path string ) {
194- _ = os .RemoveAll (path )
195- }(testDir )
193+ t .Cleanup (func () {
194+ func (path string ) {
195+ err := os .RemoveAll (path )
196+ if err != nil {
197+ fmt .Printf ("could not clean up temp dir: %v\n " , err )
198+ }
199+ }(testDir )
200+ })
201+
202+ // Create prerequisite profile
203+ p := print .NewPrinter ()
204+ profileName := "export-profile-test"
205+ err = CreateProfile (p , profileName , false , false )
206+ if err != nil {
207+ t .Fatalf ("could not create prerequisite profile, %v" , err )
208+ }
209+ t .Cleanup (func () {
210+ func (p * print.Printer , profile string ) {
211+ err := DeleteProfile (p , profile )
212+ if err != nil {
213+ fmt .Printf ("could not clean up prerequisite profile %q, %v" , profileName , err )
214+ }
215+ }(p , profileName )
216+ })
196217
197218 tests := []struct {
198219 description string
@@ -202,7 +223,7 @@ func TestExportProfile(t *testing.T) {
202223 }{
203224 {
204225 description : "valid profile" ,
205- profile : "default" ,
226+ profile : profileName ,
206227 filePath : testDir ,
207228 isValid : true ,
208229 },
@@ -213,13 +234,13 @@ func TestExportProfile(t *testing.T) {
213234 },
214235 {
215236 description : "custom file name" ,
216- profile : "default" ,
237+ profile : profileName ,
217238 filePath : filepath .Join (testDir , fmt .Sprintf ("custom-name.%s" , configFileExtension )),
218239 isValid : true ,
219240 },
220241 {
221242 description : "not existing path" ,
222- profile : "default" ,
243+ profile : profileName ,
223244 filePath : filepath .Join (testDir , "invalid" , "path" ),
224245 isValid : false ,
225246 },
0 commit comments