MCPcopy Create free account
hub / github.com/conforma/cli / CLIVersion

Function CLIVersion

acceptance/testenv/testenv.go:261–287  ·  view source on GitHub ↗

CLIVersion returns the version of the CLI, useful for matching in snapshots

(ctx context.Context)

Source from the content-addressed store, hash-verified

259
260// CLIVersion returns the version of the CLI, useful for matching in snapshots
261func 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
289type testUtil struct {
290 tempDir string

Callers 2

setupCliVersionFunction · 0.92

Calls 1

RunMethod · 0.65

Tested by

no test coverage detected