From a7635a322c59c60441d358112170882c387d90a2 Mon Sep 17 00:00:00 2001 From: Channing Gaddy Date: Tue, 8 Aug 2023 15:31:21 -0700 Subject: [PATCH] fixing lint and unit test issues Signed-off-by: Channing Gaddy --- e2e/vm/soci_test.go | 10 +++++----- pkg/config/lima_config_applier.go | 10 +++++----- pkg/config/lima_config_applier_test.go | 16 +++++++++++----- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/e2e/vm/soci_test.go b/e2e/vm/soci_test.go index 9dd7df1b9..a349c052f 100644 --- a/e2e/vm/soci_test.go +++ b/e2e/vm/soci_test.go @@ -21,7 +21,6 @@ const ( ) var testSoci = func(o *option.Option, installed bool) { - ginkgo.Describe("SOCI", func() { var limactlO *option.Option var limaHomePathEnv string @@ -47,7 +46,8 @@ var testSoci = func(o *option.Option, installed bool) { command.New(o, "pull", FfmpegSociImage).WithTimeoutInSeconds(30).Run() finchPullMounts := countMounts(limactlO) command.New(o, "rmi", "-f", FfmpegSociImage).WithTimeoutInSeconds(30).Run() - command.New(limactlO, "shell", "finch", "sudo", "nerdctl", "--snapshotter=soci", "pull", FfmpegSociImage).WithTimeoutInSeconds(30).Run().Out.Contents() + command.New(limactlO, "shell", "finch", + "sudo", "nerdctl", "--snapshotter=soci", "pull", FfmpegSociImage).WithTimeoutInSeconds(30).Run().Out.Contents() nerdctlPullMounts := countMounts(limactlO) command.New(o, "rmi", "-f", FfmpegSociImage).WithTimeoutInSeconds(30).Run() gomega.Expect(finchPullMounts).Should(gomega.Equal(nerdctlPullMounts)) @@ -63,16 +63,16 @@ var testSoci = func(o *option.Option, installed bool) { command.New(o, "run", FfmpegSociImage).WithTimeoutInSeconds(30).Run() finchPullMounts := countMounts(limactlO) command.New(o, "rmi", "-f", FfmpegSociImage).WithTimeoutInSeconds(30).Run() - command.New(limactlO, "shell", "finch", "sudo", "nerdctl", "--snapshotter=soci", "run", FfmpegSociImage).WithTimeoutInSeconds(30).Run().Out.Contents() + command.New(limactlO, "shell", "finch", + "sudo", "nerdctl", "--snapshotter=soci", "run", FfmpegSociImage).WithTimeoutInSeconds(30).Run().Out.Contents() nerdctlPullMounts := countMounts(limactlO) command.New(o, "rmi", "-f", FfmpegSociImage).WithTimeoutInSeconds(30).Run() gomega.Expect(finchPullMounts).Should(gomega.Equal(nerdctlPullMounts)) }) }) - } -// counts the mounts present in the VM after pulling an image +// counts the mounts present in the VM after pulling an image. func countMounts(limactlO *option.Option) int { mountOutput := string(command.New(limactlO, "shell", "finch", "mount").WithTimeoutInSeconds(30).Run().Out.Contents()) return strings.Count(mountOutput, sociMountString) diff --git a/pkg/config/lima_config_applier.go b/pkg/config/lima_config_applier.go index 317f6ba32..7b76481ff 100644 --- a/pkg/config/lima_config_applier.go +++ b/pkg/config/lima_config_applier.go @@ -20,7 +20,7 @@ const ( sociVersion = "0.3.0" sociInstallationProvisioningScriptHeader = "# soci installation and configuring" sociFileNameFormat = "soci-snapshotter-%s-linux-%s.tar.gz" - sociDownloadUrlFormat = "https://github.com/awslabs/soci-snapshotter/releases/download/v%s/%s" + sociDownloadURLFormat = "https://github.com/awslabs/soci-snapshotter/releases/download/v%s/%s" sociInstallationScriptFormat = `%s if [ ! -f /usr/local/bin/soci ]; then #download soci @@ -128,7 +128,7 @@ func (lca *limaConfigApplier) Apply(isInit bool) error { sociEnabled = (*lca.cfg.Snapshotter == "soci") } - toggleSoci(&limaCfg, sociEnabled, sociVersion, system.NewStdLib().Arch()) + toggleSoci(&limaCfg, sociEnabled, sociVersion) limaCfgBytes, err := yaml.Marshal(limaCfg) if err != nil { @@ -223,11 +223,11 @@ func hasUserModeEmulationInstallationScript(limaCfg *limayaml.LimaYAML) (int, bo return scriptIdx, hasCrossArchToolInstallationScript } -func toggleSoci(limaCfg *limayaml.LimaYAML, enabled bool, sociVersion string, arch string) { +func toggleSoci(limaCfg *limayaml.LimaYAML, enabled bool, sociVersion string) { idx, hasScript := hasSociInstallationScript(limaCfg) sociFileName := fmt.Sprintf(sociFileNameFormat, sociVersion, system.NewStdLib().Arch()) - sociDownloadUrl := fmt.Sprintf(sociDownloadUrlFormat, sociVersion, sociFileNameFormat) - sociInstallationScript := fmt.Sprintf(sociInstallationScriptFormat, sociInstallationProvisioningScriptHeader, sociDownloadUrl, sociFileName) + sociDownloadURL := fmt.Sprintf(sociDownloadURLFormat, sociVersion, sociFileName) + sociInstallationScript := fmt.Sprintf(sociInstallationScriptFormat, sociInstallationProvisioningScriptHeader, sociDownloadURL, sociFileName) if !hasScript && enabled { limaCfg.Env = map[string]string{"CONTAINERD_SNAPSHOTTER": "soci"} limaCfg.Provision = append(limaCfg.Provision, limayaml.Provision{ diff --git a/pkg/config/lima_config_applier_test.go b/pkg/config/lima_config_applier_test.go index c82dd2637..a6cd9003b 100644 --- a/pkg/config/lima_config_applier_test.go +++ b/pkg/config/lima_config_applier_test.go @@ -86,7 +86,8 @@ fi `, limaCfg.Provision[0].Script) }, want: nil, - }, { + }, + { name: "adds soci script when soci is set to true in config", config: &Finch{ Memory: pointer.String("2GiB"), @@ -114,8 +115,11 @@ fi require.NoError(t, err) sociFileName := fmt.Sprintf(sociFileNameFormat, sociVersion, system.NewStdLib().Arch()) - sociDownloadUrl := fmt.Sprintf(sociDownloadUrlFormat, sociVersion, sociFileName) - sociInstallationScript := fmt.Sprintf(sociInstallationScriptFormat, sociInstallationProvisioningScriptHeader, sociDownloadUrl, sociFileName) + sociDownloadURL := fmt.Sprintf(sociDownloadURLFormat, sociVersion, sociFileName) + sociInstallationScript := fmt.Sprintf(sociInstallationScriptFormat, + sociInstallationProvisioningScriptHeader, + sociDownloadURL, + sociFileName) var limaCfg limayaml.LimaYAML err = yaml.Unmarshal(buf, &limaCfg) @@ -144,7 +148,8 @@ fi `, limaCfg.Provision[0].Script) }, want: nil, - }, { + }, + { name: "doesn't add soci script when soci is set to false in config", config: &Finch{ Memory: pointer.String("2GiB"), @@ -197,7 +202,8 @@ fi `, limaCfg.Provision[0].Script) }, want: nil, - }, { + }, + { name: "updates vmType and removes cross-arch provisioning script and network config", config: &Finch{ Memory: pointer.String("2GiB"),