-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathcommit_int_test.go
More file actions
170 lines (134 loc) · 5.67 KB
/
commit_int_test.go
File metadata and controls
170 lines (134 loc) · 5.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
package integration
import (
"bytes"
"path/filepath"
"testing"
"time"
"github.com/ActiveState/cli/internal/constants"
"github.com/ActiveState/cli/internal/fileutils"
buildscript_runbit "github.com/ActiveState/cli/internal/runbits/buildscript"
"github.com/ActiveState/cli/internal/testhelpers/e2e"
"github.com/ActiveState/cli/internal/testhelpers/suite"
"github.com/ActiveState/cli/internal/testhelpers/tagsuite"
"github.com/ActiveState/cli/pkg/platform/model"
"github.com/ActiveState/cli/pkg/project"
"github.com/ActiveState/termtest"
)
type CommitIntegrationTestSuite struct {
tagsuite.Suite
}
func (suite *CommitIntegrationTestSuite) TestCommitManualBuildScriptMod() {
suite.OnlyRunForTags(tagsuite.Commit, tagsuite.BuildScripts)
ts := e2e.New(suite.T(), false)
defer ts.Close()
ts.PrepareProjectAndBuildScript("ActiveState-CLI/Commit-Test-A", "7a1b416e-c17f-4d4a-9e27-cbad9e8f5655")
proj, err := project.FromPath(ts.Dirs.Work)
suite.NoError(err, "Error loading project")
_, err = buildscript_runbit.ScriptFromProject(proj)
suite.Require().NoError(err) // verify validity
cp := ts.Spawn("commit")
cp.Expect("no new changes")
cp.ExpectExitCode(0)
_, err = buildscript_runbit.ScriptFromProject(proj)
suite.Require().NoError(err) // verify validity
scriptPath := filepath.Join(ts.Dirs.Work, constants.BuildScriptFileName)
data := fileutils.ReadFileUnsafe(scriptPath)
data = bytes.ReplaceAll(data, []byte("casestyle"), []byte("case"))
suite.Require().NoError(fileutils.WriteFile(scriptPath, data), "Update buildscript")
ts.LoginAsPersistentUser() // for CVE reporting
cp = ts.Spawn("commit")
cp.Expect("Operating on project")
cp.Expect("Creating commit")
cp.Expect("Resolving Dependencies")
cp.Expect("Installing case@")
cp.Expect("Checking for vulnerabilities")
cp.Expect("successfully created")
cp.ExpectExitCode(0)
cp = ts.Spawn("pkg")
cp.Expect("case ", e2e.RuntimeSourcingTimeoutOpt) // note: intentional trailing whitespace to not match 'casestyle'
cp.ExpectExitCode(0)
}
func (suite *CommitIntegrationTestSuite) TestCommitAtTimeChange() {
suite.OnlyRunForTags(tagsuite.Commit, tagsuite.BuildScripts)
ts := e2e.New(suite.T(), false)
defer ts.Close()
ts.PrepareProjectAndBuildScript("ActiveState-CLI/Commit-Test-A", "2ab50eba-4410-4be2-ba9d-c04ebeda640d")
proj, err := project.FromPath(ts.Dirs.Work)
suite.NoError(err, "Error loading project")
_, err = buildscript_runbit.ScriptFromProject(proj)
suite.Require().NoError(err) // verify validity
// Update top-level at_time variable.
dateTime := "2025-12-11T12:34:56Z"
buildScriptFile := filepath.Join(proj.Dir(), constants.BuildScriptFileName)
contents, err := fileutils.ReadFile(buildScriptFile)
suite.Require().NoError(err)
contents = bytes.Replace(contents, []byte("2025-12-10T17:03:26Z"), []byte(dateTime), 1)
suite.Require().NoError(fileutils.WriteFile(buildScriptFile, contents))
suite.Require().Contains(string(fileutils.ReadFileUnsafe(filepath.Join(proj.Dir(), constants.BuildScriptFileName))), dateTime)
cp := ts.Spawn("commit")
cp.Expect("successfully created", termtest.OptExpectErrorMessage(string(contents)))
cp.ExpectExitCode(0)
cp = ts.Spawn("history")
cp.Expect("Revision")
revisionTime, err := time.Parse(time.RFC3339, dateTime)
suite.Require().NoError(err)
cp.Expect(revisionTime.Format(time.RFC822))
cp.ExpectExitCode(0)
}
func (suite *CommitIntegrationTestSuite) TestCommitTimestampNow() {
ts, err := model.FetchLatestRevisionTimeStamp(nil)
suite.Require().NoError(err)
suite.testCommitTimestamp("now", ts)
}
func (suite *CommitIntegrationTestSuite) TestCommitTimestampPresent() {
ts, err := model.FetchLatestTimeStamp(nil)
suite.Require().NoError(err)
suite.testCommitTimestamp("present", ts)
}
func (suite *CommitIntegrationTestSuite) TestCommitTimestampCustom() {
ts, err := time.Parse(time.RFC3339, "2025-06-21T12:34:56Z")
suite.Require().NoError(err)
suite.testCommitTimestamp("2025-06-21T12:34:56Z", ts)
}
func (suite *CommitIntegrationTestSuite) testCommitTimestamp(input string, expected time.Time) {
suite.OnlyRunForTags(tagsuite.Commit, tagsuite.BuildScripts)
ts := e2e.New(suite.T(), true)
defer ts.Close()
ts.PrepareProjectAndBuildScript("ActiveState-CLI/Commit-Test-A", "7a1b416e-c17f-4d4a-9e27-cbad9e8f5655")
proj, err := project.FromPath(ts.Dirs.Work)
suite.NoError(err, "Error loading project")
_, err = buildscript_runbit.ScriptFromProject(proj)
suite.Require().NoError(err) // verify validity
cp := ts.Spawn("commit", "--ts", input)
cp.Expect("successfully created")
cp.ExpectExitCode(0)
cp = ts.Spawn("history")
cp.Expect("Revision")
// Assert time.RFC822 minus the timezone because Go seems to parse this inconsistently
// ie. I'm getting +0000 instead of a named timezone
cp.Expect(expected.Format("02 Jan 06 15:04"))
cp.ExpectExitCode(0)
}
func (suite *CommitIntegrationTestSuite) TestCommitSkipValidation() {
suite.OnlyRunForTags(tagsuite.Commit, tagsuite.BuildScripts)
ts := e2e.New(suite.T(), false)
defer ts.Close()
ts.PrepareProjectAndBuildScript("ActiveState-CLI/Commit-Test-A", "7a1b416e-c17f-4d4a-9e27-cbad9e8f5655")
scriptPath := filepath.Join(ts.Dirs.Work, constants.BuildScriptFileName)
data := fileutils.ReadFileUnsafe(scriptPath)
data = bytes.Replace(data, []byte("solver_version = null"), []byte("solver_version = 999"), 1)
suite.Require().NoError(fileutils.WriteFile(scriptPath, data))
cp := ts.Spawn("commit")
cp.Expect("solver_version")
cp.Expect("should be")
cp.ExpectExitCode(1)
cp = ts.Spawn("commit", "--skip-validation")
cp.ExpectExitCode(0)
cp = ts.Spawn("refresh")
cp.Expect("solver_version")
cp.Expect("should be")
cp.ExpectExitCode(1)
}
func TestCommitIntegrationTestSuite(t *testing.T) {
suite.Run(t, new(CommitIntegrationTestSuite))
}