| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- package main
- import (
- "flag"
- "strings"
- "testing"
- "time"
- )
- func TestParseHthctlArgsFileAfterCommand(t *testing.T) {
- fs := flag.NewFlagSet("hthctl-test", flag.ContinueOnError)
- file := fs.String("file", "", "")
- timeout := fs.Duration("timeout", 0, "")
- cmd := parseHthctlArgs(fs, []string{"--timeout", "30s", "resume-from-safe", "--file", "/tmp/resume.json"})
- if cmd != "resume-from-safe" {
- t.Fatalf("cmd=%q", cmd)
- }
- if *file != "/tmp/resume.json" {
- t.Fatalf("file after subcommand not parsed: %q", *file)
- }
- if *timeout != 30*time.Second {
- t.Fatalf("timeout=%v", *timeout)
- }
- }
- func TestRequireActionFile(t *testing.T) {
- for _, cmd := range []string{"validate-action", "apply-action", "resume-from-safe"} {
- if err := requireActionFile(cmd, ""); err == nil {
- t.Fatalf("%s without --file must fail", cmd)
- }
- if err := requireActionFile(cmd, "batch.json"); err != nil {
- t.Fatal(err)
- }
- }
- if err := requireActionFile("snapshot", ""); err != nil {
- t.Fatal(err)
- }
- }
- func TestSerialBackendAtTmpStillRequiresAck(t *testing.T) {
- observe := "/tmp/hth-real/observe.sock"
- if !backendRequiresHardwareAck("serial") {
- t.Fatal("serial backend must require hardware ack regardless of socket path")
- }
- if backendRequiresHardwareAck("mock") {
- t.Fatal("mock does not require hardware ack")
- }
- if err := refuseIfSerialNeedsAck("serial", observe, false); err == nil {
- t.Fatal("serial on /tmp without --i-understand-this-is-real-hardware must fail")
- } else if !strings.Contains(err.Error(), "serial") {
- t.Fatalf("error should mention serial: %v", err)
- }
- if err := refuseIfSerialNeedsAck("serial", observe, true); err != nil {
- t.Fatal(err)
- }
- if err := refuseIfSerialNeedsAck("mock", "/run/hth/observe.sock", false); err != nil {
- t.Fatal(err)
- }
- if strings.Contains(strings.ToLower(observe), "mock") {
- t.Fatal("test fixture must not rely on mock substring")
- }
- }
|