|
| 1 | +package ghinstance |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | +) |
| 6 | + |
| 7 | +func TestIsEnterprise(t *testing.T) { |
| 8 | + tests := []struct { |
| 9 | + host string |
| 10 | + want bool |
| 11 | + }{ |
| 12 | + { |
| 13 | + host: "github.com", |
| 14 | + want: false, |
| 15 | + }, |
| 16 | + { |
| 17 | + host: "api.github.com", |
| 18 | + want: false, |
| 19 | + }, |
| 20 | + { |
| 21 | + host: "ghe.io", |
| 22 | + want: true, |
| 23 | + }, |
| 24 | + { |
| 25 | + host: "example.com", |
| 26 | + want: true, |
| 27 | + }, |
| 28 | + } |
| 29 | + for _, tt := range tests { |
| 30 | + t.Run(tt.host, func(t *testing.T) { |
| 31 | + if got := IsEnterprise(tt.host); got != tt.want { |
| 32 | + t.Errorf("IsEnterprise() = %v, want %v", got, tt.want) |
| 33 | + } |
| 34 | + }) |
| 35 | + } |
| 36 | +} |
| 37 | + |
| 38 | +func TestNormalizeHostname(t *testing.T) { |
| 39 | + tests := []struct { |
| 40 | + host string |
| 41 | + want string |
| 42 | + }{ |
| 43 | + { |
| 44 | + host: "GitHub.com", |
| 45 | + want: "github.com", |
| 46 | + }, |
| 47 | + { |
| 48 | + host: "api.github.com", |
| 49 | + want: "github.com", |
| 50 | + }, |
| 51 | + { |
| 52 | + host: "ssh.github.com", |
| 53 | + want: "github.com", |
| 54 | + }, |
| 55 | + { |
| 56 | + host: "upload.github.com", |
| 57 | + want: "github.com", |
| 58 | + }, |
| 59 | + { |
| 60 | + host: "GHE.IO", |
| 61 | + want: "ghe.io", |
| 62 | + }, |
| 63 | + { |
| 64 | + host: "git.my.org", |
| 65 | + want: "git.my.org", |
| 66 | + }, |
| 67 | + } |
| 68 | + for _, tt := range tests { |
| 69 | + t.Run(tt.host, func(t *testing.T) { |
| 70 | + if got := NormalizeHostname(tt.host); got != tt.want { |
| 71 | + t.Errorf("NormalizeHostname() = %v, want %v", got, tt.want) |
| 72 | + } |
| 73 | + }) |
| 74 | + } |
| 75 | +} |
| 76 | + |
| 77 | +func TestGraphQLEndpoint(t *testing.T) { |
| 78 | + tests := []struct { |
| 79 | + host string |
| 80 | + want string |
| 81 | + }{ |
| 82 | + { |
| 83 | + host: "github.com", |
| 84 | + want: "https://api.github.com/graphql", |
| 85 | + }, |
| 86 | + { |
| 87 | + host: "ghe.io", |
| 88 | + want: "https://ghe.io/api/graphql", |
| 89 | + }, |
| 90 | + } |
| 91 | + for _, tt := range tests { |
| 92 | + t.Run(tt.host, func(t *testing.T) { |
| 93 | + if got := GraphQLEndpoint(tt.host); got != tt.want { |
| 94 | + t.Errorf("GraphQLEndpoint() = %v, want %v", got, tt.want) |
| 95 | + } |
| 96 | + }) |
| 97 | + } |
| 98 | +} |
| 99 | + |
| 100 | +func TestRESTPrefix(t *testing.T) { |
| 101 | + tests := []struct { |
| 102 | + host string |
| 103 | + want string |
| 104 | + }{ |
| 105 | + { |
| 106 | + host: "github.com", |
| 107 | + want: "https://api.github.com/", |
| 108 | + }, |
| 109 | + { |
| 110 | + host: "ghe.io", |
| 111 | + want: "https://ghe.io/api/v3/", |
| 112 | + }, |
| 113 | + } |
| 114 | + for _, tt := range tests { |
| 115 | + t.Run(tt.host, func(t *testing.T) { |
| 116 | + if got := RESTPrefix(tt.host); got != tt.want { |
| 117 | + t.Errorf("RESTPrefix() = %v, want %v", got, tt.want) |
| 118 | + } |
| 119 | + }) |
| 120 | + } |
| 121 | +} |
0 commit comments