-
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests: Simplify by using URL(); test core Path
- Loading branch information
1 parent
97717b9
commit 9dca126
Showing
4 changed files
with
129 additions
and
106 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
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,24 @@ | ||
package core_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/carlmjohnson/requests/internal/be" | ||
"github.com/carlmjohnson/requests/internal/core" | ||
) | ||
|
||
func TestPath(t *testing.T) { | ||
t.Parallel() | ||
for name, tc := range core.PathCases { | ||
t.Run(name, func(t *testing.T) { | ||
var b core.URLBuilder | ||
b.BaseURL(tc.Base) | ||
for _, p := range tc.Paths { | ||
b.Path(p) | ||
} | ||
u, err := b.URL() | ||
be.NilErr(t, err) | ||
be.Equal(t, tc.Result, u.String()) | ||
}) | ||
} | ||
} |
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,89 @@ | ||
package core | ||
|
||
// PathCases is exported to share tests with requests | ||
var PathCases = map[string]struct { | ||
Base string | ||
Paths []string | ||
Result string | ||
}{ | ||
"base-only": { | ||
"example", | ||
[]string{}, | ||
"https://example", | ||
}, | ||
"base+abspath": { | ||
"https://example", | ||
[]string{"/a"}, | ||
"https://example/a", | ||
}, | ||
"multi-abs-paths": { | ||
"https://example", | ||
[]string{"/a", "/b/", "/c"}, | ||
"https://example/c", | ||
}, | ||
"base+rel-path": { | ||
"https://example/a/", | ||
[]string{"./b"}, | ||
"https://example/a/b", | ||
}, | ||
"base+rel-paths": { | ||
"https://example/a/", | ||
[]string{"./b/", "./c"}, | ||
"https://example/a/b/c", | ||
}, | ||
"rel-path": { | ||
"https://example/", | ||
[]string{"a/", "./b"}, | ||
"https://example/a/b", | ||
}, | ||
"base+multi-paths": { | ||
"https://example/a/", | ||
[]string{"b/", "c"}, | ||
"https://example/a/b/c", | ||
}, | ||
"base+slash+multi-paths": { | ||
"https://example/a/", | ||
[]string{"b/", "c"}, | ||
"https://example/a/b/c", | ||
}, | ||
"multi-root": { | ||
"https://example/", | ||
[]string{"a", "b", "c"}, | ||
"https://example/c", | ||
}, | ||
"dot-dot-paths": { | ||
"https://example/", | ||
[]string{"a/", "b/", "../c"}, | ||
"https://example/a/c", | ||
}, | ||
"more-dot-dot-paths": { | ||
"https://example/", | ||
[]string{"a/b/c/", "../d/", "../e"}, | ||
"https://example/a/b/e", | ||
}, | ||
"more-dot-dot-paths+rel-path": { | ||
"https://example/", | ||
[]string{"a/b/c/", "../d/", "../e/", "./f"}, | ||
"https://example/a/b/e/f", | ||
}, | ||
"even-more-dot-dot-paths+base": { | ||
"https://example/a/b/c/", | ||
[]string{"../../d"}, | ||
"https://example/a/d", | ||
}, | ||
"too-many-dot-dot-paths": { | ||
"https://example", | ||
[]string{"../a"}, | ||
"https://example/a", | ||
}, | ||
"too-many-dot-dot-paths+base": { | ||
"https://example/", | ||
[]string{"../a"}, | ||
"https://example/a", | ||
}, | ||
"last-abs-path-wins": { | ||
"https://example/a/", | ||
[]string{"b/", "c/", "/d"}, | ||
"https://example/d", | ||
}, | ||
} |