@@ -2,9 +2,9 @@ package storage
22
33import (
44 "io"
5+ "io/fs"
56 "net/url"
67 "os"
7- "runtime"
88 "slices"
99 "strings"
1010 "testing"
@@ -59,17 +59,12 @@ func TestImportCommand(t *testing.T) {
5959 State : upcloud .StorageImportStateCompleted ,
6060 }
6161
62- fileNotFoundErr := "cannot get file size: stat testfile: no such file or directory"
63- if runtime .GOOS == "windows" {
64- fileNotFoundErr = "cannot get file size: CreateFile testfile: The system cannot find the file specified."
65- }
66-
6762 for _ , test := range []struct {
68- name string
69- args []string
70- error string
71- request request. CreateStorageImportRequest
72- windowsError string
63+ name string
64+ args []string
65+ error string
66+ expectFileNotExist bool
67+ request request. CreateStorageImportRequest
7368 }{
7469 {
7570 name : "source is missing" ,
@@ -127,7 +122,7 @@ func TestImportCommand(t *testing.T) {
127122 "--zone" , "fi-hel1" ,
128123 "--title" , "test-2" ,
129124 },
130- error : fileNotFoundErr ,
125+ expectFileNotExist : true ,
131126 },
132127 } {
133128 t .Run (test .name , func (t * testing.T ) {
@@ -146,8 +141,13 @@ func TestImportCommand(t *testing.T) {
146141 c .Cobra ().SetArgs (test .args )
147142 _ , err := mockexecute .MockExecute (c , mService , conf )
148143
149- if test .error != "" {
150- assert .EqualError (t , err , test .error )
144+ if test .error != "" || test .expectFileNotExist {
145+ assert .Error (t , err )
146+ if test .expectFileNotExist {
147+ assert .ErrorIs (t , err , fs .ErrNotExist )
148+ } else {
149+ assert .EqualError (t , err , test .error )
150+ }
151151 } else {
152152 assert .NoError (t , err )
153153
@@ -169,7 +169,7 @@ func TestParseSource(t *testing.T) {
169169 name string
170170 input string
171171 expectedError string
172- expectedWindowsError string
172+ expectFileNotExist bool
173173 expectedSourceType string
174174 expectedFileSize int64
175175 expectedParsedURLScheme string
@@ -191,10 +191,9 @@ func TestParseSource(t *testing.T) {
191191 expectedParsedURLPath : "tempfile" ,
192192 },
193193 {
194- name : "local non-existent file" ,
195- input : "foobar" ,
196- expectedError : "cannot get file size: stat foobar: no such file or directory" ,
197- expectedWindowsError : "cannot get file size: CreateFile foobar: The system cannot find the file specified." ,
194+ name : "local non-existent file" ,
195+ input : "foobar" ,
196+ expectFileNotExist : true ,
198197 },
199198 {
200199 name : "remote http url" ,
@@ -240,9 +239,10 @@ func TestParseSource(t *testing.T) {
240239 } else {
241240 purl , stype , fsize , err = parseSource (test .input )
242241 }
243- if test .expectedError != "" {
244- if test .expectedWindowsError != "" && runtime .GOOS == "windows" {
245- assert .EqualError (t , err , test .expectedWindowsError )
242+ if test .expectedError != "" || test .expectFileNotExist {
243+ assert .Error (t , err )
244+ if test .expectFileNotExist {
245+ assert .ErrorIs (t , err , fs .ErrNotExist )
246246 } else {
247247 assert .EqualError (t , err , test .expectedError )
248248 }
0 commit comments