MCPcopy Index your code
hub / github.com/google/go-github / Test_parseURL

Function Test_parseURL

github/url_test.go:13–74  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func Test_parseURL(t *testing.T) {
14 t.Parallel()
15
16 for _, tt := range []struct {
17 name string
18 input string
19 want string
20 wantErr string
21 }{
22 {
23 name: "empty_string_returns_error",
24 input: "",
25 wantErr: "url cannot be empty",
26 },
27 {
28 name: "invalid_url_returns_error",
29 input: "://invalid-url\n",
30 wantErr: "invalid url",
31 },
32 {
33 name: "valid_url",
34 input: "https://api.github.com/",
35 want: "https://api.github.com/",
36 },
37 {
38 name: "valid_url_without_trailing_slash_adds_slash",
39 input: "https://api.github.com",
40 want: "https://api.github.com/",
41 },
42 } {
43 t.Run(tt.name, func(t *testing.T) {
44 t.Parallel()
45
46 got, err := parseURL(tt.input)
47 if err != nil {
48 if tt.wantErr == "" {
49 t.Fatalf("unexpected error: %v", err)
50 }
51
52 if !strings.Contains(err.Error(), tt.wantErr) {
53 t.Fatalf("expected error to contain %v, got %v", tt.wantErr, err.Error())
54 }
55
56 return
57 }
58
59 if tt.wantErr != "" {
60 t.Fatalf("expected error to contain %v, got nil", tt.wantErr)
61 return
62 }
63
64 if got == nil {
65 t.Fatal("expected non-nil URL, got nil")
66 return
67 }
68
69 if got.String() != tt.want {
70 t.Fatalf("expected URL %v, got %v", tt.want, got.String())

Callers

nothing calls this directly

Calls 4

parseURLFunction · 0.85
RunMethod · 0.45
ErrorMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…