From d0e89cf676eaacc636285944fa9f9b1f3d64dcc5 Mon Sep 17 00:00:00 2001 From: Nathan Rijksen Date: Fri, 4 Aug 2023 09:47:07 -0700 Subject: [PATCH 1/2] WIP: End to end tests and fixes for state publish --- cmd/state-offline-installer/install.go | 2 +- internal/app/app_darwin.go | 6 +-- internal/assets/assets.go | 8 ++- internal/captain/command.go | 2 +- internal/fileutils/fileutils.go | 38 ++++++++------ internal/locale/locales/en-us.yaml | 6 +++ internal/notify/notify_windows.go | 2 +- .../osutils/autostart/autostart_darwin.go | 2 +- .../osutils/autostart/autostart_windows.go | 2 +- internal/runbits/requirements/requirements.go | 9 +++- internal/runners/clean/run_win.go | 2 +- internal/runners/deploy/deploy.go | 2 +- internal/subshell/sscommon/rcfile.go | 6 +-- pkg/platform/model/buildplanner.go | 6 +-- pkg/platform/model/vcs.go | 7 +-- .../buildexpression/buildexpression.go | 11 +--- pkg/platform/runtime/target/target.go | 1 + pkg/projectfile/projectfile.go | 6 +-- .../python-ingredient/example/__init__.py | 0 .../python-ingredient/example/hello.dat | 1 + .../assets/python-ingredient/example/hello.py | 1 + .../assets/python-ingredient/pyproject.toml | 11 ++++ test/integration/init_int_test.go | 2 +- test/integration/publish_int_test.go | 52 ++++++++++++++++--- 24 files changed, 123 insertions(+), 62 deletions(-) create mode 100644 test/integration/assets/python-ingredient/example/__init__.py create mode 100644 test/integration/assets/python-ingredient/example/hello.dat create mode 100644 test/integration/assets/python-ingredient/example/hello.py create mode 100644 test/integration/assets/python-ingredient/pyproject.toml diff --git a/cmd/state-offline-installer/install.go b/cmd/state-offline-installer/install.go index 42d7d0da76..8ce1dd5c6a 100644 --- a/cmd/state-offline-installer/install.go +++ b/cmd/state-offline-installer/install.go @@ -374,7 +374,7 @@ func (r *runner) configureEnvironment(path string, namespace *project.Namespaced } if rt.GOOS == "windows" { - contents, err := assets.ReadFileBytes("scripts/setenv.bat") + contents, err := assets.ReadFile("scripts/setenv.bat") if err != nil { return errs.Wrap(err, "Error reading file bytes") } diff --git a/internal/app/app_darwin.go b/internal/app/app_darwin.go index 64754f72ac..5a1e0154ae 100644 --- a/internal/app/app_darwin.go +++ b/internal/app/app_darwin.go @@ -82,7 +82,7 @@ func (a *App) Path() string { } func (a *App) createIcon(path string) error { - icon, err := assets.ReadFileBytes(a.options.IconFileSource) + icon, err := assets.ReadFile(a.options.IconFileSource) if err != nil { return errs.Wrap(err, "Could not read asset") } @@ -96,7 +96,7 @@ func (a *App) createIcon(path string) error { func (a *App) createExecFile(base string) error { path := filepath.Join(base, "Contents", "MacOS") - asset, err := assets.ReadFileBytes(execFileSource) + asset, err := assets.ReadFile(execFileSource) if err != nil { return errs.Wrap(err, "Could not read asset") } @@ -128,7 +128,7 @@ func (a *App) createExecFile(base string) error { func (a *App) createInfoFile(base string) error { path := filepath.Join(base, "Contents") - asset, err := assets.ReadFileBytes(launchFileSource) + asset, err := assets.ReadFile(launchFileSource) if err != nil { return errs.Wrap(err, "Could not read asset") } diff --git a/internal/assets/assets.go b/internal/assets/assets.go index 38d0e5a2af..a59d4d501e 100644 --- a/internal/assets/assets.go +++ b/internal/assets/assets.go @@ -25,9 +25,13 @@ func (a *AssetsFS) ReadDir(name string) ([]iofs.DirEntry, error) { return a.fs.ReadDir("contents/" + name) } -// ReadFileBytes reads and returns bytes from the given file in this package's embedded assets. +func (a *AssetsFS) ReadFile(filename string) ([]byte, error) { + return a.fs.ReadFile("contents/" + filename) +} + +// ReadFile reads and returns bytes from the given file in this package's embedded assets. // Filenames should use forward slashes, not `filepath.Join()`, because go:embed requires '/'. -func ReadFileBytes(filename string) ([]byte, error) { +func ReadFile(filename string) ([]byte, error) { return fs.ReadFile("contents/" + filename) } diff --git a/internal/captain/command.go b/internal/captain/command.go index 37e1cd4b21..1892b32539 100644 --- a/internal/captain/command.go +++ b/internal/captain/command.go @@ -888,7 +888,7 @@ func (cmd *Command) Usage() error { "childCommands": childCommands, }) - contents, err := assets.ReadFileBytes("usage.tpl") + contents, err := assets.ReadFile("usage.tpl") if err != nil { return errs.Wrap(err, "Could not read asset") } diff --git a/internal/fileutils/fileutils.go b/internal/fileutils/fileutils.go index 66889b54df..3d5bf74d40 100644 --- a/internal/fileutils/fileutils.go +++ b/internal/fileutils/fileutils.go @@ -3,6 +3,7 @@ package fileutils import ( "bytes" "crypto/sha256" + "embed" "encoding/hex" "errors" "fmt" @@ -17,7 +18,6 @@ import ( "time" "unicode" - "github.com/ActiveState/cli/internal/assets" "github.com/ActiveState/cli/internal/errs" "github.com/ActiveState/cli/internal/locale" "github.com/ActiveState/cli/internal/logging" @@ -268,20 +268,6 @@ func CopyFile(src, target string) error { return nil } -func CopyAsset(assetName, dest string) error { - asset, err := assets.ReadFileBytes(assetName) - if err != nil { - return errs.Wrap(err, "Asset %s failed", assetName) - } - - err = ioutil.WriteFile(dest, asset, 0644) - if err != nil { - return errs.Wrap(err, "ioutil.WriteFile %s failed", dest) - } - - return nil -} - func CopyMultipleFiles(files map[string]string) error { for src, target := range files { err := CopyFile(src, target) @@ -703,6 +689,7 @@ func WriteTempFileToDir(dir, pattern string, data []byte, perm os.FileMode) (str type DirReader interface { ReadDir(string) ([]os.DirEntry, error) + ReadFile(string) ([]byte, error) } func CopyFilesDirReader(reader DirReader, src, dst, placeholderFileName string) error { @@ -736,9 +723,14 @@ func CopyFilesDirReader(reader DirReader, src, dst, placeholderFileName string) continue } - err := CopyAsset(srcPath, destPath) + f, err := reader.ReadFile(srcPath) if err != nil { - return errs.Wrap(err, "CopyFile %s:%s failed", srcPath, destPath) + return errs.Wrap(err, "Read file %s failed", srcPath) + } + + err = os.WriteFile(destPath, f, 0644) + if err != nil { + return errs.Wrap(err, "Write file %s failed", destPath) } } } @@ -1184,3 +1176,15 @@ func globPath(path string) string { } return result } + +type EmbedFS struct { + fs embed.FS +} + +func NewEmbedFS(fs embed.FS) *EmbedFS { + return &EmbedFS{fs: fs} +} + +func (a *EmbedFS) ReadDir(name string) ([]fs.DirEntry, error) { + return a.fs.ReadDir(name) +} diff --git a/internal/locale/locales/en-us.yaml b/internal/locale/locales/en-us.yaml index 4fa9621c4d..5a61f22002 100644 --- a/internal/locale/locales/en-us.yaml +++ b/internal/locale/locales/en-us.yaml @@ -856,6 +856,8 @@ err_project_no_languages: other: Your project does not have any languages configured err_add_commit: other: "Error occurred while trying to create a commit: {{.V0}}" +err_add_commit_initial: + other: "Error occurred while trying to create initial commit: {{.V0}}" err_update_branch: other: "Error occurred while trying to update a branch: {{.V0}}" err_get_commit_history: @@ -1186,6 +1188,10 @@ package_added: other: "Package added: [NOTICE]{{.V0}}[/RESET]" package_version_added: other: "Package added: [NOTICE]{{.V0}}@{{.V1}}[/RESET]" +raw_added: + other: "Dependency added: [NOTICE]{{.V0}}[/RESET]" +raw_version_added: + other: "Dependency added: [NOTICE]{{.V0}}@{{.V1}}[/RESET]" bundle_added: other: "[SUCCESS]✔ {{.V0}} Bundle successfully installed![/RESET]" bundle_version_added: diff --git a/internal/notify/notify_windows.go b/internal/notify/notify_windows.go index fbcdfcd6c8..8250a0d677 100644 --- a/internal/notify/notify_windows.go +++ b/internal/notify/notify_windows.go @@ -9,7 +9,7 @@ import ( ) func Send(title, message, actionName, actionLink string) error { - iconBytes, err := assets.ReadFileBytes("icon.png") + iconBytes, err := assets.ReadFile("icon.png") if err != nil { return errs.Wrap(err, "Could not read asset") } diff --git a/internal/osutils/autostart/autostart_darwin.go b/internal/osutils/autostart/autostart_darwin.go index d5299d1fcd..d48bbdbcca 100644 --- a/internal/osutils/autostart/autostart_darwin.go +++ b/internal/osutils/autostart/autostart_darwin.go @@ -33,7 +33,7 @@ func enable(exec string, opts Options) error { return errs.Wrap(err, "Could not get launch file") } - asset, err := assets.ReadFileBytes(autostartFileSource) + asset, err := assets.ReadFile(autostartFileSource) if err != nil { return errs.Wrap(err, "Could not read asset") } diff --git a/internal/osutils/autostart/autostart_windows.go b/internal/osutils/autostart/autostart_windows.go index a214011e68..7882792196 100644 --- a/internal/osutils/autostart/autostart_windows.go +++ b/internal/osutils/autostart/autostart_windows.go @@ -29,7 +29,7 @@ func enable(exec string, opts Options) error { return errs.Wrap(err, "Could not create shortcut") } - icon, err := assets.ReadFileBytes(opts.IconFileSource) + icon, err := assets.ReadFile(opts.IconFileSource) if err != nil { return errs.Wrap(err, "Could not read asset") } diff --git a/internal/runbits/requirements/requirements.go b/internal/runbits/requirements/requirements.go index 992f23f216..e6aeac6850 100644 --- a/internal/runbits/requirements/requirements.go +++ b/internal/runbits/requirements/requirements.go @@ -224,7 +224,10 @@ func (r *RequirementOperation) ExecuteRequirementOperation( ) if !hasParentCommit { - languageFromNs := model.LanguageFromNamespace(ns.String()) + var languageFromNs string + if ns.Type() != model.NamespaceRaw { + languageFromNs = model.LanguageFromNamespace(ns.String()) + } parentCommitID, err = model.CommitInitial(model.HostPlatform, languageFromNs, langVersion) if err != nil { return locale.WrapError(err, "err_install_no_project_commit", "Could not create initial commit for new project") @@ -259,7 +262,7 @@ func (r *RequirementOperation) ExecuteRequirementOperation( bp := model.NewBuildPlannerModel(r.Auth) commitID, err := bp.StageCommit(params) if err != nil { - return locale.WrapError(err, "err_package_save_and_build", "Error occurred while trying to create a commit") + return locale.WrapError(err, "err_package_save_and_build", "Error occurred while trying to stage a commit") } orderChanged := !hasParentCommit @@ -283,6 +286,8 @@ func (r *RequirementOperation) ExecuteRequirementOperation( trigger = target.TriggerPackage case model.NamespacePlatform: trigger = target.TriggerPlatform + case model.NamespaceRaw: + trigger = target.TriggerCustom default: return errs.Wrap(err, "Unsupported namespace type: %s", ns.Type().String()) } diff --git a/internal/runners/clean/run_win.go b/internal/runners/clean/run_win.go index d6c0c47b41..82def52986 100644 --- a/internal/runners/clean/run_win.go +++ b/internal/runners/clean/run_win.go @@ -137,7 +137,7 @@ func removeInstall(logFile string, params *UninstallParams, cfg *config.Instance func removePaths(logFile string, paths ...string) error { logging.Debug("Removing paths: %v", paths) scriptName := "removePaths" - scriptBlock, err := assets.ReadFileBytes(fmt.Sprintf("scripts/%s.bat", scriptName)) + scriptBlock, err := assets.ReadFile(fmt.Sprintf("scripts/%s.bat", scriptName)) if err != nil { return err } diff --git a/internal/runners/deploy/deploy.go b/internal/runners/deploy/deploy.go index e3f80672b9..7b1a372f56 100644 --- a/internal/runners/deploy/deploy.go +++ b/internal/runners/deploy/deploy.go @@ -179,7 +179,7 @@ func (d *Deploy) install(rtTarget setup.Targeter) (rerr error) { _, _ = rti.Env(false, false) if rt.GOOS == "windows" { - contents, err := assets.ReadFileBytes("scripts/setenv.bat") + contents, err := assets.ReadFile("scripts/setenv.bat") if err != nil { return err } diff --git a/internal/subshell/sscommon/rcfile.go b/internal/subshell/sscommon/rcfile.go index b40d2d7e87..6dcde781ab 100644 --- a/internal/subshell/sscommon/rcfile.go +++ b/internal/subshell/sscommon/rcfile.go @@ -82,7 +82,7 @@ func WriteRcFile(rcTemplateName string, path string, data RcIdentification, env return err } - tpl, err := assets.ReadFileBytes(fmt.Sprintf("shells/%s", rcTemplateName)) + tpl, err := assets.ReadFile(fmt.Sprintf("shells/%s", rcTemplateName)) if err != nil { return errs.Wrap(err, "Failed to read asset") } @@ -192,7 +192,7 @@ func CleanRcFile(path string, data RcIdentification) error { // SetupShellRcFile create a rc file to activate a runtime (without a project being present) func SetupShellRcFile(rcFileName, templateName string, env map[string]string, namespace *project.Namespaced) error { - tpl, err := assets.ReadFileBytes(fmt.Sprintf("shells/%s", templateName)) + tpl, err := assets.ReadFile(fmt.Sprintf("shells/%s", templateName)) if err != nil { return errs.Wrap(err, "Failed to read asset") } @@ -234,7 +234,7 @@ func SetupShellRcFile(rcFileName, templateName string, env map[string]string, na // SetupProjectRcFile creates a temporary RC file that our shell is initiated from, this allows us to template the logic // used for initialising the subshell func SetupProjectRcFile(prj *project.Project, templateName, ext string, env map[string]string, out output.Outputer, cfg Configurable, bashifyPaths bool) (*os.File, error) { - tpl, err := assets.ReadFileBytes(fmt.Sprintf("shells/%s", templateName)) + tpl, err := assets.ReadFile(fmt.Sprintf("shells/%s", templateName)) if err != nil { return nil, errs.Wrap(err, "Failed to read asset") } diff --git a/pkg/platform/model/buildplanner.go b/pkg/platform/model/buildplanner.go index 85037949c9..a14ab8d97d 100644 --- a/pkg/platform/model/buildplanner.go +++ b/pkg/platform/model/buildplanner.go @@ -73,6 +73,7 @@ func NewBuildPlannerModel(auth *authentication.Auth) *BuildPlanner { logging.Debug("Using build planner at: %s", bpURL) client := gqlclient.NewWithOpts(bpURL, 0, graphql.WithHTTPClient(&http.Client{})) + client.EnableDebugLog() if auth.Authenticated() { client.SetTokenProvider(auth) @@ -273,10 +274,7 @@ func (bp *BuildPlanner) StageCommit(params StageCommitParams) (strfmt.UUID, erro } } - err = expression.UpdateTimestamp(params.TimeStamp) - if err != nil { - return "", errs.Wrap(err, "Failed to update build expression with timestamp") - } + expression.UpdateTimestamp(params.TimeStamp) // With the updated build expression call the stage commit mutation request := request.StageCommit(params.Owner, params.Project, params.ParentCommit, expression) diff --git a/pkg/platform/model/vcs.go b/pkg/platform/model/vcs.go index c4dd98d2b1..b733fefb05 100644 --- a/pkg/platform/model/vcs.go +++ b/pkg/platform/model/vcs.go @@ -445,10 +445,6 @@ func AddChangeset(parentCommitID strfmt.UUID, commitMessage string, changeset Ch res, err := mono.New().VersionControl.AddCommit(params, authentication.ClientAuth()) if err != nil { switch err.(type) { - case *version_control.AddCommitBadRequest, - *version_control.AddCommitConflict, - *version_control.AddCommitNotFound: - return nil, locale.WrapInputError(err, "err_add_commit", "", api.ErrorMessageFromPayload(err)) case *version_control.AddCommitForbidden: return nil, locale.WrapInputError(err, "err_add_commit", "", locale.T("err_auth_required")) default: @@ -607,6 +603,7 @@ func CommitChangeset(parentCommitID strfmt.UUID, commitMsg string, changeset Cha // CommitInitial creates a root commit for a new branch func CommitInitial(hostPlatform string, langName, langVersion string) (strfmt.UUID, error) { + logging.Debug("Creating initial commit, platform: %s, language: %s@%s", hostPlatform, langName, langVersion) platformID, err := hostPlatformToPlatformID(hostPlatform) if err != nil { return "", err @@ -650,7 +647,7 @@ func CommitInitial(hostPlatform string, langName, langVersion string) (strfmt.UU res, err := mono.New().VersionControl.AddCommit(params, authentication.ClientAuth()) if err != nil { - return "", locale.WrapError(err, "err_add_commit", "", api.ErrorMessageFromPayload(err)) + return "", locale.WrapError(err, "err_add_commit_initial", "", api.ErrorMessageFromPayload(err)) } return res.Payload.CommitID, nil diff --git a/pkg/platform/runtime/buildexpression/buildexpression.go b/pkg/platform/runtime/buildexpression/buildexpression.go index 21a558f023..a5aa7548d7 100644 --- a/pkg/platform/runtime/buildexpression/buildexpression.go +++ b/pkg/platform/runtime/buildexpression/buildexpression.go @@ -679,23 +679,16 @@ func (e *BuildExpression) removePlatform(platformID strfmt.UUID) error { return nil } -func (e *BuildExpression) UpdateTimestamp(timestamp time.Time) error { - formatted, err := time.Parse(time.RFC3339, timestamp.String()) - if err != nil { - return errs.Wrap(err, "Could not parse latest timestamp") - } - +func (e *BuildExpression) UpdateTimestamp(timestamp time.Time) { for _, arg := range e.getSolveNode().Arguments { if arg.Assignment == nil { continue } if arg.Assignment.Name == "at_time" { - arg.Assignment.Value.Str = ptr.To(formatted.Format(time.RFC3339)) + arg.Assignment.Value.Str = ptr.To(timestamp.Format(time.RFC3339)) } } - - return nil } func (e *BuildExpression) MarshalJSON() ([]byte, error) { diff --git a/pkg/platform/runtime/target/target.go b/pkg/platform/runtime/target/target.go index b70c302da7..39aff02ea2 100644 --- a/pkg/platform/runtime/target/target.go +++ b/pkg/platform/runtime/target/target.go @@ -34,6 +34,7 @@ const ( TriggerPackage Trigger = "package" TriggerLanguage Trigger = "language" TriggerPlatform Trigger = "platform" + TriggerCustom Trigger = "custom" TriggerPull Trigger = "pull" TriggerRefresh Trigger = "refresh" TriggerReset Trigger = "reset" diff --git a/pkg/projectfile/projectfile.go b/pkg/projectfile/projectfile.go index 977835feb9..8a7a237574 100644 --- a/pkg/projectfile/projectfile.go +++ b/pkg/projectfile/projectfile.go @@ -992,7 +992,7 @@ func createCustom(params *CreateParams, lang language.Language) (*Project, error content := params.Content if content == "" && lang != language.Unset && lang != language.Unknown { tplName := "activestate.yaml." + strings.TrimRight(lang.String(), "23") + ".tpl" - template, err := assets.ReadFileBytes(tplName) + template, err := assets.ReadFile(tplName) if err != nil { return nil, errs.Wrap(err, "Could not read asset") } @@ -1013,7 +1013,7 @@ func createCustom(params *CreateParams, lang language.Language) (*Project, error } tplName := "activestate.yaml.tpl" - tplContents, err := assets.ReadFileBytes(tplName) + tplContents, err := assets.ReadFile(tplName) if err != nil { return nil, errs.Wrap(err, "Could not read asset") } @@ -1048,7 +1048,7 @@ func createHostFile(filePath, cachePath string) error { } tplName := "activestate.yaml.cache.tpl" - tplContents, err := assets.ReadFileBytes(tplName) + tplContents, err := assets.ReadFile(tplName) if err != nil { return errs.Wrap(err, "Could not read asset") } diff --git a/test/integration/assets/python-ingredient/example/__init__.py b/test/integration/assets/python-ingredient/example/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/integration/assets/python-ingredient/example/hello.dat b/test/integration/assets/python-ingredient/example/hello.dat new file mode 100644 index 0000000000..ce01362503 --- /dev/null +++ b/test/integration/assets/python-ingredient/example/hello.dat @@ -0,0 +1 @@ +hello diff --git a/test/integration/assets/python-ingredient/example/hello.py b/test/integration/assets/python-ingredient/example/hello.py new file mode 100644 index 0000000000..11b15b1a45 --- /dev/null +++ b/test/integration/assets/python-ingredient/example/hello.py @@ -0,0 +1 @@ +print("hello") diff --git a/test/integration/assets/python-ingredient/pyproject.toml b/test/integration/assets/python-ingredient/pyproject.toml new file mode 100644 index 0000000000..1d2e1a7c2d --- /dev/null +++ b/test/integration/assets/python-ingredient/pyproject.toml @@ -0,0 +1,11 @@ +[build-system] +requires = ["setuptools>=61"] +build-backend = "setuptools.build_meta" + +[project] +name = "example" +version = "0.1" + +[tool.setuptools] +package-data = {"example" = ["*.dat"]} + diff --git a/test/integration/init_int_test.go b/test/integration/init_int_test.go index 5b7ee27a47..c4cf220a60 100644 --- a/test/integration/init_int_test.go +++ b/test/integration/init_int_test.go @@ -80,7 +80,7 @@ func (suite *InitIntegrationTestSuite) runInitTest(addPath bool, lang string, ex configFilepath := filepath.Join(ts.Dirs.Work, constants.ConfigFileName) suite.Require().FileExists(configFilepath) - templateFile, err := assets.ReadFileBytes("activestate.yaml.python.tpl") + templateFile, err := assets.ReadFile("activestate.yaml.python.tpl") if err != nil { panic(err.Error()) } diff --git a/test/integration/publish_int_test.go b/test/integration/publish_int_test.go index 4d65f2e3b1..ae7440d7cb 100644 --- a/test/integration/publish_int_test.go +++ b/test/integration/publish_int_test.go @@ -1,18 +1,24 @@ package integration import ( + "embed" "fmt" "os" + "path/filepath" "regexp" "testing" + "time" "github.com/ActiveState/cli/internal/constants" + "github.com/ActiveState/cli/internal/errs" "github.com/ActiveState/cli/internal/fileutils" "github.com/ActiveState/cli/internal/rtutils/ptr" "github.com/ActiveState/cli/internal/strutils" "github.com/ActiveState/cli/internal/testhelpers/e2e" "github.com/ActiveState/cli/internal/testhelpers/tagsuite" "github.com/ActiveState/cli/pkg/platform/api/graphql/request" + "github.com/labstack/gommon/random" + "github.com/mholt/archiver" "github.com/stretchr/testify/suite" "gopkg.in/yaml.v3" ) @@ -23,6 +29,9 @@ type PublishIntegrationTestSuite struct { tagsuite.Suite } +//go:embed assets/python-ingredient/* +var pythonIngredient embed.FS + func (suite *PublishIntegrationTestSuite) TestPublish() { suite.OnlyRunForTags(tagsuite.Publish) @@ -46,6 +55,7 @@ func (suite *PublishIntegrationTestSuite) TestPublish() { immediateOutput string exitBeforePrompt bool exitCode int + installSuccess bool } type invocation struct { @@ -53,14 +63,18 @@ func (suite *PublishIntegrationTestSuite) TestPublish() { expect expect } - tempFile := fileutils.TempFilePathUnsafe("", "*.zip") - defer os.Remove(tempFile) + ts := e2e.New(suite.T(), true) + defer ts.Close() - tempFileInvalid := fileutils.TempFilePathUnsafe("", "*.notzip") - defer os.Remove(tempFileInvalid) + tempFileInvalid := fileutils.TempFilePathUnsafe(ts.Dirs.Work, "*.notzip") - ts := e2e.New(suite.T(), false) - defer ts.Close() + payload := fileutils.TempDirFromBaseDirUnsafe(ts.Dirs.Work) + tempFile := filepath.Join(ts.Dirs.Work, "payload.zip") + + err := fileutils.CopyFilesDirReader(pythonIngredient, "assets/python-ingredient", payload, "") + suite.Require().NoError(err, errs.JoinMessage(err)) + + suite.Require().NoError(archiver.Archive(fileutils.ListDirSimple(payload, false), tempFile)) ts.Env = append(ts.Env, // Publish tests shouldn't run against staging as they pollute the inventory db and artifact cache @@ -103,6 +117,7 @@ func (suite *PublishIntegrationTestSuite) TestPublish() { "", false, 0, + true, }, }, }, @@ -120,6 +135,7 @@ func (suite *PublishIntegrationTestSuite) TestPublish() { "Expected file extension to be either", false, 1, + false, }, }, }, @@ -154,6 +170,7 @@ authors: "", false, 0, + false, }, }}, }, @@ -187,6 +204,7 @@ authors: "", false, 0, + false, }, }}, }, @@ -220,6 +238,7 @@ authors: "", false, 0, + false, }, }}, }, @@ -237,6 +256,7 @@ authors: "", false, 0, + false, }, }}, }, @@ -262,6 +282,7 @@ authors: "", false, 0, + false, }, }, { // Edit ingredient @@ -290,6 +311,7 @@ authors: "", false, 0, + false, }, }, { // Must supply version @@ -310,6 +332,7 @@ authors: "", true, 1, + false, }, }, { // description editing not supported @@ -330,6 +353,7 @@ authors: "", true, 1, + false, }, }, }, @@ -419,6 +443,22 @@ authors: cp = ts.Spawn("search", meta.Namespace+"/"+meta.Name, "--ts=now") cp.Expect(meta.Version) cp.ExpectExitCode(0) + + if inv.expect.installSuccess { + // We shouldn't need to include Python, but this is working around a bug: + // https://activestatef.atlassian.net/browse/PB-4483 + cp := ts.Spawn("init", "--language=python", user.Username+"/"+random.String(8, random.Alphanumeric), ".") + cp.ExpectExitCode(0) + + cp = ts.SpawnWithOpts( + e2e.WithArgs("install", meta.Namespace+"/"+meta.Name, "--ts=now"), + e2e.AppendEnv("ACTIVESTATE_CLI_DISABLE_RUNTIME=false")) + cp.ExpectRe("(?:Dependency added|being built)", 30*time.Second) + cp.Expect("no match") + cp.ExpectExitCode(0) + + fmt.Printf("Dirs: %s\n", ts.Dirs.Base) + } }) } }) From c75100b66918dee27c4cbd64d98153fd2d3a5ff7 Mon Sep 17 00:00:00 2001 From: Nathan Rijksen Date: Fri, 4 Aug 2023 14:22:33 -0700 Subject: [PATCH 2/2] Attempt with setup.py --- .../assets/python-ingredient/pyproject.toml | 11 ----------- test/integration/assets/python-ingredient/setup.py | 6 ++++++ test/integration/publish_int_test.go | 7 ++++--- 3 files changed, 10 insertions(+), 14 deletions(-) delete mode 100644 test/integration/assets/python-ingredient/pyproject.toml create mode 100644 test/integration/assets/python-ingredient/setup.py diff --git a/test/integration/assets/python-ingredient/pyproject.toml b/test/integration/assets/python-ingredient/pyproject.toml deleted file mode 100644 index 1d2e1a7c2d..0000000000 --- a/test/integration/assets/python-ingredient/pyproject.toml +++ /dev/null @@ -1,11 +0,0 @@ -[build-system] -requires = ["setuptools>=61"] -build-backend = "setuptools.build_meta" - -[project] -name = "example" -version = "0.1" - -[tool.setuptools] -package-data = {"example" = ["*.dat"]} - diff --git a/test/integration/assets/python-ingredient/setup.py b/test/integration/assets/python-ingredient/setup.py new file mode 100644 index 0000000000..3c7e692b4b --- /dev/null +++ b/test/integration/assets/python-ingredient/setup.py @@ -0,0 +1,6 @@ +from setuptools import find_packages, setup +setup(name="example", + version="0.1", + author="ActiveState", + packages=find_packages(), + ) diff --git a/test/integration/publish_int_test.go b/test/integration/publish_int_test.go index ae7440d7cb..2913fb9e43 100644 --- a/test/integration/publish_int_test.go +++ b/test/integration/publish_int_test.go @@ -29,14 +29,14 @@ type PublishIntegrationTestSuite struct { tagsuite.Suite } -//go:embed assets/python-ingredient/* +//go:embed all:assets/python-ingredient var pythonIngredient embed.FS func (suite *PublishIntegrationTestSuite) TestPublish() { suite.OnlyRunForTags(tagsuite.Publish) // For development convenience, should not be committed without commenting out.. - // os.Setenv(constants.APIHostEnvVarName, "pr11496.activestate.build") + os.Setenv(constants.APIHostEnvVarName, "pr11496.activestate.build") if v := os.Getenv(constants.APIHostEnvVarName); v == "" || v == constants.DefaultAPIHost { suite.T().Skipf("Skipping test as %s is not set, this test can only be run against non-production envs.", constants.APIHostEnvVarName) @@ -74,7 +74,7 @@ func (suite *PublishIntegrationTestSuite) TestPublish() { err := fileutils.CopyFilesDirReader(pythonIngredient, "assets/python-ingredient", payload, "") suite.Require().NoError(err, errs.JoinMessage(err)) - suite.Require().NoError(archiver.Archive(fileutils.ListDirSimple(payload, false), tempFile)) + suite.Require().NoError(archiver.Archive(fileutils.ListFilesUnsafe(payload), tempFile)) ts.Env = append(ts.Env, // Publish tests shouldn't run against staging as they pollute the inventory db and artifact cache @@ -99,6 +99,7 @@ func (suite *PublishIntegrationTestSuite) TestPublish() { "--version", "2.3.4", "--description", "im-a-description", "--author", "author-name ", + "--depend", "builder/python-module-builder", }, nil, nil,