57 lines
1.8 KiB
Go
57 lines
1.8 KiB
Go
package windsurf
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
)
|
|
|
|
func TestRuntimeOS_DefaultIsLinux(t *testing.T) {
|
|
// t.Setenv unsets after the test, and a nil env var makes RuntimeOS()
|
|
// fall back to DefaultRuntimeOS. Setting to "" has the same effect.
|
|
t.Setenv("WINDSURF_METADATA_OS", "")
|
|
if got := RuntimeOS(); got != "linux" {
|
|
t.Errorf("default RuntimeOS = %q, want %q", got, "linux")
|
|
}
|
|
}
|
|
|
|
func TestRuntimeOS_EnvOverride(t *testing.T) {
|
|
t.Setenv("WINDSURF_METADATA_OS", "darwin")
|
|
if got := RuntimeOS(); got != "darwin" {
|
|
t.Errorf("env-overridden RuntimeOS = %q, want %q", got, "darwin")
|
|
}
|
|
}
|
|
|
|
func TestHardwareArch_DefaultIsX86_64(t *testing.T) {
|
|
t.Setenv("WINDSURF_METADATA_ARCH", "")
|
|
if got := HardwareArch(); got != "x86_64" {
|
|
t.Errorf("default HardwareArch = %q, want %q", got, "x86_64")
|
|
}
|
|
}
|
|
|
|
func TestHardwareArch_EnvOverride(t *testing.T) {
|
|
t.Setenv("WINDSURF_METADATA_ARCH", "arm64")
|
|
if got := HardwareArch(); got != "arm64" {
|
|
t.Errorf("env-overridden HardwareArch = %q, want %q", got, "arm64")
|
|
}
|
|
}
|
|
|
|
// TestBuildMetadata_UsesOverriddenValues confirms that buildMetadata reads
|
|
// RuntimeOS() / HardwareArch() at call time, not at package init, so
|
|
// switching the env per-test actually flows through to the wire format.
|
|
func TestBuildMetadata_UsesOverriddenValues(t *testing.T) {
|
|
t.Setenv("WINDSURF_METADATA_OS", "darwin")
|
|
t.Setenv("WINDSURF_METADATA_ARCH", "arm64")
|
|
|
|
meta := buildMetadata("test-token", "test-session-id")
|
|
|
|
if !bytes.Contains(meta, []byte("darwin")) {
|
|
t.Errorf("expected meta to contain overridden OS %q, got %q", "darwin", meta)
|
|
}
|
|
if !bytes.Contains(meta, []byte("arm64")) {
|
|
t.Errorf("expected meta to contain overridden arch %q, got %q", "arm64", meta)
|
|
}
|
|
if bytes.Contains(meta, []byte("linux")) || bytes.Contains(meta, []byte("x86_64")) {
|
|
t.Errorf("meta should not contain default values when env is set, got %q", meta)
|
|
}
|
|
}
|