(t *testing.T)
| 20 | } |
| 21 | |
| 22 | func TestNewVersionCommand_AllFieldsSet(t *testing.T) { |
| 23 | // Save and restore original values |
| 24 | origVersion := Version |
| 25 | origBuildGoVersion := BuildGoVersion |
| 26 | origBuildTime := BuildTime |
| 27 | defer func() { |
| 28 | Version = origVersion |
| 29 | BuildGoVersion = origBuildGoVersion |
| 30 | BuildTime = origBuildTime |
| 31 | }() |
| 32 | |
| 33 | Version = "1.2.3" |
| 34 | BuildGoVersion = "go1.25.0" |
| 35 | BuildTime = "2024-01-01" |
| 36 | |
| 37 | cmd := NewVersionCommand() |
| 38 | |
| 39 | // Capture stdout |
| 40 | old := os.Stdout |
| 41 | r, w, _ := os.Pipe() |
| 42 | os.Stdout = w |
| 43 | |
| 44 | cmd.Run(cmd, []string{}) |
| 45 | |
| 46 | w.Close() |
| 47 | os.Stdout = old |
| 48 | |
| 49 | var buf bytes.Buffer |
| 50 | buf.ReadFrom(r) |
| 51 | output := buf.String() |
| 52 | |
| 53 | assert.Contains(t, output, "Version: 1.2.3") |
| 54 | assert.Contains(t, output, "GoVersion: go1.25.0") |
| 55 | assert.Contains(t, output, "BuildTime: 2024-01-01") |
| 56 | } |
| 57 | |
| 58 | func TestNewVersionCommand_EmptyFields(t *testing.T) { |
| 59 | // Save and restore original values |
nothing calls this directly
no test coverage detected