44 lines
1.3 KiB
Go
44 lines
1.3 KiB
Go
package kitrun
|
|
|
|
import (
|
|
"net"
|
|
"strconv"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/samcharles93/archie-core/internal/infrastructure/egress"
|
|
)
|
|
|
|
// A Kit worker reaches the State Store through its relay, never through the
|
|
// daemon's own target: ordinary image tasks got a per-task relay instead, and
|
|
// this path must not follow them onto it.
|
|
func TestWorkerEnvKeepsRelayAddress(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
env, err := WorkerEnv(Endpoints{
|
|
NATS: "nats://127.0.0.1:4222",
|
|
StateStore: "127.0.0.1:9090",
|
|
StateStoreToken: "task-token",
|
|
StateStoreCA: []byte("ca-pem"),
|
|
}, 0, 0)
|
|
if err != nil {
|
|
t.Fatalf("WorkerEnv: %v", err)
|
|
}
|
|
values := make(map[string]string, len(env))
|
|
for _, entry := range env {
|
|
key, value, _ := strings.Cut(entry, "=")
|
|
values[key] = value
|
|
}
|
|
|
|
want := net.JoinHostPort(egress.RelayAlias, strconv.Itoa(egress.RelayStateStorePort))
|
|
if got := values["STATE_STORE_URL"]; got != want {
|
|
t.Fatalf("STATE_STORE_URL = %q, want the relay address %q", got, want)
|
|
}
|
|
if values["STATE_STORE_TOKEN"] != "task-token" {
|
|
t.Fatalf("STATE_STORE_TOKEN = %q, want the task's own token", values["STATE_STORE_TOKEN"])
|
|
}
|
|
if values["STATE_STORE_CA"] != "ca-pem" {
|
|
t.Fatalf("STATE_STORE_CA = %q, want the CA passed through", values["STATE_STORE_CA"])
|
|
}
|
|
}
|