Skip to content

Commit

Permalink
Merge pull request #2656 from ActiveState/DX-2041
Browse files Browse the repository at this point in the history
  • Loading branch information
Naatan authored Jul 26, 2023
2 parents 07dc651 + 4dbdc7a commit 21da0b3
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 57 deletions.
2 changes: 1 addition & 1 deletion cmd/state/internal/cmdtree/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func newPublish(prime *primer.Values) *captain.Command {
Name: "namespace",
Description: locale.Tl(
"author_upload_namespace_description",
"The namespace of the ingredient. Defaults to <orgname>/shared. Must start with '<orgname>/'.",
"The namespace of the ingredient. Defaults to org/<orgname>. Must start with 'org/<orgname>'.",
),
Value: &params.Namespace,
},
Expand Down
4 changes: 2 additions & 2 deletions internal/runners/publish/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
auth "github.com/ActiveState/cli/pkg/platform/authentication"
"github.com/ActiveState/cli/pkg/platform/model"
"github.com/ActiveState/cli/pkg/project"
"github.com/machinebox/graphql"
"github.com/ActiveState/graphql"
"github.com/skratchdot/open-golang/open"
"gopkg.in/yaml.v3"
)
Expand Down Expand Up @@ -107,7 +107,7 @@ func (r *Runner) Run(params *Params) error {
if params.Namespace != "" {
reqVars.Namespace = params.Namespace
} else if reqVars.Namespace == "" && r.project != nil && r.project.Owner() != "" {
reqVars.Namespace = model.NewSharedNamespace(r.project.Owner()).String()
reqVars.Namespace = model.NewOrgNamespace(r.project.Owner()).String()
}

// Name
Expand Down
48 changes: 24 additions & 24 deletions internal/testhelpers/e2e/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type Session struct {
createdProjects []*project.Namespaced
// users created during session
users []string
t *testing.T
T *testing.T
Exe string
SvcExe string
ExecutorExe string
Expand Down Expand Up @@ -120,24 +120,24 @@ func (s *Session) CopyExeToDir(from, to string) string {
var err error
to, err = filepath.Abs(filepath.Join(to, filepath.Base(from)))
if err != nil {
s.t.Fatal(err)
s.T.Fatal(err)
}
if fileutils.TargetExists(to) {
return to
}

err = fileutils.CopyFile(from, to)
require.NoError(s.t, err, "Could not copy %s to %s", from, to)
require.NoError(s.T, err, "Could not copy %s to %s", from, to)

// Ensure modTime is the same as source exe
stat, err := os.Stat(from)
require.NoError(s.t, err)
require.NoError(s.T, err)
t := stat.ModTime()
require.NoError(s.t, os.Chtimes(to, t, t))
require.NoError(s.T, os.Chtimes(to, t, t))

permissions, _ := permbits.Stat(to)
permissions.SetUserExecute(true)
require.NoError(s.t, permbits.Chmod(to, permissions))
require.NoError(s.T, permbits.Chmod(to, permissions))
return to
}

Expand Down Expand Up @@ -201,7 +201,7 @@ func new(t *testing.T, retainDirs, updatePath bool, extraEnv ...string) *Session
// add session environment variables
env = append(env, extraEnv...)

session := &Session{Dirs: dirs, Env: env, retainDirs: retainDirs, t: t}
session := &Session{Dirs: dirs, Env: env, retainDirs: retainDirs, T: t}

// Mock installation directory
exe, svcExe, execExe := executablePaths(t)
Expand All @@ -210,7 +210,7 @@ func new(t *testing.T, retainDirs, updatePath bool, extraEnv ...string) *Session
session.ExecutorExe = session.copyExeToBinDir(execExe)

err = fileutils.Touch(filepath.Join(dirs.Base, installation.InstallDirMarker))
require.NoError(session.t, err)
require.NoError(session.T, err)

return session
}
Expand Down Expand Up @@ -281,7 +281,7 @@ func (s *Session) SpawnCmdWithOpts(exe string, opts ...SpawnOptions) *termtest.C
}

console, err := termtest.New(pOpts.Options)
require.NoError(s.t, err)
require.NoError(s.T, err)
if !pOpts.BackgroundProcess {
s.cp = console
}
Expand All @@ -295,7 +295,7 @@ func (s *Session) SpawnCmdWithOpts(exe string, opts ...SpawnOptions) *termtest.C
// provided contents and saves the output to an as.y file within the named
// directory.
func (s *Session) PrepareActiveStateYAML(contents string) {
require.NoError(s.t, fileutils.WriteFile(filepath.Join(s.Dirs.Work, "activestate.yaml"), []byte(contents)))
require.NoError(s.T, fileutils.WriteFile(filepath.Join(s.Dirs.Work, "activestate.yaml"), []byte(contents)))
}

// PrepareFile writes a file to path with contents, expecting no error
Expand All @@ -305,12 +305,12 @@ func (s *Session) PrepareFile(path, contents string) {
contents = strings.TrimSpace(contents)

err := os.MkdirAll(filepath.Dir(path), 0770)
require.NoError(s.t, err, errMsg)
require.NoError(s.T, err, errMsg)

bs := append([]byte(contents), '\n')

err = ioutil.WriteFile(path, bs, 0660)
require.NoError(s.t, err, errMsg)
require.NoError(s.T, err, errMsg)
}

func (s *Session) LoginUser(userName string) {
Expand Down Expand Up @@ -345,7 +345,7 @@ func (s *Session) AddUserToCleanup(username string) {

func (s *Session) CreateNewUser() *mono_models.UserEditable {
uid, err := uuid.NewRandom()
require.NoError(s.t, err)
require.NoError(s.T, err)

username := fmt.Sprintf("user-%s", uid.String()[0:8])
userMeta := &mono_models.UserEditable{
Expand All @@ -359,7 +359,7 @@ func (s *Session) CreateNewUser() *mono_models.UserEditable {
params.SetUser(userMeta)
_, err = mono.New().Users.AddUser(params)

require.NoError(s.t, err)
require.NoError(s.T, err)

p := s.Spawn("auth", "--username", username, "--password", userMeta.Password)
p.ExpectExitCode(0)
Expand Down Expand Up @@ -392,7 +392,7 @@ func observeSendFn(s *Session) func(string, int, error) {
return
}

s.t.Fatalf("Could not send data to terminal\nerror: %v", err)
s.T.Fatalf("Could not send data to terminal\nerror: %v", err)
}
}

Expand Down Expand Up @@ -428,7 +428,7 @@ func (s *Session) DebugMessage(prefix string) string {
"Z": sectionEnd,
}, nil)
if err != nil {
s.t.Fatalf("Parsing template failed: %s", err)
s.T.Fatalf("Parsing template failed: %s", err)
}

return v
Expand All @@ -447,7 +447,7 @@ func observeExpectFn(s *Session) expect.ExpectObserver {
sep = ", "
}

s.t.Fatal(s.DebugMessage(fmt.Sprintf(`
s.T.Fatal(s.DebugMessage(fmt.Sprintf(`
Could not meet expectation: '%s'
Error: %s`, value, err)))
}
Expand All @@ -462,7 +462,7 @@ func (s *Session) Close() error {
}

cfg, err := config.NewCustom(s.Dirs.Config, singlethread.New(), true)
require.NoError(s.t, err, "Could not read e2e session configuration: %s", errs.JoinMessage(err))
require.NoError(s.T, err, "Could not read e2e session configuration: %s", errs.JoinMessage(err))

if !s.retainDirs {
defer s.Dirs.Close()
Expand All @@ -473,7 +473,7 @@ func (s *Session) Close() error {
}

if os.Getenv("PLATFORM_API_TOKEN") == "" {
s.t.Log("PLATFORM_API_TOKEN env var not set, not running suite tear down")
s.T.Log("PLATFORM_API_TOKEN env var not set, not running suite tear down")
return nil
}

Expand Down Expand Up @@ -503,7 +503,7 @@ func (s *Session) Close() error {
if runtime.GOOS == "linux" {
projects, err := getProjects(org, auth)
if err != nil {
s.t.Errorf("Could not fetch projects: %v", errs.JoinMessage(err))
s.T.Errorf("Could not fetch projects: %v", errs.JoinMessage(err))
}
for _, proj := range projects {
if strfmt.IsUUID(proj.Name) {
Expand All @@ -516,14 +516,14 @@ func (s *Session) Close() error {
for _, proj := range s.createdProjects {
err := model.DeleteProject(proj.Owner, proj.Project, auth)
if err != nil {
s.t.Errorf("Could not delete project %s: %v", proj.Project, errs.JoinMessage(err))
s.T.Errorf("Could not delete project %s: %v", proj.Project, errs.JoinMessage(err))
}
}

for _, user := range s.users {
err := cleanUser(s.t, user, auth)
err := cleanUser(s.T, user, auth)
if err != nil {
s.t.Errorf("Could not delete user %s: %v", user, errs.JoinMessage(err))
s.T.Errorf("Could not delete user %s: %v", user, errs.JoinMessage(err))
}
}

Expand Down Expand Up @@ -619,7 +619,7 @@ func (s *Session) DetectLogErrors() {
rx := regexp.MustCompile(`(?:\[ERR:|Panic:)`)
for _, path := range s.LogFiles() {
if contents := string(fileutils.ReadFileUnsafe(path)); rx.MatchString(contents) {
s.t.Errorf("Found error and/or panic in log file %s, contents:\n%s", path, contents)
s.T.Errorf("Found error and/or panic in log file %s, contents:\n%s", path, contents)
}
}
}
Expand Down
26 changes: 12 additions & 14 deletions pkg/platform/model/vcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,8 @@ const (
// NamespaceCamelFlagsMatch is the namespace used for passing camel flags
NamespaceCamelFlagsMatch = `^camel-flags$`

// NamespaceSharedMatch is the namespace used for shared requirements (usually runtime libraries)
NamespaceSharedMatch = `^shared$`

NamespaceOrgSharedMatch = `^\w+\/shared(?$|\/\w+$)`
// NamespaceOrgMatch is the namespace used for org specific requirements
NamespaceOrgMatch = `^org\/`
)

type TrackingType string
Expand Down Expand Up @@ -129,13 +127,13 @@ type NamespaceType struct {
}

var (
NamespacePackage = NamespaceType{"package", "language", NamespacePackageMatch} // these values should match the namespace prefix
NamespaceBundle = NamespaceType{"bundle", "bundles", NamespaceBundlesMatch}
NamespaceLanguage = NamespaceType{"language", "", NamespaceLanguageMatch}
NamespacePlatform = NamespaceType{"platform", "", NamespacePlatformMatch}
NamespaceOrgShared = NamespaceType{"org-shared", "", NamespaceOrgSharedMatch}
NamespaceRaw = NamespaceType{"raw", "", ""}
NamespaceBlank = NamespaceType{"", "", ""}
NamespacePackage = NamespaceType{"package", "language", NamespacePackageMatch} // these values should match the namespace prefix
NamespaceBundle = NamespaceType{"bundle", "bundles", NamespaceBundlesMatch}
NamespaceLanguage = NamespaceType{"language", "", NamespaceLanguageMatch}
NamespacePlatform = NamespaceType{"platform", "", NamespacePlatformMatch}
NamespaceOrg = NamespaceType{"org", "org", NamespaceOrgMatch}
NamespaceRaw = NamespaceType{"raw", "", ""}
NamespaceBlank = NamespaceType{"", "", ""}
)

func (t NamespaceType) String() string {
Expand Down Expand Up @@ -203,10 +201,10 @@ func NewNamespacePlatform() Namespace {
return Namespace{NamespacePlatform, "platform"}
}

func NewSharedNamespace(orgName string) Namespace {
func NewOrgNamespace(orgName string) Namespace {
return Namespace{
nsType: NamespaceOrgShared,
value: fmt.Sprintf("%s/shared", orgName),
nsType: NamespaceOrg,
value: fmt.Sprintf("org/%s", orgName),
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/platform/runtime/setup/buildlog/buildlog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func TestBuildLog(t *testing.T) {
cm := &connectionMock{}
tt.ConnectionMock(t, cm)

bl, err := NewWithCustomConnections(artifactMap, cm, em, recipeArtifact.ArtifactID, fileutils.TempFilePathUnsafe())
bl, err := NewWithCustomConnections(artifactMap, cm, em, recipeArtifact.ArtifactID, fileutils.TempFilePathUnsafe("", ""))
require.NoError(t, err)

var downloads []artifact.ArtifactID
Expand Down
32 changes: 17 additions & 15 deletions test/integration/publish_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ func (suite *PublishIntegrationTestSuite) TestPublish() {
"New ingredient with file arg and flags",
input{
[]string{tempFile,
"--name", "im-a-name",
"--namespace", "{{.Username}}/shared",
"--name", "im-a-name-test1",
"--namespace", "org/{{.Username}}",
"--version", "2.3.4",
"--description", "im-a-description",
"--author", "author-name <[email protected]>",
Expand All @@ -82,8 +82,8 @@ func (suite *PublishIntegrationTestSuite) TestPublish() {
expect{
[]string{
`Upload following ingredient?`,
`name: im-a-name`,
`namespace: {{.Username}}/shared`,
`name: im-a-name-test1`,
`namespace: org/{{.Username}}`,
`version: 2.3.4`,
`description: im-a-description`,
`name: author-name`,
Expand Down Expand Up @@ -112,8 +112,8 @@ func (suite *PublishIntegrationTestSuite) TestPublish() {
input{
[]string{"--meta", "{{.MetaFile}}", tempFile},
ptr.To(`
name: im-a-name
namespace: {{.Username}}/shared
name: im-a-name-test2
namespace: org/{{.Username}}
version: 2.3.4
description: im-a-description
authors:
Expand All @@ -126,8 +126,8 @@ authors:
expect{
[]string{
`Upload following ingredient?`,
`name: im-a-name`,
`namespace: {{.Username}}/shared`,
`name: im-a-name-test2`,
`namespace: org/{{.Username}}`,
`version: 2.3.4`,
`description: im-a-description`,
`name: author-name`,
Expand All @@ -143,7 +143,7 @@ authors:
[]string{"--meta", "{{.MetaFile}}", tempFile, "--name", "im-a-name-from-flag", "--author", "author-name-from-flag <[email protected]>"},
ptr.To(`
name: im-a-name
namespace: {{.Username}}/shared
namespace: org/{{.Username}}
version: 2.3.4
description: im-a-description
authors:
Expand All @@ -157,7 +157,7 @@ authors:
[]string{
`Upload following ingredient?`,
`name: im-a-name-from-flag`,
`namespace: {{.Username}}/shared`,
`namespace: org/{{.Username}}`,
`version: 2.3.4`,
`description: im-a-description`,
`name: author-name-from-flag`,
Expand All @@ -173,8 +173,8 @@ authors:
[]string{tempFile, "--editor"},
nil,
ptr.To(`
name: im-a-name
namespace: {{.Username}}/shared
name: im-a-name-test3
namespace: org/{{.Username}}
version: 2.3.4
description: im-a-description
authors:
Expand All @@ -186,8 +186,8 @@ authors:
expect{
[]string{
`Upload following ingredient?`,
`name: im-a-name`,
`namespace: {{.Username}}/shared`,
`name: im-a-name-test3`,
`namespace: org/{{.Username}}`,
`version: 2.3.4`,
`description: im-a-description`,
`name: author-name`,
Expand All @@ -200,7 +200,7 @@ authors:
{
"Cancel upload",
input{
[]string{tempFile, "--name", "bogus", "--namespace", "{{.Username}}/shared"},
[]string{tempFile, "--name", "bogus", "--namespace", "org/{{.Username}}"},
nil,
nil,
false,
Expand All @@ -215,6 +215,8 @@ authors:
}
for _, tt := range tests {
suite.Run(tt.name, func() {
ts.T = suite.T() // This differs per subtest

templateVars := map[string]interface{}{
"Username": user.Username,
"Email": user.Email,
Expand Down

0 comments on commit 21da0b3

Please sign in to comment.