|
| 1 | +package commands_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/githubnext/apm/internal/commands" |
| 7 | +) |
| 8 | + |
| 9 | +// TestParityCommandContextFields verifies field parity with Python CommandContext. |
| 10 | +func TestParityCommandContextFields(t *testing.T) { |
| 11 | + ctx := commands.NewCommandContext() |
| 12 | + if ctx.Verbose { |
| 13 | + t.Fatal("expected Verbose=false") |
| 14 | + } |
| 15 | + if ctx.Global { |
| 16 | + t.Fatal("expected Global=false") |
| 17 | + } |
| 18 | + if ctx.DryRun { |
| 19 | + t.Fatal("expected DryRun=false") |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | +// TestParityCommandContextConfigPath verifies ConfigPath field. |
| 24 | +func TestParityCommandContextConfigPath(t *testing.T) { |
| 25 | + ctx := &commands.CommandContext{ConfigPath: "/tmp/apm.yml"} |
| 26 | + if ctx.ConfigPath != "/tmp/apm.yml" { |
| 27 | + t.Fatalf("unexpected ConfigPath: %s", ctx.ConfigPath) |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +// TestParityCommandResultSuccess verifies IsSuccess. |
| 32 | +func TestParityCommandResultSuccess(t *testing.T) { |
| 33 | + r := &commands.CommandResult{ExitCode: 0} |
| 34 | + if !r.IsSuccess() { |
| 35 | + t.Fatal("expected IsSuccess for exit code 0") |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +// TestParityCommandResultFailure verifies failure detection. |
| 40 | +func TestParityCommandResultFailure(t *testing.T) { |
| 41 | + r := &commands.CommandResult{ExitCode: 1, Error: "something failed"} |
| 42 | + if r.IsSuccess() { |
| 43 | + t.Fatal("expected !IsSuccess for exit code 1") |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +// TestParityCommandResultOutput verifies Output field. |
| 48 | +func TestParityCommandResultOutput(t *testing.T) { |
| 49 | + r := &commands.CommandResult{ExitCode: 0, Output: "[+] Done"} |
| 50 | + if r.Output != "[+] Done" { |
| 51 | + t.Fatalf("unexpected output: %s", r.Output) |
| 52 | + } |
| 53 | +} |
| 54 | + |
| 55 | +// TestParityNewCommandContextDefaults verifies zero values. |
| 56 | +func TestParityNewCommandContextDefaults(t *testing.T) { |
| 57 | + ctx := commands.NewCommandContext() |
| 58 | + if ctx == nil { |
| 59 | + t.Fatal("NewCommandContext returned nil") |
| 60 | + } |
| 61 | + if ctx.ConfigPath != "" { |
| 62 | + t.Fatalf("expected empty ConfigPath, got %s", ctx.ConfigPath) |
| 63 | + } |
| 64 | +} |
| 65 | + |
| 66 | +// TestParityCommandContextVerboseFlag verifies setting verbose. |
| 67 | +func TestParityCommandContextVerboseFlag(t *testing.T) { |
| 68 | + ctx := commands.NewCommandContext() |
| 69 | + ctx.Verbose = true |
| 70 | + if !ctx.Verbose { |
| 71 | + t.Fatal("expected Verbose=true after set") |
| 72 | + } |
| 73 | +} |
| 74 | + |
| 75 | +// TestParityCommandContextDryRunFlag verifies DryRun field. |
| 76 | +func TestParityCommandContextDryRunFlag(t *testing.T) { |
| 77 | + ctx := &commands.CommandContext{DryRun: true} |
| 78 | + if !ctx.DryRun { |
| 79 | + t.Fatal("expected DryRun=true") |
| 80 | + } |
| 81 | +} |
| 82 | + |
| 83 | +// TestParityCommandContextGlobalFlag verifies Global field. |
| 84 | +func TestParityCommandContextGlobalFlag(t *testing.T) { |
| 85 | + ctx := &commands.CommandContext{Global: true} |
| 86 | + if !ctx.Global { |
| 87 | + t.Fatal("expected Global=true") |
| 88 | + } |
| 89 | +} |
| 90 | + |
| 91 | +// TestParityCommandResultErrorField verifies Error field. |
| 92 | +func TestParityCommandResultErrorField(t *testing.T) { |
| 93 | + r := &commands.CommandResult{ExitCode: 2, Error: "permission denied"} |
| 94 | + if r.Error != "permission denied" { |
| 95 | + t.Fatalf("unexpected error: %s", r.Error) |
| 96 | + } |
| 97 | +} |
| 98 | + |
| 99 | +// TestParityCommandResultExitCode verifies exit code field. |
| 100 | +func TestParityCommandResultExitCode(t *testing.T) { |
| 101 | + r := &commands.CommandResult{ExitCode: 42} |
| 102 | + if r.ExitCode != 42 { |
| 103 | + t.Fatalf("unexpected exit code: %d", r.ExitCode) |
| 104 | + } |
| 105 | +} |
0 commit comments