summaryrefslogtreecommitdiff
path: root/internal/httpwrap/httpwrap_test.go
diff options
context:
space:
mode:
authorJeroen Wijenbergh <jeroen.wijenbergh@geant.org>2026-02-12 12:34:08 +0100
committerJeroen Wijenbergh <jeroen.wijenbergh@geant.org>2026-02-12 12:59:03 +0100
commita30ef6b27e578a4cf0a674b24f5b52b4c1516c63 (patch)
tree27c7321cbceac2a487c1ba17151711de3d438a53 /internal/httpwrap/httpwrap_test.go
parentb00ce8214479c50e137db73c77b0cc1393c5e7d4 (diff)
All: Rename packages that sound useless or clash with std
Diffstat (limited to 'internal/httpwrap/httpwrap_test.go')
-rw-r--r--internal/httpwrap/httpwrap_test.go61
1 files changed, 61 insertions, 0 deletions
diff --git a/internal/httpwrap/httpwrap_test.go b/internal/httpwrap/httpwrap_test.go
new file mode 100644
index 0000000..422ee3f
--- /dev/null
+++ b/internal/httpwrap/httpwrap_test.go
@@ -0,0 +1,61 @@
+package httpwrap
+
+import (
+ "testing"
+)
+
+func TestEnsureValidURL(t *testing.T) {
+ _, validErr := EnsureValidURL("%notvalid%", true)
+
+ if validErr == nil {
+ t.Fatal("Got nil error, want: non-nil")
+ }
+
+ testCases := map[string]string{
+ // Make sure we set https
+ "example.com/": "https://example.com/",
+ // Make sure we do override the scheme to https
+ "http://example.com/": "https://example.com/",
+ // This URL is already valid
+ "https://example.com/": "https://example.com/",
+ // Make sure to add a trailing slash (/)
+ "https://example.com": "https://example.com/",
+ // Cleanup the path 1
+ "https://example.com/////": "https://example.com/",
+ // Cleanup the path 2
+ "https://example.com/..": "https://example.com/",
+ }
+
+ for k, v := range testCases {
+ valid, validErr := EnsureValidURL(k, true)
+ if validErr != nil {
+ t.Fatalf("Got: %v, want: nil", validErr)
+ }
+ if valid != v {
+ t.Fatalf("Got: %v, want: %v", valid, v)
+ }
+ }
+}
+
+func Test_JoinURLPath(t *testing.T) {
+ cases := []struct {
+ u string
+ p string
+ want string
+ }{
+ {u: "https://example.com", p: "test", want: "https://example.com/test"},
+ {u: "https://example.com", p: "/test", want: "https://example.com/test"},
+ {u: "https://example.com", p: "../test", want: "https://example.com/test"},
+ {u: "https://example.com", p: "../test/", want: "https://example.com/test"},
+ {u: "https://example.com", p: "test/", want: "https://example.com/test"},
+ }
+ for _, c := range cases {
+ got, err := JoinURLPath(c.u, c.p)
+ if err != nil {
+ t.Fatalf("Failed to parse join url case: %v, err: %v", c, err)
+ }
+ if got != c.want {
+ t.Fatalf("Failed test case for joining URL, want: %v, got: %v", c.want, got)
+ }
+ }
+}