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

     1  package integration
     2  
     3  import (
     4  	"path/filepath"
     5  	"testing"
     6  	"time"
     7  
     8  	"github.com/ActiveState/cli/internal/constants"
     9  	"github.com/ActiveState/cli/internal/testhelpers/e2e"
    10  	"github.com/ActiveState/cli/internal/testhelpers/suite"
    11  	"github.com/ActiveState/cli/internal/testhelpers/tagsuite"
    12  	"github.com/ActiveState/termtest"
    13  )
    14  
    15  type ExportIntegrationTestSuite struct {
    16  	tagsuite.Suite
    17  }
    18  
    19  func (suite *ExportIntegrationTestSuite) TestExport_ConfigDir() {
    20  	suite.OnlyRunForTags(tagsuite.Export)
    21  	ts := e2e.New(suite.T(), false)
    22  	defer ts.Close()
    23  
    24  	ts.PrepareProject("cli-integration-tests/Export", e2e.CommitIDNotChecked)
    25  	cp := ts.Spawn("export", "config", "--filter", "junk")
    26  	cp.ExpectExitCode(1)
    27  	ts.IgnoreLogErrors()
    28  }
    29  
    30  func (suite *ExportIntegrationTestSuite) TestExport_Config() {
    31  	suite.OnlyRunForTags(tagsuite.Export)
    32  	ts := e2e.New(suite.T(), false)
    33  	defer ts.Close()
    34  
    35  	ts.PrepareProject("cli-integration-tests/Export", e2e.CommitIDNotChecked)
    36  	cp := ts.Spawn("export", "config")
    37  	cp.Expect(`dir: `)
    38  	cp.Expect(ts.Dirs.Config, termtest.OptExpectTimeout(time.Second))
    39  	cp.ExpectExitCode(0)
    40  }
    41  
    42  func (suite *ExportIntegrationTestSuite) TestExport_Env() {
    43  	suite.OnlyRunForTags(tagsuite.Export)
    44  	ts := e2e.New(suite.T(), false)
    45  	defer ts.Close()
    46  
    47  	ts.PrepareProject("ActiveState-CLI/Export", "5397f645-da8a-4591-b106-9d7fa99545fe")
    48  	cp := ts.SpawnWithOpts(
    49  		e2e.OptArgs("export", "env"),
    50  		e2e.OptAppendEnv(constants.DisableRuntime+"=false"),
    51  	)
    52  	cp.Expect(`PATH: `, e2e.RuntimeSourcingTimeoutOpt)
    53  	cp.ExpectExitCode(0)
    54  
    55  	suite.Assert().NotContains(cp.Output(), "ACTIVESTATE_ACTIVATED")
    56  }
    57  
    58  func (suite *ExportIntegrationTestSuite) TestLog() {
    59  	suite.OnlyRunForTags(tagsuite.Export)
    60  	ts := e2e.New(suite.T(), false)
    61  	defer ts.ClearCache()
    62  
    63  	cp := ts.Spawn("export", "log")
    64  	cp.Expect(filepath.Join(ts.Dirs.Config, "logs"))
    65  	cp.ExpectRe(`state-\d+`)
    66  	cp.Expect(".log")
    67  	cp.ExpectExitCode(0)
    68  
    69  	cp = ts.Spawn("export", "log", "state-svc")
    70  	cp.Expect(filepath.Join(ts.Dirs.Config, "logs"))
    71  	cp.ExpectRe(`state-svc-\d+`)
    72  	cp.Expect(".log")
    73  	cp.ExpectExitCode(0)
    74  }
    75  
    76  func (suite *ExportIntegrationTestSuite) TestJSON() {
    77  	suite.OnlyRunForTags(tagsuite.Export, tagsuite.JSON)
    78  	ts := e2e.New(suite.T(), false)
    79  	defer ts.Close()
    80  
    81  	cp := ts.Spawn("export", "config", "-o", "json")
    82  	cp.Expect(`{"dir":`)
    83  	cp.ExpectExitCode(0)
    84  	AssertValidJSON(suite.T(), cp)
    85  
    86  	cp = ts.SpawnWithOpts(
    87  		e2e.OptArgs("checkout", "ActiveState-CLI/small-python", "."),
    88  		e2e.OptAppendEnv(constants.DisableRuntime+"=false"),
    89  	)
    90  	cp.ExpectExitCode(0, e2e.RuntimeSourcingTimeoutOpt)
    91  
    92  	cp = ts.SpawnWithOpts(
    93  		e2e.OptArgs("export", "env", "-o", "json"),
    94  		e2e.OptAppendEnv(constants.DisableRuntime+"=false"),
    95  	)
    96  	cp.ExpectExitCode(0, e2e.RuntimeSourcingTimeoutOpt)
    97  	AssertValidJSON(suite.T(), cp)
    98  
    99  	ts.LoginAsPersistentUser()
   100  	cp = ts.Spawn("export", "jwt", "-o", "json")
   101  	cp.Expect(`{"value":`)
   102  	cp.ExpectExitCode(0)
   103  	AssertValidJSON(suite.T(), cp)
   104  
   105  	cp = ts.Spawn("export", "log", "-o", "json")
   106  	cp.Expect(`{"logFile":"`)
   107  	cp.Expect(`.log"}`)
   108  	cp.ExpectExitCode(0)
   109  	AssertValidJSON(suite.T(), cp)
   110  }
   111  
   112  func TestExportIntegrationTestSuite(t *testing.T) {
   113  	suite.Run(t, new(ExportIntegrationTestSuite))
   114  }