Skip to content

Commit 94d9653

Browse files
rohanKanojiapraveenkumar
authored andcommitted
test (e2e) : Improve crc version assertion
Improve how to verify crc version output. Instead of just doing a string match. Parse `crc version` JSON output and verify each field. Add a special condition for crc version, if it's not matching but it's an actual date skip it. Signed-off-by: Rohan Kumar <rohaan@redhat.com>
1 parent bc43ae1 commit 94d9653

2 files changed

Lines changed: 36 additions & 10 deletions

File tree

test/e2e/features/basic.feature

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ Feature: Basic test
66

77
@darwin @linux @windows @release
88
Scenario: CRC version
9-
When executing crc version command
10-
Then stdout should contain correct version
9+
Then crc version has expected output
1110

1211
@darwin @linux @windows
1312
Scenario: CRC help

test/e2e/testsuite/testsuite.go

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package testsuite
33
import (
44
"context"
55
"crypto/tls"
6+
"encoding/json"
67
"fmt"
78
"net/http"
89
"os"
@@ -404,8 +405,6 @@ func InitializeScenario(s *godog.ScenarioContext) {
404405
util.CommandReturnShouldNotContain)
405406
s.Step(`^(stdout|stderr|exitcode) (?:should|does not) contain$`,
406407
util.CommandReturnShouldNotContainContent)
407-
s.Step(`^(stdout|stderr|exitcode) (?:should contain|contains) correct version$`,
408-
CommandReturnShouldContainCorrectVersion)
409408

410409
s.Step(`^(stdout|stderr|exitcode) (?:should equal|equals) "(.*)"$`,
411410
util.CommandReturnShouldEqual)
@@ -554,6 +553,8 @@ func InitializeScenario(s *godog.ScenarioContext) {
554553
EnsureMicroshiftClusterIsOperational)
555554
s.Step(`^kubeconfig is cleaned up$`,
556555
EnsureKubeConfigIsCleanedUp)
556+
s.Step(`^crc version has expected output$`,
557+
EnsureCrcVersionIsCorrect)
557558

558559
s.After(func(ctx context.Context, _ *godog.Scenario, err error) (context.Context, error) {
559560

@@ -642,13 +643,39 @@ func CheckOutputMatchWithRetry(retryCount int, retryTime string, command string,
642643
return matchErr
643644
}
644645

645-
func CommandReturnShouldContainCorrectVersion() error {
646-
647-
if CRCVersion == "" {
648-
return util.CommandReturnShouldContain("stdout", "version:")
646+
func EnsureCrcVersionIsCorrect() error {
647+
err := util.ExecuteCommand("crc version -ojson")
648+
if err != nil {
649+
return fmt.Errorf("could not execute 'crc version -ojson' command: %v", err)
649650
}
650-
651-
return util.CommandReturnShouldContain("stdout", CRCVersion)
651+
crcVersionJSONOutput := util.GetLastCommandOutput("stdout")
652+
type CrcVersionOutput struct {
653+
Version string `json:"version"`
654+
Commit string `json:"commit"`
655+
OpenShiftVersion string `json:"openshiftVersion"`
656+
MicroShiftVersion string `json:"microshiftVersion"`
657+
}
658+
var crcVersionOutput CrcVersionOutput
659+
err = json.Unmarshal([]byte(crcVersionJSONOutput), &crcVersionOutput)
660+
if err != nil {
661+
return fmt.Errorf("error in unmarshalling crc version output json: %v", err)
662+
}
663+
if crcVersionOutput.Version != version.GetCRCVersion() {
664+
_, err := time.Parse("06.01.02", crcVersionOutput.Version)
665+
if err != nil {
666+
return fmt.Errorf("crc version doesn't match, expected '%s', actual '%s'", version.GetCRCVersion(), crcVersionOutput.Version)
667+
}
668+
}
669+
if crcVersionOutput.Commit != version.GetCommitSha() {
670+
return fmt.Errorf("crc version commit sha don't match, expected '%s', actual '%s'", version.GetCommitSha(), crcVersionOutput.Commit)
671+
}
672+
if len(crcVersionOutput.OpenShiftVersion) == 0 {
673+
return fmt.Errorf("expected OpenShift version to be set in crc version output")
674+
}
675+
if len(crcVersionOutput.MicroShiftVersion) == 0 {
676+
return fmt.Errorf("expected MicroShift version to be set in crc version output")
677+
}
678+
return nil
652679
}
653680

654681
func CheckCRCStatus(state string) error {

0 commit comments

Comments
 (0)