@@ -3,6 +3,7 @@ package testsuite
33import (
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
654681func CheckCRCStatus (state string ) error {
0 commit comments