| 1 |
// Copyright 2026 The NATS Authors |
| 2 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 |
// you may not use this file except in compliance with the License. |
| 4 |
// You may obtain a copy of the License at |
| 5 |
// |
| 6 |
// http://www.apache.org/licenses/LICENSE-2.0 |
| 7 |
// |
| 8 |
// Unless required by applicable law or agreed to in writing, software |
| 9 |
// distributed under the License is distributed on an "AS IS" BASIS, |
| 10 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 |
// See the License for the specific language governing permissions and |
| 12 |
// limitations under the License. |
| 13 |
|
| 14 |
package test |
| 15 |
|
| 16 |
import ( |
| 17 |
"context" |
| 18 |
"fmt" |
| 19 |
"os" |
| 20 |
"testing" |
| 21 |
|
| 22 |
"github.com/synadia-io/orbit.go/ntf" |
| 23 |
) |
| 24 |
|
| 25 |
// Keep in sync with the copies in test and micro/test. |
| 26 |
func TestMain(m *testing.M) { |
| 27 |
testerURL = os.Getenv("TESTER_NATS_URL") |
| 28 |
if testerURL == "" { |
| 29 |
// CI must use the pinned synadia/ntf-server image, which ships its own |
| 30 |
// nats-server build. |
| 31 |
if os.Getenv("GITHUB_ACTIONS") != "" { |
| 32 |
fmt.Fprintln(os.Stderr, "TESTER_NATS_URL must be set in CI; refusing to fall back to the in-process tester") |
| 33 |
os.Exit(1) |
| 34 |
} |
| 35 |
// ntf's embedded server binds the wildcard address, so ClientURL reports |
| 36 |
// 0.0.0.0 — neither reachable nor a SAN on the certs it generates. Pin |
| 37 |
// both this URL and what managed servers advertise to localhost. |
| 38 |
svc, err := ntf.New(context.Background(), ntf.Options{AdvertiseHost: "localhost"}) |
| 39 |
if err != nil { |
| 40 |
fmt.Fprintln(os.Stderr, "could not start the in-process tester:", err) |
| 41 |
os.Exit(1) |
| 42 |
} |
| 43 |
defer svc.Close() |
| 44 |
testerURL = fmt.Sprintf("nats://localhost:%d", svc.Port()) |
| 45 |
} |
| 46 |
m.Run() |
| 47 |
} |