github.com/filecoin-project/bacalhau@v0.3.23-0.20230228154132-45c989550ace/cmd/bacalhau/version_test.go (about) 1 //go:build unit || !integration 2 3 /* 4 Copyright 2020 The Kubernetes Authors. 5 Licensed under the Apache License, Version 2.0 (the "License"); 6 you may not use this file except in compliance with the License. 7 You may obtain a copy of the License at 8 http://www.apache.org/licenses/LICENSE-2.0 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 */ 15 16 package bacalhau 17 18 import ( 19 "testing" 20 21 "github.com/filecoin-project/bacalhau/pkg/model" 22 "github.com/stretchr/testify/require" 23 "github.com/stretchr/testify/suite" 24 ) 25 26 // In order for 'go test' to run this suite, we need to create 27 // a normal test function and pass our suite to suite.Run 28 func TestVersionSuite(t *testing.T) { 29 suite.Run(t, new(VersionSuite)) 30 } 31 32 type VersionSuite struct { 33 BaseSuite 34 } 35 36 func (suite *VersionSuite) Test_Version() { 37 _, out, err := ExecuteTestCobraCommand(suite.T(), "version", 38 "--api-host", suite.host, 39 "--api-port", suite.port, 40 ) 41 require.NoError(suite.T(), err) 42 43 require.Contains(suite.T(), string(out), "Client Version", "Client version not in output") 44 require.Contains(suite.T(), string(out), "Server Version", "Server version not in output") 45 } 46 47 func (suite *VersionSuite) Test_VersionOutputs() { 48 _, out, err := ExecuteTestCobraCommand(suite.T(), "version", 49 "--api-host", suite.host, 50 "--api-port", suite.port, 51 "--output", JSONFormat, 52 ) 53 require.NoError(suite.T(), err, "Could not request version with json output.") 54 55 jsonDoc := &Versions{} 56 err = model.JSONUnmarshalWithMax([]byte(out), &jsonDoc) 57 require.NoError(suite.T(), err, "Could not unmarshall the output into json - %+v", err) 58 require.Equal(suite.T(), jsonDoc.ClientVersion.GitCommit, jsonDoc.ServerVersion.GitCommit, "Client and Server do not match in json.") 59 60 _, out, err = ExecuteTestCobraCommand(suite.T(), "version", 61 "--api-host", suite.host, 62 "--api-port", suite.port, 63 "--output", YAMLFormat, 64 ) 65 require.NoError(suite.T(), err, "Could not request version with json output.") 66 67 yamlDoc := &Versions{} 68 err = model.YAMLUnmarshalWithMax([]byte(out), &yamlDoc) 69 require.NoError(suite.T(), err, "Could not unmarshall the output into yaml - %+v", err) 70 require.Equal(suite.T(), yamlDoc.ClientVersion.GitCommit, yamlDoc.ServerVersion.GitCommit, "Client and Server do not match in yaml.") 71 72 }