Skip to content

Commit

Permalink
test: add ut
Browse files Browse the repository at this point in the history
  • Loading branch information
welkeyever committed Nov 8, 2023
1 parent 4b7492b commit 8b7b2fc
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions pkg/protocol/uri_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
package protocol

import (
"bytes"
"path/filepath"
"reflect"
"runtime"
Expand Down Expand Up @@ -468,3 +469,39 @@ func TestParseURI(t *testing.T) {
uri := string(ParseURI(expectURI).FullURI())
assert.DeepEqual(t, expectURI, uri)
}

func TestSplitHostURI(t *testing.T) {
cases := []struct {
host, uri []byte
wantScheme, wantHost, wantPath []byte
}{
{
[]byte("example.com"), []byte("/foobar"),
[]byte("http"), []byte("example.com"), []byte("/foobar"),
},
{
[]byte("example2.com"), []byte("http://example2.com"),
[]byte("http"), []byte("example2.com"), []byte("/"),
},
{
[]byte("example2.com"), []byte("http://example3.com"),
[]byte("http"), []byte("example3.com"), []byte("/"),
},
{
[]byte("example3.com"), []byte("https://foobar.com?a=b"),
[]byte("https"), []byte("foobar.com"), []byte("?a=b"),
},
{
[]byte("example.com"), []byte("//www.google.com/://../../ping"),
[]byte("http"), []byte("example.com"), []byte("//www.google.com/://../../ping"),
},
}

for _, c := range cases {
gotScheme, gotHost, gotPath := splitHostURI(c.host, c.uri)
if !bytes.Equal(gotScheme, c.wantScheme) || !bytes.Equal(gotHost, c.wantHost) || !bytes.Equal(gotPath, c.wantPath) {
t.Errorf("splitHostURI(%q, %q) == (%q, %q, %q), want (%q, %q, %q)",
c.host, c.uri, gotScheme, gotHost, gotPath, c.wantScheme, c.wantHost, c.wantPath)
}
}
}

0 comments on commit 8b7b2fc

Please sign in to comment.