diff --git a/cli/cmd/download.go b/cli/cmd/download.go index 7276735f3..4b32b0c1c 100644 --- a/cli/cmd/download.go +++ b/cli/cmd/download.go @@ -5,6 +5,7 @@ package cmd import ( "github.com/codesphere-cloud/cs-go/pkg/io" + "github.com/codesphere-cloud/oms/cli/cmd/k0s" "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/spf13/cobra" ) @@ -26,5 +27,5 @@ func AddDownloadCmd(rootCmd *cobra.Command, opts *util.GlobalOptions) { util.AddCmd(rootCmd, download.cmd) AddDownloadPackageCmd(download.cmd, opts) - AddDownloadK0sCmd(download.cmd, opts) + k0s.AddDownloadCmd(download.cmd, opts) } diff --git a/cli/cmd/init_install_config_test.go b/cli/cmd/init_install_config_test.go index 7e6fcb90d..d098b6418 100644 --- a/cli/cmd/init_install_config_test.go +++ b/cli/cmd/init_install_config_test.go @@ -12,6 +12,7 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + "github.com/codesphere-cloud/oms/cli/cmd/testutil" "github.com/codesphere-cloud/oms/internal/installer" "github.com/codesphere-cloud/oms/internal/installer/files" "github.com/codesphere-cloud/oms/internal/installer/vault" @@ -216,7 +217,7 @@ codesphere: Context("valid configuration", func() { It("validates successfully", func() { - if !sopsAndAgeAvailableForUpdateInstallConfig() { + if !testutil.SopsAndAgeAvailable() { Skip("sops and age-keygen not available") } diff --git a/cli/cmd/install.go b/cli/cmd/install.go index eb7674d57..931928fc4 100644 --- a/cli/cmd/install.go +++ b/cli/cmd/install.go @@ -6,6 +6,7 @@ package cmd import ( "github.com/codesphere-cloud/cs-go/pkg/io" "github.com/codesphere-cloud/oms/cli/cmd/codesphere" + "github.com/codesphere-cloud/oms/cli/cmd/k0s" "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/spf13/cobra" ) @@ -26,6 +27,6 @@ func AddInstallCmd(rootCmd *cobra.Command, opts *util.GlobalOptions) { util.AddCmd(rootCmd, install.cmd) codesphere.AddInstallCmd(install.cmd, opts) - AddInstallK0sCmd(install.cmd, opts) + k0s.AddInstallCmd(install.cmd, opts) AddInstallOpenBaoCmd(install.cmd, opts) } diff --git a/cli/cmd/download_k0s.go b/cli/cmd/k0s/download_k0s.go similarity index 96% rename from cli/cmd/download_k0s.go rename to cli/cmd/k0s/download_k0s.go index c859f8db6..cff80a7fd 100644 --- a/cli/cmd/download_k0s.go +++ b/cli/cmd/k0s/download_k0s.go @@ -1,7 +1,7 @@ // Copyright (c) Codesphere Inc. // SPDX-License-Identifier: Apache-2.0 -package cmd +package k0s import ( "fmt" @@ -45,7 +45,7 @@ func (c *DownloadK0sCmd) RunE(_ *cobra.Command, args []string) error { return nil } -func AddDownloadK0sCmd(download *cobra.Command, opts *util.GlobalOptions) { +func AddDownloadCmd(download *cobra.Command, opts *util.GlobalOptions) { k0s := DownloadK0sCmd{ cmd: &cobra.Command{ Use: "k0s", diff --git a/cli/cmd/download_k0s_test.go b/cli/cmd/k0s/download_k0s_test.go similarity index 92% rename from cli/cmd/download_k0s_test.go rename to cli/cmd/k0s/download_k0s_test.go index ed20ed402..bdb3fc4a0 100644 --- a/cli/cmd/download_k0s_test.go +++ b/cli/cmd/k0s/download_k0s_test.go @@ -1,7 +1,7 @@ // Copyright (c) Codesphere Inc. // SPDX-License-Identifier: Apache-2.0 -package cmd_test +package k0s_test import ( "errors" @@ -9,17 +9,17 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "github.com/codesphere-cloud/oms/cli/cmd" + "github.com/codesphere-cloud/oms/cli/cmd/k0s" "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/codesphere-cloud/oms/internal/env" "github.com/codesphere-cloud/oms/internal/installer" intutil "github.com/codesphere-cloud/oms/internal/util" ) -var _ = Describe("DownloadK0sCmd", func() { +var _ = Describe("DownloadK0sk0s", func() { var ( - c cmd.DownloadK0sCmd - opts *cmd.DownloadK0sOpts + c k0s.DownloadK0sCmd + opts *k0s.DownloadK0sOpts globalOpts *util.GlobalOptions mockEnv *env.MockEnv mockFileWriter *intutil.MockFileIO @@ -29,13 +29,13 @@ var _ = Describe("DownloadK0sCmd", func() { mockEnv = env.NewMockEnv(GinkgoT()) mockFileWriter = intutil.NewMockFileIO(GinkgoT()) globalOpts = &util.GlobalOptions{} - opts = &cmd.DownloadK0sOpts{ + opts = &k0s.DownloadK0sOpts{ GlobalOptions: globalOpts, Version: "", Force: false, Quiet: false, } - c = cmd.DownloadK0sCmd{ + c = k0s.DownloadK0sCmd{ Opts: *opts, Env: mockEnv, FileWriter: mockFileWriter, diff --git a/cli/cmd/install_k0s.go b/cli/cmd/k0s/install_k0s.go similarity index 99% rename from cli/cmd/install_k0s.go rename to cli/cmd/k0s/install_k0s.go index ecd59d464..0ed37ed21 100644 --- a/cli/cmd/install_k0s.go +++ b/cli/cmd/k0s/install_k0s.go @@ -1,7 +1,7 @@ // Copyright (c) Codesphere Inc. // SPDX-License-Identifier: Apache-2.0 -package cmd +package k0s import ( "fmt" @@ -52,7 +52,7 @@ func (c *InstallK0sCmd) RunE(_ *cobra.Command, args []string) error { return c.InstallK0s(pm, k0s, k0sctl) } -func AddInstallK0sCmd(install *cobra.Command, opts *util.GlobalOptions) { +func AddInstallCmd(install *cobra.Command, opts *util.GlobalOptions) { k0s := InstallK0sCmd{ cmd: &cobra.Command{ Use: "k0s", diff --git a/cli/cmd/install_k0s_integration_test.go b/cli/cmd/k0s/install_k0s_integration_test.go similarity index 99% rename from cli/cmd/install_k0s_integration_test.go rename to cli/cmd/k0s/install_k0s_integration_test.go index 28a5523cc..c949116cf 100644 --- a/cli/cmd/install_k0s_integration_test.go +++ b/cli/cmd/k0s/install_k0s_integration_test.go @@ -4,7 +4,7 @@ //go:build integration // +build integration -package cmd_test +package k0s_test import ( "fmt" diff --git a/cli/cmd/install_k0s_test.go b/cli/cmd/k0s/install_k0s_test.go similarity index 98% rename from cli/cmd/install_k0s_test.go rename to cli/cmd/k0s/install_k0s_test.go index 3d0e3b4eb..e96f53ec5 100644 --- a/cli/cmd/install_k0s_test.go +++ b/cli/cmd/k0s/install_k0s_test.go @@ -1,7 +1,7 @@ // Copyright (c) Codesphere Inc. // SPDX-License-Identifier: Apache-2.0 -package cmd_test +package k0s_test import ( "os" @@ -14,7 +14,8 @@ import ( "github.com/stretchr/testify/mock" "gopkg.in/yaml.v3" - "github.com/codesphere-cloud/oms/cli/cmd" + "github.com/codesphere-cloud/oms/cli/cmd/k0s" + "github.com/codesphere-cloud/oms/cli/cmd/testutil" "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/codesphere-cloud/oms/internal/env" "github.com/codesphere-cloud/oms/internal/installer" @@ -30,8 +31,8 @@ func execCmd(name string, args ...string) ([]byte, error) { var _ = Describe("InstallK0sCmd", func() { var ( - c cmd.InstallK0sCmd - opts *cmd.InstallK0sOpts + c k0s.InstallK0sCmd + opts *k0s.InstallK0sOpts globalOpts *util.GlobalOptions mockEnv *env.MockEnv mockFileWriter *intutil.MockFileIO @@ -41,14 +42,14 @@ var _ = Describe("InstallK0sCmd", func() { mockEnv = env.NewMockEnv(GinkgoT()) mockFileWriter = intutil.NewMockFileIO(GinkgoT()) globalOpts = &util.GlobalOptions{} - opts = &cmd.InstallK0sOpts{ + opts = &k0s.InstallK0sOpts{ GlobalOptions: globalOpts, Version: "", Package: "", InstallConfig: "", Force: false, } - c = cmd.InstallK0sCmd{ + c = k0s.InstallK0sCmd{ Opts: *opts, Env: mockEnv, FileWriter: mockFileWriter, @@ -384,7 +385,7 @@ var _ = Describe("InstallK0sCmd", func() { }) It("re-encrypts vault after saving kubeconfig when vault was SOPS-encrypted", func() { - if !sopsAndAgeAvailable() { + if !testutil.SopsAndAgeAvailable() { Skip("sops and age-keygen not available") } @@ -451,7 +452,7 @@ var _ = Describe("InstallK0sCmd", func() { }) It("leaves the vault untouched when vault decryption fails with invalid key", func() { - if !sopsAndAgeAvailable() { + if !testutil.SopsAndAgeAvailable() { Skip("sops and age-keygen not available") } @@ -521,7 +522,7 @@ var _ = Describe("InstallK0sCmd", func() { }) It("leaves the vault untouched when encryption of the new vault fails", func() { - if !sopsAndAgeAvailable() { + if !testutil.SopsAndAgeAvailable() { Skip("sops and age-keygen not available") } diff --git a/cli/cmd/template_config_test.go b/cli/cmd/template_config_test.go index 09b884023..8e611f0ac 100644 --- a/cli/cmd/template_config_test.go +++ b/cli/cmd/template_config_test.go @@ -11,6 +11,7 @@ import ( "strings" "github.com/codesphere-cloud/oms/cli/cmd" + "github.com/codesphere-cloud/oms/cli/cmd/testutil" "github.com/codesphere-cloud/oms/internal/installer/files" "github.com/codesphere-cloud/oms/internal/installer/vault" @@ -20,7 +21,7 @@ import ( var _ = Describe("TemplateConfigCmd", func() { It("renders config templates with secrets from a vault file", func() { - if !sopsAndAgeAvailable() { + if !testutil.SopsAndAgeAvailable() { Skip("sops and age-keygen not available") } @@ -102,13 +103,3 @@ postgres: Expect(configCmd.Flags().Lookup("age-key")).NotTo(BeNil()) }) }) - -func sopsAndAgeAvailable() bool { - if _, err := exec.LookPath("sops"); err != nil { - return false - } - if _, err := exec.LookPath("age-keygen"); err != nil { - return false - } - return true -} diff --git a/cli/cmd/testutil/testutil.go b/cli/cmd/testutil/testutil.go new file mode 100644 index 000000000..42e65e93d --- /dev/null +++ b/cli/cmd/testutil/testutil.go @@ -0,0 +1,16 @@ +// Copyright (c) Codesphere Inc. +// SPDX-License-Identifier: Apache-2.0 + +package testutil + +import "os/exec" + +func SopsAndAgeAvailable() bool { + if _, err := exec.LookPath("sops"); err != nil { + return false + } + if _, err := exec.LookPath("age-keygen"); err != nil { + return false + } + return true +} diff --git a/cli/cmd/update_install_config_test.go b/cli/cmd/update_install_config_test.go index 9a067bd4a..4b7a221b8 100644 --- a/cli/cmd/update_install_config_test.go +++ b/cli/cmd/update_install_config_test.go @@ -13,6 +13,7 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + "github.com/codesphere-cloud/oms/cli/cmd/testutil" "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/codesphere-cloud/oms/internal/installer" "github.com/codesphere-cloud/oms/internal/installer/files" @@ -41,7 +42,7 @@ var _ = Describe("UpdateInstallConfig", func() { ) BeforeEach(func() { - if !sopsAndAgeAvailableForUpdateInstallConfig() { + if !testutil.SopsAndAgeAvailable() { Skip("sops and age-keygen not available") } @@ -457,16 +458,6 @@ codesphere: }) }) -func sopsAndAgeAvailableForUpdateInstallConfig() bool { - if _, err := exec.LookPath("sops"); err != nil { - return false - } - if _, err := exec.LookPath("age-keygen"); err != nil { - return false - } - return true -} - var _ = Describe("SecretDependencyTracker", func() { var tracker *SecretDependencyTracker