69 lines
1.7 KiB
Go
69 lines
1.7 KiB
Go
package nsc
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
)
|
|
|
|
func TestNormalizeMacOSNSCMachineTypeRoundsUp(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
got, changed, err := normalizeMacOSNSCMachineType("5x10")
|
|
if err != nil {
|
|
t.Fatalf("normalizeMacOSNSCMachineType: %v", err)
|
|
}
|
|
if !changed {
|
|
t.Fatal("expected machine type to be normalized")
|
|
}
|
|
if got != "6x14" {
|
|
t.Fatalf("expected 6x14, got %q", got)
|
|
}
|
|
}
|
|
|
|
func TestNormalizeMacOSNSCMachineTypeKeepsAllowedShape(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
got, changed, err := normalizeMacOSNSCMachineType("6x14")
|
|
if err != nil {
|
|
t.Fatalf("normalizeMacOSNSCMachineType: %v", err)
|
|
}
|
|
if changed {
|
|
t.Fatal("expected allowed machine type to remain unchanged")
|
|
}
|
|
if got != "6x14" {
|
|
t.Fatalf("expected 6x14, got %q", got)
|
|
}
|
|
}
|
|
|
|
func TestShouldFallbackToNSCSSHFallbackForComputeAuthErrors(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
err := errors.New("compute get ssh config failed: unauthenticated: invalid tenant credentials")
|
|
if !shouldFallbackToNSCSSH(err) {
|
|
t.Fatal("expected compute auth error to fall back to nsc ssh")
|
|
}
|
|
}
|
|
|
|
func TestShouldFallbackToNSCSSHRejectsOtherErrors(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
err := errors.New("compute ssh runner bootstrap failed: exit status 1")
|
|
if shouldFallbackToNSCSSH(err) {
|
|
t.Fatal("expected unrelated bootstrap errors to remain fatal")
|
|
}
|
|
}
|
|
|
|
func TestNSCSSHBootstrapLikelySucceeded(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
err := errors.New("wait: remote command exited without exit status or exit signal")
|
|
output := `
|
|
level=info msg="Runner registered successfully."
|
|
time="2026-03-19T11:29:49Z" level=info msg="Starting job"
|
|
time="2026-03-19T11:29:50Z" level=info msg="task 124 repo is hackclub/burrow"
|
|
`
|
|
|
|
if !nscSSHBootstrapLikelySucceeded(err, output) {
|
|
t.Fatal("expected handoff success heuristic to match")
|
|
}
|
|
}
|