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

     1  package integration
     2  
     3  import (
     4  	"path/filepath"
     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  	"github.com/ActiveState/termtest"
    11  )
    12  
    13  type HistoryIntegrationTestSuite struct {
    14  	tagsuite.Suite
    15  }
    16  
    17  func (suite *HistoryIntegrationTestSuite) TestHistory_History() {
    18  	suite.OnlyRunForTags(tagsuite.History)
    19  	ts := e2e.New(suite.T(), false)
    20  	defer ts.Close()
    21  
    22  	ts.LoginAsPersistentUser()
    23  
    24  	cp := ts.Spawn("checkout", "ActiveState-CLI/History")
    25  	cp.Expect("Skipping runtime setup")
    26  	cp.Expect("Checked out")
    27  	cp.ExpectExitCode(0)
    28  
    29  	cp = ts.SpawnWithOpts(
    30  		e2e.OptArgs("history"),
    31  		e2e.OptWD(filepath.Join(ts.Dirs.Work, "History")),
    32  	)
    33  	cp.Expect("Operating on project")
    34  	cp.Expect("ActiveState-CLI/History")
    35  	cp.Expect("Commit")
    36  	cp.Expect("Author")
    37  	cp.Expect("Date")
    38  	cp.Expect("Revision")
    39  	cp.Expect("Message")
    40  	cp.Expect("• requests (2.26.0 → 2.7.0)")
    41  	cp.Expect("namespace: language/python")
    42  	cp.Expect("• autopip (1.6.0 → Auto)")
    43  	cp.Expect("+ autopip 1.6.0")
    44  	cp.SetLogger(termtest.VerboseLogger)
    45  	cp.Expect("- convertdate")
    46  	cp.Expect("namespace: language/python")
    47  	cp.SetLogger(termtest.VoidLogger)
    48  	cp.Expect(`+ Platform`)
    49  	cp.Expect("namespace: platform")
    50  	suite.Assert().NotContains(cp.Output(), "StructuredChanges")
    51  	cp.ExpectExitCode(0)
    52  }
    53  
    54  func (suite *HistoryIntegrationTestSuite) TestJSON() {
    55  	suite.OnlyRunForTags(tagsuite.History)
    56  	ts := e2e.New(suite.T(), false)
    57  	defer ts.Close()
    58  
    59  	cp := ts.Spawn("checkout", "ActiveState-CLI/History", ".")
    60  	cp.Expect("Skipping runtime setup")
    61  	cp.Expect("Checked out")
    62  	cp.ExpectExitCode(0)
    63  
    64  	cp = ts.Spawn("history", "-o", "json")
    65  	cp.Expect(`[{"hash":`)
    66  	cp.Expect(`"changes":[{`)
    67  	cp.Expect(`"operation":"updated"`)
    68  	cp.Expect(`"requirement":`)
    69  	cp.Expect(`"version_constraints_old":`)
    70  	cp.Expect(`"version_constraints_new":`)
    71  	cp.Expect(`"namespace":`)
    72  	cp.ExpectExitCode(0)
    73  	// AssertValidJSON(suite.T(), cp) // list is too large to fit in terminal snapshot
    74  }
    75  
    76  func TestHistoryIntegrationTestSuite(t *testing.T) {
    77  	suite.Run(t, new(HistoryIntegrationTestSuite))
    78  }