-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse_url_test.go
35 lines (31 loc) · 1.25 KB
/
parse_url_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package jsonnet_test
import (
"fmt"
"testing"
f "github.com/harsimranmaan/go-jsonnet-func"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestParseURL(t *testing.T) {
var tests = []struct {
input []interface{}
output map[string]interface{}
expectedErr string
}{
{nil, nil, "bad arguments to parseUrl: needs 1 argument"},
{[]interface{}{"https://me:[email protected]:8080/abc?param=1¶m=2#frag"}, map[string]interface{}{"fragment": "frag", "host": "example.com:8080", "hostname": "example.com", "opaque": "", "path": "/abc", "port": "8080", "query": "param=1¶m=2", "scheme": "https", "userinfo": "me:pwd"}, ""},
{[]interface{}{"data:text/plain;base64,SGVsbG8sIFdvcmxkIQ=="}, map[string]interface{}{"fragment": "", "host": "", "hostname": "", "opaque": "text/plain;base64,SGVsbG8sIFdvcmxkIQ==", "path": "", "port": "", "query": "", "scheme": "data", "userinfo": ""}, ""},
}
for i, test := range tests {
t.Run(fmt.Sprintf("parseUrl-%d", i), func(t *testing.T) {
ret, err := f.ParseURL().Func(test.input)
if test.expectedErr == "" {
require.Nil(t, err)
assert.Equal(t, test.output, ret)
} else {
require.NotNil(t, err)
assert.Equal(t, test.expectedErr, err.Error())
}
})
}
}