github.com/ActiveState/cli@v0.0.0-20240508170324-6801f60cd051/test/integration/executor_int_test.go (about)

     1  package integration
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  	"testing"
     7  
     8  	"github.com/ActiveState/cli/internal/testhelpers/suite"
     9  
    10  	"github.com/ActiveState/cli/internal/constants"
    11  	"github.com/ActiveState/cli/internal/osutils"
    12  	"github.com/ActiveState/cli/internal/testhelpers/e2e"
    13  	"github.com/ActiveState/cli/internal/testhelpers/tagsuite"
    14  )
    15  
    16  type ExecutorIntegrationTestSuite struct {
    17  	tagsuite.Suite
    18  }
    19  
    20  func TestExecutorIntegrationTestSuite(t *testing.T) {
    21  	suite.Run(t, new(ExecutorIntegrationTestSuite))
    22  }
    23  
    24  func (suite *ExecutorIntegrationTestSuite) TestExecutorForwards() {
    25  	suite.OnlyRunForTags(tagsuite.Executor)
    26  
    27  	ts := e2e.New(suite.T(), false)
    28  	defer ts.Close()
    29  
    30  	cp := ts.SpawnWithOpts(
    31  		e2e.OptArgs("checkout", "ActiveState-CLI/Python3"),
    32  	)
    33  	cp.Expect("Checked out project")
    34  	cp.ExpectExitCode(0)
    35  
    36  	cp = ts.SpawnWithOpts(
    37  		e2e.OptArgs("shell", "ActiveState-CLI/Python3"),
    38  		e2e.OptAppendEnv(constants.DisableRuntime+"=false"),
    39  	)
    40  	cp.Expect("Activated", e2e.RuntimeSourcingTimeoutOpt)
    41  	cp.ExpectInput()
    42  
    43  	cp.SendLine("python3 -c \"import sys; print(sys.copyright)\"")
    44  	cp.Expect("ActiveState Software Inc.")
    45  
    46  	cp.SendLine("exit")
    47  	cp.Expect("Deactivated")
    48  	cp.ExpectExitCode(0)
    49  }
    50  
    51  func (suite *ExecutorIntegrationTestSuite) TestExecutorExitCode() {
    52  	suite.OnlyRunForTags(tagsuite.Executor)
    53  
    54  	ts := e2e.New(suite.T(), false)
    55  	defer ts.Close()
    56  
    57  	cp := ts.SpawnWithOpts(
    58  		e2e.OptArgs("checkout", "ActiveState-CLI/Python3"),
    59  	)
    60  	cp.Expect("Checked out project")
    61  	cp.ExpectExitCode(0)
    62  
    63  	cp = ts.SpawnWithOpts(
    64  		e2e.OptArgs("shell", "ActiveState-CLI/Python3"),
    65  		e2e.OptAppendEnv(constants.DisableRuntime+"=false"),
    66  	)
    67  	cp.Expect("Activated", e2e.RuntimeSourcingTimeoutOpt)
    68  	cp.ExpectInput()
    69  
    70  	cp.SendLine("python3 -c \"exit(42)\"")
    71  
    72  	cp.SendLine("exit")
    73  	cp.ExpectExitCode(42)
    74  }
    75  
    76  func sizeByMegs(megabytes float64) int64 {
    77  	return int64(megabytes * float64(1000000))
    78  }
    79  
    80  func (suite *ExecutorIntegrationTestSuite) TestExecutorSizeOnDisk() {
    81  	suite.OnlyRunForTags(tagsuite.Executor)
    82  
    83  	ts := e2e.New(suite.T(), false)
    84  	defer ts.Close()
    85  
    86  	execFilePath := filepath.Join(ts.Dirs.Bin, constants.StateExecutorCmd+osutils.ExeExtension)
    87  	fi, err := os.Stat(execFilePath)
    88  	suite.Require().NoError(err, "should be able to obtain executor file info")
    89  
    90  	maxSize := sizeByMegs(4)
    91  	suite.Require().LessOrEqual(fi.Size(), maxSize, "executor (%d bytes) should be less than or equal to %d bytes", fi.Size(), maxSize)
    92  }