-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathinit_int_test.go
More file actions
155 lines (130 loc) · 4.73 KB
/
init_int_test.go
File metadata and controls
155 lines (130 loc) · 4.73 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
package integration
import (
"fmt"
"io/ioutil"
"path/filepath"
"runtime"
"testing"
"github.com/ActiveState/cli/internal/assets"
"github.com/ActiveState/cli/internal/constants"
"github.com/ActiveState/cli/internal/fileutils"
"github.com/ActiveState/cli/internal/language"
"github.com/ActiveState/cli/internal/strutils"
"github.com/ActiveState/cli/internal/testhelpers/e2e"
"github.com/ActiveState/cli/internal/testhelpers/tagsuite"
"github.com/stretchr/testify/suite"
)
type InitIntegrationTestSuite struct {
tagsuite.Suite
}
func (suite *InitIntegrationTestSuite) TestInit() {
suite.OnlyRunForTags(tagsuite.Init, tagsuite.Critical)
suite.runInitTest(false, "python", "python3")
}
func (suite *InitIntegrationTestSuite) TestInit_Path() {
suite.OnlyRunForTags(tagsuite.Init)
suite.runInitTest(true, "python", "python3")
}
func (suite *InitIntegrationTestSuite) TestInit_BadVersion() {
suite.OnlyRunForTags(tagsuite.Init)
ts := e2e.New(suite.T(), false)
defer ts.Close()
ts.LoginAsPersistentUser()
cp := ts.Spawn("init", "--language", "python@1.0", "test-user/test-project")
cp.Expect("version")
cp.Expect("cannot be found")
cp.ExpectNotExitCode(0)
}
func (suite *InitIntegrationTestSuite) TestInit_DisambiguatePython() {
suite.OnlyRunForTags(tagsuite.Init)
suite.runInitTest(false, "python", "python3")
suite.runInitTest(false, "python@3.10.0", "python3")
suite.runInitTest(false, "python@2.7.18", "python2")
}
func (suite *InitIntegrationTestSuite) TestInit_PartialVersions() {
suite.OnlyRunForTags(tagsuite.Init)
suite.runInitTest(false, "python@3.10", "python3")
suite.runInitTest(false, "python@2", "python2")
}
func (suite *InitIntegrationTestSuite) runInitTest(addPath bool, lang string, expectedConfigLanguage string, args ...string) {
ts := e2e.New(suite.T(), false)
defer ts.Close()
ts.LoginAsPersistentUser()
// Generate a new namespace for the project to be created.
pname := strutils.UUID()
namespace := fmt.Sprintf("%s/%s", e2e.PersistentUsername, pname)
computedArgs := append([]string{"init", "--language", lang, namespace}, args...)
if addPath {
computedArgs = append(computedArgs, ts.Dirs.Work)
}
// Run `state init`, creating the project.
cp := ts.Spawn(computedArgs...)
cp.Expect("Skipping runtime setup")
cp.ExpectLongString(fmt.Sprintf("Project '%s' has been successfully initialized", namespace))
cp.ExpectExitCode(0)
ts.NotifyProjectCreated(e2e.PersistentUsername, pname.String())
// Verify the config template contains the correct shell, language, and content.
configFilepath := filepath.Join(ts.Dirs.Work, constants.ConfigFileName)
suite.Require().FileExists(configFilepath)
templateFile, err := assets.ReadFile("activestate.yaml.python.tpl")
if err != nil {
panic(err.Error())
}
shell := "bash"
if runtime.GOOS == "windows" {
shell = "batch"
}
yaml, err := strutils.ParseTemplate(
string(templateFile),
map[string]interface{}{
"Owner": e2e.PersistentUsername,
"Project": pname.String(),
"Shell": shell,
"Language": expectedConfigLanguage,
"LangExe": language.MakeByName(expectedConfigLanguage).Executable().Filename(),
}, nil)
content, err := ioutil.ReadFile(configFilepath)
suite.Require().NoError(err)
suite.Contains(string(content), yaml)
}
func (suite *InitIntegrationTestSuite) TestInit_NoLanguage() {
suite.OnlyRunForTags(tagsuite.Init)
ts := e2e.New(suite.T(), false)
defer ts.Close()
cp := ts.Spawn("init", "test-user/test-project")
cp.ExpectNotExitCode(0)
}
func (suite *InitIntegrationTestSuite) TestInit_InferLanguageFromUse() {
suite.OnlyRunForTags(tagsuite.Init)
ts := e2e.New(suite.T(), false)
defer ts.Close()
ts.LoginAsPersistentUser()
cp := ts.Spawn("checkout", "ActiveState-CLI/Python3")
cp.Expect("Skipping runtime setup")
cp.Expect("Checked out project")
cp.ExpectExitCode(0)
cp = ts.SpawnWithOpts(
e2e.WithArgs("use", "Python3"),
e2e.AppendEnv("ACTIVESTATE_CLI_DISABLE_RUNTIME=false"),
)
cp.Expect("Switched to project")
cp.ExpectExitCode(0)
pname := strutils.UUID()
namespace := fmt.Sprintf("%s/%s", e2e.PersistentUsername, pname)
cp = ts.Spawn("init", namespace)
cp.Expect("Skipping runtime setup")
cp.Expect("successfully initialized")
cp.ExpectExitCode(0)
ts.NotifyProjectCreated(e2e.PersistentUsername, pname.String())
suite.Contains(string(fileutils.ReadFileUnsafe(filepath.Join(ts.Dirs.Work, constants.ConfigFileName))), "language: python3")
}
func (suite *InitIntegrationTestSuite) TestInit_NotAuthenticated() {
suite.OnlyRunForTags(tagsuite.Init)
ts := e2e.New(suite.T(), false)
defer ts.Close()
cp := ts.Spawn("init", "test-user/test-project", "python3")
cp.ExpectLongString("You need to be authenticated to initialize a project.")
}
func TestInitIntegrationTestSuite(t *testing.T) {
suite.Run(t, new(InitIntegrationTestSuite))
}