-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
115 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,4 @@ | |
dist/ | ||
*.exe | ||
|
||
.idea | ||
.idea/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package main | ||
|
||
import ( | ||
"net/url" | ||
"os" | ||
"testing" | ||
) | ||
|
||
func TestDifferentTypesOfParsing(t *testing.T) { | ||
// Create a temporary file | ||
tempFile, err := os.CreateTemp("", "test20230815114.txt") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer os.Remove(tempFile.Name()) // Clean up | ||
|
||
testCases := []struct { | ||
pv string | ||
isUriType bool | ||
expectErr bool | ||
}{ | ||
{ | ||
pv: "http://example.com", | ||
isUriType: true, | ||
expectErr: false, | ||
}, | ||
{ | ||
pv: "thisisnotavaliduri", | ||
isUriType: true, | ||
expectErr: true, | ||
}, | ||
{ | ||
pv: tempFile.Name(), | ||
isUriType: false, | ||
expectErr: false, | ||
}, | ||
{ | ||
pv: "non_existent_file.txt", | ||
isUriType: false, | ||
expectErr: true, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
result := DifferentTypesOfParsing(tc.pv, tc.isUriType) | ||
if tc.expectErr && result != nil { | ||
t.Errorf("Expected error for pv %s, but got no error", tc.pv) | ||
} | ||
if !tc.isUriType && result != nil { | ||
_, ok := result.(os.File) | ||
if !ok { | ||
t.Errorf("Expected FileInfo type for pv %s", tc.pv) | ||
} | ||
} | ||
if tc.isUriType && result != nil { | ||
_, ok := result.(*url.URL) | ||
if !ok { | ||
t.Errorf("Expected URL type for pv %s", tc.pv) | ||
} | ||
} | ||
} | ||
} |