github.com/ActiveState/cli@v0.0.0-20240508170324-6801f60cd051/test/integration/reset_int_test.go (about) 1 package integration 2 3 import ( 4 "bytes" 5 "path/filepath" 6 "testing" 7 8 "github.com/ActiveState/cli/internal/constants" 9 "github.com/ActiveState/cli/internal/fileutils" 10 "github.com/ActiveState/cli/internal/testhelpers/e2e" 11 "github.com/ActiveState/cli/internal/testhelpers/suite" 12 "github.com/ActiveState/cli/internal/testhelpers/tagsuite" 13 ) 14 15 type ResetIntegrationTestSuite struct { 16 tagsuite.Suite 17 } 18 19 func (suite *ResetIntegrationTestSuite) TestReset() { 20 suite.OnlyRunForTags(tagsuite.Reset) 21 ts := e2e.New(suite.T(), false) 22 defer ts.Close() 23 24 cp := ts.Spawn("checkout", "ActiveState-CLI/Reset#3a2d095d-efd6-4be0-b824-21de94fc4ad6", ".") 25 cp.Expect("Skipping runtime setup") 26 cp.Expect("Checked out") 27 cp.ExpectExitCode(0) 28 29 cp = ts.Spawn("install", "requests") 30 cp.Expect("Package added") 31 cp.ExpectExitCode(0) 32 33 cp = ts.Spawn("history") 34 cp.Expect("requests") 35 cp.ExpectExitCode(0) 36 37 cp = ts.Spawn("reset") 38 cp.Expect("Your project will be reset to 3a2d095d-efd6-4be0-b824-21de94fc4ad6") 39 cp.Expect("Are you sure") 40 cp.Expect("(y/N)") 41 cp.SendLine("y") 42 cp.Expect("Successfully reset to commit: 3a2d095d-efd6-4be0-b824-21de94fc4ad6") 43 cp.ExpectExitCode(0) 44 45 cp = ts.Spawn("history") 46 cp.ExpectExitCode(0) 47 suite.Assert().NotContains(cp.Snapshot(), "requests") 48 49 cp = ts.Spawn("reset") 50 cp.Expect("You are already on the latest commit") 51 cp.ExpectNotExitCode(0) 52 53 cp = ts.Spawn("reset", "00000000-0000-0000-0000-000000000000") 54 cp.Expect("The given commit ID does not exist") 55 cp.ExpectNotExitCode(0) 56 } 57 58 func (suite *ResetIntegrationTestSuite) TestJSON() { 59 suite.OnlyRunForTags(tagsuite.Reset, tagsuite.JSON) 60 ts := e2e.New(suite.T(), false) 61 defer ts.Close() 62 63 cp := ts.Spawn("checkout", "ActiveState-CLI/Branches#46c83477-d580-43e2-a0c6-f5d3677517f1", ".") 64 cp.Expect("Skipping runtime setup") 65 cp.Expect("Checked out") 66 cp.ExpectExitCode(0) 67 68 cp = ts.Spawn("reset", "35af7414-b44b-4fd7-aa93-2ecad337ed2b", "-o", "json") 69 cp.Expect(`{"commitID":"35af7414-b44b-4fd7-aa93-2ecad337ed2b"}`) 70 cp.ExpectExitCode(0) 71 } 72 73 func (suite *ResetIntegrationTestSuite) TestRevertInvalidURL() { 74 suite.OnlyRunForTags(tagsuite.Reset) 75 ts := e2e.New(suite.T(), false) 76 defer ts.Close() 77 78 commitID := "3a2d095d-efd6-4be0-b824-21de94fc4ad6" 79 80 cp := ts.Spawn("checkout", "ActiveState-CLI/Reset#"+commitID, ".") 81 cp.Expect("Skipping runtime setup") 82 cp.Expect("Checked out") 83 cp.ExpectExitCode(0) 84 85 contents := fileutils.ReadFileUnsafe(filepath.Join(ts.Dirs.Work, constants.ConfigFileName)) 86 contents = bytes.Replace(contents, []byte("3a2d095d-efd6-4be0-b824-21de94fc4ad6"), []byte(""), 1) 87 err := fileutils.WriteFile(filepath.Join(ts.Dirs.Work, constants.ConfigFileName), contents) 88 suite.Require().NoError(err) 89 90 cp = ts.Spawn("install", "requests") 91 cp.Expect("invalid commit ID") 92 cp.Expect("Please run 'state reset' to fix it.") 93 cp.ExpectNotExitCode(0) 94 95 cp = ts.Spawn("reset", "-n") 96 cp.Expect("Successfully reset to commit: " + commitID) 97 cp.ExpectExitCode(0) 98 } 99 100 func TestResetIntegrationTestSuite(t *testing.T) { 101 suite.Run(t, new(ResetIntegrationTestSuite)) 102 }