| 1 | package relay_test |
| 2 | |
| 3 | // This file, alone in the package, is relay_test (an EXTERNAL test |
| 4 | // package) rather than relay: it asserts that BuildConfig's value is safe |
| 5 | // to materialize into an EnvironmentFile, which means importing |
| 6 | // internal/appconfig for ValidVarValue — and internal/appconfig imports |
| 7 | // internal/relay for real since Task 12 (configack.go, relaySuffixesFromRelayVar). |
| 8 | // An INTERNAL relay test importing appconfig would close relay -> |
| 9 | // appconfig -> relay, which go vet refuses; this package, built separately |
| 10 | // from both, does not. |
| 11 | |
| 12 | import ( |
| 13 | "crypto/sha256" |
| 14 | "testing" |
| 15 | |
| 16 | "github.com/carlosframework/platform/internal/appconfig" |
| 17 | "github.com/carlosframework/platform/internal/relay" |
| 18 | ) |
| 19 | |
| 20 | func TestBuildConfigValueIsEnvSafe(t *testing.T) { |
| 21 | m := sha256.Sum256([]byte("carlos-relay-test-master")) |
| 22 | r := &relay.Record{Enabled: true, Incarnation: "0123456789abcdef", Regions: []string{"eu-west-1"}} |
| 23 | urls := func(region string) []string { |
| 24 | h := "relay." + region + ".oncarlos.com:3478" |
| 25 | return []string{"stun:" + h, "turn:" + h + "?transport=udp", "turn:" + h + "?transport=tcp"} |
| 26 | } |
| 27 | val, _, err := relay.BuildConfig("abc", "meet", r, []relay.RegionMaster{{Region: "eu-west-1", Kid: "k1", Master: m[:]}}, urls) |
| 28 | if err != nil { |
| 29 | t.Fatal(err) |
| 30 | } |
| 31 | if err := appconfig.ValidVarValue(val); err != nil { |
| 32 | t.Fatalf("BuildConfig's value is not env-safe: %v", err) |
| 33 | } |
| 34 | } |
| 35 | |