(t *testing.T)
| 127 | } |
| 128 | |
| 129 | func TestNewVersionCommand_OnlyGoVersionSet(t *testing.T) { |
| 130 | origVersion := Version |
| 131 | origBuildGoVersion := BuildGoVersion |
| 132 | origBuildTime := BuildTime |
| 133 | defer func() { |
| 134 | Version = origVersion |
| 135 | BuildGoVersion = origBuildGoVersion |
| 136 | BuildTime = origBuildTime |
| 137 | }() |
| 138 | |
| 139 | Version = "" |
| 140 | BuildGoVersion = "go1.21.0" |
| 141 | BuildTime = "" |
| 142 | |
| 143 | cmd := NewVersionCommand() |
| 144 | |
| 145 | old := os.Stdout |
| 146 | r, w, _ := os.Pipe() |
| 147 | os.Stdout = w |
| 148 | |
| 149 | cmd.Run(cmd, []string{}) |
| 150 | |
| 151 | w.Close() |
| 152 | os.Stdout = old |
| 153 | |
| 154 | var buf bytes.Buffer |
| 155 | buf.ReadFrom(r) |
| 156 | output := buf.String() |
| 157 | |
| 158 | assert.Contains(t, output, "GoVersion: go1.21.0") |
| 159 | assert.NotContains(t, output, "BuildTime:") |
| 160 | // Verify there's no standalone "Version:" line |
| 161 | for _, line := range strings.Split(output, "\n") { |
| 162 | assert.False(t, strings.HasPrefix(line, "Version:"), |
| 163 | "should not have a Version: line, got: %q", line) |
| 164 | } |
| 165 | } |
nothing calls this directly
no test coverage detected