-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: return file protocol by default
- Loading branch information
1 parent
d154bd3
commit aaf1554
Showing
2 changed files
with
51 additions
and
0 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
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,48 @@ | ||
package utils_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/WangYihang/gojob/pkg/utils" | ||
) | ||
|
||
func TestParseProtocol(t *testing.T) { | ||
testcases := []struct { | ||
uri string | ||
expected string | ||
}{ | ||
{ | ||
uri: "http://example.com", | ||
expected: "http", | ||
}, | ||
{ | ||
uri: "https://example.com", | ||
expected: "https", | ||
}, | ||
{ | ||
uri: "ftp://example.com", | ||
expected: "ftp", | ||
}, | ||
{ | ||
uri: "file://example.com", | ||
expected: "file", | ||
}, | ||
{ | ||
uri: "s3://bucket/shakespeare.txt", | ||
expected: "s3", | ||
}, | ||
{ | ||
uri: "/etc/passwd", | ||
expected: "file", | ||
}, | ||
} | ||
for _, tc := range testcases { | ||
protocol, err := utils.ParseProtocol(tc.uri) | ||
if err != nil { | ||
t.Errorf("unexpected error: %v", err) | ||
} | ||
if protocol != tc.expected { | ||
t.Errorf("expected %s, got %s", tc.expected, protocol) | ||
} | ||
} | ||
} |