github.com/ActiveState/cli@v0.0.0-20240508170324-6801f60cd051/internal/testhelpers/suite/suite.go (about)

     1  package suite
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/ActiveState/cli/internal/errs"
     8  	"github.com/stretchr/testify/require"
     9  	testify "github.com/stretchr/testify/suite"
    10  )
    11  
    12  type tSuite interface {
    13  	testify.TestingSuite
    14  	IsHelperSuite() bool
    15  }
    16  
    17  type Suite struct {
    18  	testify.Suite
    19  }
    20  
    21  func (suite *Suite) NoError(err error, msgAndArgs ...interface{}) {
    22  	if err == nil {
    23  		return
    24  	}
    25  
    26  	suite.Fail(fmt.Sprintf("Received unexpected error:\n%+v", errs.JoinMessage(err)), msgAndArgs...)
    27  }
    28  
    29  func (suite *Suite) Require() *Assertions {
    30  	return &Assertions{suite.Suite.Require()}
    31  }
    32  
    33  func (suite *Suite) IsHelperSuite() bool {
    34  	return true
    35  }
    36  
    37  type Assertions struct {
    38  	*require.Assertions
    39  }
    40  
    41  func (a *Assertions) NoError(err error, msgAndArgs ...interface{}) {
    42  	if err == nil {
    43  		return
    44  	}
    45  
    46  	a.Fail(fmt.Sprintf("Received unexpected error:\n%+v", errs.JoinMessage(err)), msgAndArgs...)
    47  }
    48  
    49  func Run(t *testing.T, suite tSuite) {
    50  	testify.Run(t, suite)
    51  }