github.com/smartcontractkit/chainlink-testing-framework/libs@v0.0.0-20240227141906-ec710b4eb1a3/gauntlet/gauntlet_test.go (about)

     1  package gauntlet_test
     2  
     3  import (
     4  	"os"
     5  	"testing"
     6  
     7  	gauntlet "github.com/smartcontractkit/chainlink-testing-framework/libs/gauntlet"
     8  	"github.com/smartcontractkit/chainlink-testing-framework/libs/logging"
     9  
    10  	"github.com/stretchr/testify/require"
    11  )
    12  
    13  func TestMain(m *testing.M) {
    14  	logging.Init()
    15  	os.Exit(m.Run())
    16  }
    17  
    18  func TestNewGauntletStruct(t *testing.T) {
    19  	t.Parallel()
    20  	g, err := gauntlet.NewGauntlet()
    21  	require.NoError(t, err, "Error getting new Gauntlet struct")
    22  	require.Contains(t, g.Network, "test", "Network did not contain a test")
    23  }
    24  
    25  func TestProperlyFormattedFlag(t *testing.T) {
    26  	t.Parallel()
    27  	g, err := gauntlet.NewGauntlet()
    28  	require.NoError(t, err, "Error getting new Gauntlet struct")
    29  	require.Equal(t, "--flag=value", g.Flag("flag", "value"))
    30  }
    31  
    32  func TestExecuteCommand(t *testing.T) {
    33  	t.Parallel()
    34  	g, err := gauntlet.NewGauntlet()
    35  	require.NoError(t, err, "Error getting new Gauntlet struct")
    36  
    37  	options := gauntlet.ExecCommandOptions{
    38  		ErrHandling:       []string{},
    39  		CheckErrorsInRead: true,
    40  	}
    41  	out, err := g.ExecCommand([]string{}, options)
    42  
    43  	require.Error(t, err, "The command should technically always fail because we don't have access to a gauntlet"+
    44  		"executable, if it passed without error then we have an issue")
    45  	require.Contains(t, out, "yarn", "Did not contain expected output")
    46  }
    47  
    48  func TestExpectedError(t *testing.T) {
    49  	t.Parallel()
    50  	g, err := gauntlet.NewGauntlet()
    51  	require.NoError(t, err, "Error getting new Gauntlet struct")
    52  
    53  	options := gauntlet.ExecCommandOptions{
    54  		ErrHandling: []string{"yarn"},
    55  		RetryCount:  1,
    56  	}
    57  	_, err = g.ExecCommandWithRetries([]string{}, options)
    58  	require.Error(t, err, "Failed to find the expected error")
    59  }