(t *testing.T)
| 162 | } |
| 163 | |
| 164 | func TestNormalizeExternalURL(t *testing.T) { |
| 165 | tests := []struct { |
| 166 | url string |
| 167 | want string |
| 168 | wantErr bool |
| 169 | }{ |
| 170 | { |
| 171 | url: "http://localhost:3000", |
| 172 | want: "http://localhost:3000", |
| 173 | wantErr: false, |
| 174 | }, |
| 175 | { |
| 176 | url: "https://localhost:3000", |
| 177 | want: "https://localhost:3000", |
| 178 | wantErr: false, |
| 179 | }, |
| 180 | { |
| 181 | url: "https://localhost", |
| 182 | want: "https://localhost", |
| 183 | wantErr: false, |
| 184 | }, |
| 185 | { |
| 186 | url: "http://localhost:80", |
| 187 | want: "http://localhost", |
| 188 | wantErr: false, |
| 189 | }, |
| 190 | { |
| 191 | url: "https://localhost:443", |
| 192 | want: "https://localhost", |
| 193 | wantErr: false, |
| 194 | }, |
| 195 | { |
| 196 | url: " https://localhost:3000/ ", |
| 197 | want: "https://localhost:3000", |
| 198 | wantErr: false, |
| 199 | }, |
| 200 | // Missing http:// or https:// |
| 201 | { |
| 202 | url: "localhost:3000", |
| 203 | want: "", |
| 204 | wantErr: true, |
| 205 | }, |
| 206 | // Invalid port |
| 207 | { |
| 208 | url: "http://localhost:xxx", |
| 209 | want: "", |
| 210 | wantErr: true, |
| 211 | }, |
| 212 | } |
| 213 | for _, tt := range tests { |
| 214 | t.Run(tt.url, func(t *testing.T) { |
| 215 | g, err := NormalizeExternalURL(tt.url) |
| 216 | if err != nil { |
| 217 | if !tt.wantErr { |
| 218 | t.Errorf("expect no error, got %s", err.Error()) |
| 219 | } |
| 220 | } else { |
| 221 | if tt.wantErr { |
nothing calls this directly
no test coverage detected