github.com/filecoin-project/bacalhau@v0.3.23-0.20230228154132-45c989550ace/cmd/bacalhau/validate_test.go (about)

     1  //go:build unit || !integration
     2  
     3  package bacalhau
     4  
     5  import (
     6  	"fmt"
     7  	"testing"
     8  
     9  	testutils "github.com/filecoin-project/bacalhau/pkg/test/utils"
    10  	"github.com/stretchr/testify/require"
    11  	"github.com/stretchr/testify/suite"
    12  )
    13  
    14  type ValidateSuite struct {
    15  	BaseSuite
    16  }
    17  
    18  func TestValidateSuite(t *testing.T) {
    19  	suite.Run(t, new(ValidateSuite))
    20  }
    21  
    22  func (s *ValidateSuite) TestValidate() {
    23  
    24  	tests := map[string]struct {
    25  		testFile string
    26  		valid    bool
    27  	}{
    28  		"validJobFile":   {testFile: "../../testdata/job-noop.yaml", valid: true},
    29  		"InvalidJobFile": {testFile: "../../testdata/job-noop-invalid.yml", valid: false},
    30  	}
    31  	for name, test := range tests {
    32  		func() {
    33  			Fatal = FakeFatalErrorHandler
    34  
    35  			_, out, err := ExecuteTestCobraCommand(s.T(), "validate",
    36  				"--api-host", s.host,
    37  				"--api-port", s.port,
    38  				test.testFile,
    39  			)
    40  
    41  			require.NoError(s.T(), err)
    42  
    43  			// fmt.Print(s)
    44  			if test.valid {
    45  				require.Contains(s.T(), out, "The Job is valid", fmt.Sprintf("%s: Jobspec Invalid", name))
    46  			} else {
    47  				fatalError, err := testutils.FirstFatalError(s.T(), out)
    48  				require.NoError(s.T(), err)
    49  				require.Contains(s.T(), fatalError.Message, "The Job is not valid.", fmt.Sprintf("%s: Jobspec Invalid returning valid", name))
    50  				require.Contains(s.T(), fatalError.Message, "APIVersion is required", fmt.Sprintf("%s: Jobspec Invalid returning valid", name))
    51  			}
    52  		}()
    53  
    54  	}
    55  }