|
| 1 | +package model |
| 2 | + |
| 3 | +import "testing" |
| 4 | + |
| 5 | +func TestPublicURL(t *testing.T) { |
| 6 | + originalProtocol := Protocol |
| 7 | + originalHost := ExternalHost |
| 8 | + originalBasePath := ExternalBasePath |
| 9 | + t.Cleanup(func() { |
| 10 | + Protocol = originalProtocol |
| 11 | + ExternalHost = originalHost |
| 12 | + ExternalBasePath = originalBasePath |
| 13 | + }) |
| 14 | + |
| 15 | + Protocol = "https" |
| 16 | + ExternalHost = "example.com" |
| 17 | + ExternalBasePath = "/aggregator" |
| 18 | + |
| 19 | + got := PublicURL("/registration") |
| 20 | + want := "https://example.com/aggregator/registration" |
| 21 | + if got != want { |
| 22 | + t.Fatalf("expected %q, got %q", want, got) |
| 23 | + } |
| 24 | +} |
| 25 | + |
| 26 | +func TestPublicURLNoBasePath(t *testing.T) { |
| 27 | + originalProtocol := Protocol |
| 28 | + originalHost := ExternalHost |
| 29 | + originalBasePath := ExternalBasePath |
| 30 | + t.Cleanup(func() { |
| 31 | + Protocol = originalProtocol |
| 32 | + ExternalHost = originalHost |
| 33 | + ExternalBasePath = originalBasePath |
| 34 | + }) |
| 35 | + |
| 36 | + Protocol = "https" |
| 37 | + ExternalHost = "example.com" |
| 38 | + ExternalBasePath = "" |
| 39 | + |
| 40 | + got := PublicURL("registration") |
| 41 | + want := "https://example.com/registration" |
| 42 | + if got != want { |
| 43 | + t.Fatalf("expected %q, got %q", want, got) |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +func TestPublicBaseURL(t *testing.T) { |
| 48 | + originalProtocol := Protocol |
| 49 | + originalHost := ExternalHost |
| 50 | + originalBasePath := ExternalBasePath |
| 51 | + t.Cleanup(func() { |
| 52 | + Protocol = originalProtocol |
| 53 | + ExternalHost = originalHost |
| 54 | + ExternalBasePath = originalBasePath |
| 55 | + }) |
| 56 | + |
| 57 | + Protocol = "https" |
| 58 | + ExternalHost = "example.com" |
| 59 | + ExternalBasePath = "/aggregator/" |
| 60 | + |
| 61 | + got := PublicBaseURL() |
| 62 | + want := "https://example.com/aggregator" |
| 63 | + if got != want { |
| 64 | + t.Fatalf("expected %q, got %q", want, got) |
| 65 | + } |
| 66 | +} |
0 commit comments