Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func BuildRoot() *cobra.Command {
rootCmd.AddCommand(NewExportCmd(globalFlags))
rootCmd.AddCommand(NewImportCmd(globalFlags))
rootCmd.AddCommand(NewLogsCmd(globalFlags))
rootCmd.AddCommand(NewUpgradeCmd())
rootCmd.AddCommand(NewSelfUpdateCmd())
rootCmd.AddCommand(NewTroubleshootCmd(globalFlags))
rootCmd.AddCommand(NewPingCmd(globalFlags))
rootCmd.AddCommand(NewReadConfigurationCmd(globalFlags))
Expand Down
26 changes: 13 additions & 13 deletions cmd/upgrade.go → cmd/self_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,32 @@ import (
"github.com/spf13/cobra"
)

// UpgradeCmd is a struct that defines a command call for "upgrade".
type UpgradeCmd struct {
// SelfUpdateCmd is a struct that defines a command call for "self-update".
type SelfUpdateCmd struct {
Version string
DryRun bool
}

// NewUpgradeCmd creates a new upgrade command.
func NewUpgradeCmd() *cobra.Command {
cmd := &UpgradeCmd{}
upgradeCmd := &cobra.Command{
Use: "upgrade",
Short: "Upgrade the Devsy CLI to the newest version",
// NewSelfUpdateCmd creates a new self-update command.
func NewSelfUpdateCmd() *cobra.Command {
cmd := &SelfUpdateCmd{}
selfUpdateCmd := &cobra.Command{
Use: "self-update",
Short: "Update the Devsy CLI to the newest version",
Args: cobra.NoArgs,
RunE: func(cobraCmd *cobra.Command, args []string) error {
ctx := cobraCmd.Context()
if err := upgrade.Upgrade(ctx, cmd.Version, cmd.DryRun); err != nil {
return fmt.Errorf("unable to upgrade: %w", err)
return fmt.Errorf("unable to update: %w", err)
}
return nil
},
}

upgradeCmd.Flags().
selfUpdateCmd.Flags().
StringVar(&cmd.Version, "version", "",
"The version to update to. Defaults to the latest stable version available")
upgradeCmd.Flags().
BoolVar(&cmd.DryRun, "dry-run", false, "Show which version would be downloaded without actually upgrading")
return upgradeCmd
selfUpdateCmd.Flags().
BoolVar(&cmd.DryRun, "dry-run", false, "Show which version would be downloaded without actually updating")
return selfUpdateCmd
}
36 changes: 36 additions & 0 deletions cmd/self_update_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package cmd

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestNewSelfUpdateCmd_CommandName(t *testing.T) {
cmd := NewSelfUpdateCmd()
assert.Equal(t, "self-update", cmd.Use)
}

func TestNewSelfUpdateCmd_HasVersionFlag(t *testing.T) {
cmd := NewSelfUpdateCmd()
f := cmd.Flags().Lookup("version")
require.NotNil(t, f, "--version flag must exist")
assert.Equal(t, "", f.DefValue)
}

func TestNewSelfUpdateCmd_HasDryRunFlag(t *testing.T) {
cmd := NewSelfUpdateCmd()
f := cmd.Flags().Lookup("dry-run")
require.NotNil(t, f, "--dry-run flag must exist")
assert.Equal(t, "false", f.DefValue)
}

func TestNewSelfUpdateCmd_AcceptsNoPositionalArgs(t *testing.T) {
cmd := NewSelfUpdateCmd()
err := cmd.Args(cmd, []string{"unexpected"})
assert.Error(t, err, "should reject positional arguments")

err = cmd.Args(cmd, []string{})
assert.NoError(t, err, "should accept zero arguments")
}
2 changes: 1 addition & 1 deletion e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import (
_ "github.com/devsy-org/devsy/e2e/tests/machineprovider"
_ "github.com/devsy-org/devsy/e2e/tests/provider"
_ "github.com/devsy-org/devsy/e2e/tests/readconfiguration"
_ "github.com/devsy-org/devsy/e2e/tests/selfupdate"
_ "github.com/devsy-org/devsy/e2e/tests/ssh"
_ "github.com/devsy-org/devsy/e2e/tests/tunnel"
_ "github.com/devsy-org/devsy/e2e/tests/up"
_ "github.com/devsy-org/devsy/e2e/tests/up-features"
_ "github.com/devsy-org/devsy/e2e/tests/upgrade"
"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
)
Expand Down
48 changes: 48 additions & 0 deletions e2e/tests/selfupdate/selfupdate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package selfupdate

import (
"context"
"os"
"runtime"
"strings"

"github.com/devsy-org/devsy/e2e/framework"
"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
)

var _ = ginkgo.Describe(
"testing self-update command", ginkgo.Label("selfupdate"), ginkgo.Ordered, func() {
ginkgo.It(
"should detect correct binary for current OS and architecture using dry-run",
ginkgo.SpecTimeout(framework.TimeoutShort()),
func(ctx context.Context) {
initialDir, err := os.Getwd()
framework.ExpectNoError(err, "getting current working directory should not error")

f := framework.NewDefaultFramework(initialDir + "/bin")
output, err := f.ExecCommandOutput(ctx, []string{"self-update", "--dry-run"})
framework.ExpectNoError(err, "self-update --dry-run should not error")

ginkgo.By("Parsing dry-run key=value output")
lines := strings.Split(strings.TrimSpace(output), "\n")
values := make(map[string]string)
for _, line := range lines {
parts := strings.SplitN(line, "=", 2)
if len(parts) == 2 {
values[parts[0]] = parts[1]
}
}

expectedOS := runtime.GOOS
framework.ExpectEqual(values["os"], expectedOS, "OS should match runtime")

expectedArch := runtime.GOARCH
framework.ExpectEqual(values["arch"], expectedArch, "Arch should match runtime")

expectedAssetPattern := "devsy-" + expectedOS + "-" + expectedArch
gomega.Expect(values["asset_name"]).
To(gomega.ContainSubstring(expectedAssetPattern), "Asset name should contain OS and Arch")
},
)
})
47 changes: 0 additions & 47 deletions e2e/tests/upgrade/upgrade.go

This file was deleted.

Loading