CLIVersion returns the version of the CLI, useful for matching in snapshots
(ctx context.Context)
| 259 | |
| 260 | // CLIVersion returns the version of the CLI, useful for matching in snapshots |
| 261 | func CLIVersion(ctx context.Context) (string, error) { |
| 262 | // For individual test runs, we need to ensure the version is always fresh |
| 263 | // Check if we're in a test context and if the version needs to be refreshed |
| 264 | if !versionInitialized || ecVersion == "undefined" { |
| 265 | ec := path.Join("dist", fmt.Sprintf("ec_%s_%s", runtime.GOOS, runtime.GOARCH)) |
| 266 | |
| 267 | cmd := exec.CommandContext(ctx, ec, "version", "--json") |
| 268 | var stdout bytes.Buffer |
| 269 | cmd.Stdout = &stdout |
| 270 | |
| 271 | if ecVersionErr = cmd.Run(); ecVersionErr != nil { |
| 272 | return ecVersion, ecVersionErr |
| 273 | } |
| 274 | |
| 275 | ver := struct { |
| 276 | Version string |
| 277 | }{} |
| 278 | if err := json.Unmarshal(stdout.Bytes(), &ver); err != nil { |
| 279 | panic(err) |
| 280 | } |
| 281 | |
| 282 | ecVersion = ver.Version |
| 283 | versionInitialized = true |
| 284 | } |
| 285 | |
| 286 | return ecVersion, ecVersionErr |
| 287 | } |
| 288 | |
| 289 | type testUtil struct { |
| 290 | tempDir string |
no test coverage detected