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

     1  package integration
     2  
     3  import (
     4  	"strings"
     5  	"testing"
     6  
     7  	"github.com/ActiveState/cli/internal/testhelpers/e2e"
     8  	"github.com/ActiveState/cli/internal/testhelpers/suite"
     9  	"github.com/ActiveState/cli/internal/testhelpers/tagsuite"
    10  )
    11  
    12  type ScriptsIntegrationTestSuite struct {
    13  	tagsuite.Suite
    14  }
    15  
    16  func (suite *ScriptsIntegrationTestSuite) setupConfigFile(ts *e2e.Session) {
    17  	configFileContent := strings.TrimSpace(`
    18  project: "https://platform.activestate.com/ScriptOrg/ScriptProject"
    19  scripts:
    20    - name: first-script
    21      value: echo "first script"
    22      if: ne .OS.Name "Windows"
    23    - name: first-script
    24      value: echo first script
    25      if: eq .OS.Name "Windows"
    26    - name: second-script
    27      value: print("second script")
    28      language: python3
    29    - name: super-script
    30      language: bash
    31      value: |
    32        $scripts.first-script.path._posix()
    33    - name: testenv
    34      language: bash
    35      value: echo $I_SHOULD_EXIST
    36  `)
    37  
    38  	ts.PrepareActiveStateYAML(configFileContent)
    39  }
    40  
    41  func (suite *ScriptsIntegrationTestSuite) TestRunInheritEnv() {
    42  	suite.OnlyRunForTags(tagsuite.Scripts)
    43  	ts := e2e.New(suite.T(), false)
    44  	suite.setupConfigFile(ts)
    45  
    46  	cp := ts.SpawnWithOpts(e2e.OptArgs("run", "testenv"), e2e.OptAppendEnv("I_SHOULD_EXIST=I_SURE_DO_EXIST"))
    47  	cp.Expect("I_SURE_DO_EXIST")
    48  	cp.ExpectExitCode(0)
    49  }
    50  
    51  func (suite *ScriptsIntegrationTestSuite) TestRunSubscripts() {
    52  	suite.OnlyRunForTags(tagsuite.Scripts)
    53  	ts := e2e.New(suite.T(), false)
    54  	suite.setupConfigFile(ts)
    55  
    56  	cp := ts.Spawn("run", "super-script")
    57  	cp.Expect("first script")
    58  	cp.ExpectExitCode(0)
    59  }
    60  
    61  func TestScriptsIntegrationTestSuite(t *testing.T) {
    62  	suite.Run(t, new(ScriptsIntegrationTestSuite))
    63  }