Skip to content

Commit fab6e43

Browse files
committed
add test
1 parent 13808cc commit fab6e43

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

internal/api/api_test.go

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,40 @@
11
package api
22

3-
// TODO: implement a super basic GraphQL server that can return canned results.
3+
import (
4+
"net/url"
5+
"testing"
6+
)
7+
8+
func TestBuildTransport(t *testing.T) {
9+
boolPtr := func(b bool) *bool { return &b }
10+
11+
t.Run("insecure skip verify", func(t *testing.T) {
12+
transport := buildTransport(ClientOpts{}, &Flags{insecureSkipVerify: boolPtr(true)})
13+
if !transport.TLSClientConfig.InsecureSkipVerify {
14+
t.Error("expected InsecureSkipVerify to be true")
15+
}
16+
})
17+
18+
t.Run("unix socket proxy clears Proxy", func(t *testing.T) {
19+
transport := buildTransport(ClientOpts{ProxyPath: "/tmp/test.sock"}, defaultFlags())
20+
if transport.Proxy != nil {
21+
t.Error("expected Proxy to be nil")
22+
}
23+
})
24+
25+
// http.DefaultTransport.Dial / DialTLS is already set and we can't compare two funcs
26+
// so our best effort here is to just check Proxy is nil / not nill based on the ProxyURL
27+
t.Run("http proxy clears Proxy", func(t *testing.T) {
28+
transport := buildTransport(ClientOpts{ProxyURL: &url.URL{Scheme: "http", Host: "proxy:8080"}}, defaultFlags())
29+
if transport.Proxy != nil {
30+
t.Error("expected Proxy to be nil")
31+
}
32+
})
33+
34+
t.Run("socks5 proxy sets Proxy", func(t *testing.T) {
35+
transport := buildTransport(ClientOpts{ProxyURL: &url.URL{Scheme: "socks5", Host: "proxy:1080"}}, defaultFlags())
36+
if transport.Proxy == nil {
37+
t.Error("expected Proxy to be set")
38+
}
39+
})
40+
}

0 commit comments

Comments
 (0)