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

     1  package integration
     2  
     3  import (
     4  	"path/filepath"
     5  	"strings"
     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/fileutils"
    12  	"github.com/ActiveState/cli/internal/testhelpers/e2e"
    13  	"github.com/ActiveState/cli/internal/testhelpers/tagsuite"
    14  )
    15  
    16  type ShowIntegrationTestSuite struct {
    17  	tagsuite.Suite
    18  }
    19  
    20  func (suite *ShowIntegrationTestSuite) TestShow() {
    21  	suite.OnlyRunForTags(tagsuite.Show)
    22  	ts := e2e.New(suite.T(), false)
    23  	defer ts.Close()
    24  
    25  	suite.PrepareProject(ts)
    26  
    27  	cp := ts.SpawnWithOpts(
    28  		e2e.OptArgs("activate"),
    29  		e2e.OptAppendEnv(constants.DisableRuntime+"=false"),
    30  	)
    31  	cp.ExpectInput(e2e.RuntimeSourcingTimeoutOpt)
    32  
    33  	cp = ts.Spawn("show")
    34  	cp.Expect(`Name`)
    35  	cp.Expect(`Show`)
    36  	cp.Expect(`Organization`)
    37  	cp.Expect(`cli-integration-tests`)
    38  	cp.Expect(`Namespace`)
    39  	cp.Expect(`cli-integration-tests/Show`)
    40  	cp.Expect(`Location`)
    41  	cp.Expect(ts.Dirs.Work)
    42  	cp.Expect(`Executables`)
    43  	cp.Expect(ts.Dirs.Cache)
    44  	cp.Expect(`Visibility`)
    45  	cp.Expect(`Public`)
    46  	cp.Expect(`Latest Commit`)
    47  	cp.Expect(`d5d84598-fc2e-4a45-b075-a845e587b5bf`)
    48  	cp.Expect(`Events`)
    49  	cp.Expect(`• FIRST_INSTALL`)
    50  	cp.Expect(`• AFTER_UPDATE`)
    51  	cp.Expect(`Scripts`)
    52  	cp.Expect(`• debug`)
    53  	cp.Expect(`Platforms`)
    54  	cp.Expect(`CentOS`)
    55  	cp.Expect(`Languages`)
    56  	cp.Expect(`python`)
    57  	cp.Expect(`3.6.6`)
    58  	cp.ExpectExitCode(0)
    59  }
    60  
    61  func (suite *ShowIntegrationTestSuite) TestShowWithoutBranch() {
    62  	suite.OnlyRunForTags(tagsuite.Show, tagsuite.Critical)
    63  	ts := e2e.New(suite.T(), false)
    64  	defer ts.Close()
    65  
    66  	ts.PrepareProject("cli-integration-tests/Show", "e8f3b07b-502f-4763-83c1-763b9b952e18")
    67  
    68  	cp := ts.SpawnWithOpts(e2e.OptArgs("show"))
    69  	cp.ExpectExitCode(0)
    70  
    71  	contents, err := fileutils.ReadFile(filepath.Join(ts.Dirs.Work, constants.ConfigFileName))
    72  	suite.Require().NoError(err)
    73  
    74  	suite.Contains(string(contents), "branch="+constants.DefaultBranchName)
    75  }
    76  
    77  func (suite *ShowIntegrationTestSuite) PrepareProject(ts *e2e.Session) {
    78  	asyData := strings.TrimSpace(`
    79  project: "https://platform.activestate.com/cli-integration-tests/Show?branch=main"
    80  constants:
    81    - name: DEBUG
    82      value: true
    83    - name: PYTHONPATH
    84      value: '%projectDir%/src:%projectDir%/tests'
    85    - name: PYTHONPATH
    86      value: '%projectDir%/src:%projectDir%/tests'
    87  events:
    88    - name: FIRST_INSTALL
    89      value: '%pythonExe% %projectDir%/setup.py prepare'
    90    - name: AFTER_UPDATE
    91      value: '%pythonExe% %projectDir%/setup.py prepare'
    92  scripts:
    93    - name: tests
    94      value: pytest %projectDir%/tests
    95    - name: debug
    96      value: debug foo
    97  `)
    98  
    99  	ts.PrepareActiveStateYAML(asyData)
   100  	ts.PrepareCommitIdFile("d5d84598-fc2e-4a45-b075-a845e587b5bf")
   101  }
   102  
   103  func (suite *ShowIntegrationTestSuite) TestJSON() {
   104  	suite.OnlyRunForTags(tagsuite.Show, tagsuite.JSON)
   105  	ts := e2e.New(suite.T(), false)
   106  	defer ts.Close()
   107  
   108  	cp := ts.Spawn("checkout", "ActiveState-CLI/small-python", ".")
   109  	cp.Expect("Skipping runtime setup")
   110  	cp.Expect("Checked out")
   111  	cp.ExpectExitCode(0)
   112  
   113  	cp = ts.Spawn("show", "-o", "json")
   114  	cp.Expect(`"project_url":`)
   115  	cp.Expect(`"name":`)
   116  	cp.Expect(`"platforms":`)
   117  	cp.Expect(`"languages":`)
   118  	cp.Expect(`"secrets":`)
   119  	cp.Expect(`"events":`)
   120  	cp.Expect(`"scripts":`)
   121  	cp.ExpectExitCode(0)
   122  	AssertValidJSON(suite.T(), cp)
   123  }
   124  
   125  func TestShowIntegrationTestSuite(t *testing.T) {
   126  	suite.Run(t, new(ShowIntegrationTestSuite))
   127  }