Skip to content

Commit

Permalink
fixing lint and unit test issues
Browse files Browse the repository at this point in the history
Signed-off-by: Channing Gaddy <[email protected]>
  • Loading branch information
CodeChanning committed Aug 8, 2023
1 parent 65f7029 commit a7635a3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
10 changes: 5 additions & 5 deletions e2e/vm/soci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const (
)

var testSoci = func(o *option.Option, installed bool) {

ginkgo.Describe("SOCI", func() {
var limactlO *option.Option
var limaHomePathEnv string
Expand All @@ -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))
Expand All @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions pkg/config/lima_config_applier.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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{
Expand Down
16 changes: 11 additions & 5 deletions pkg/config/lima_config_applier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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"),
Expand Down

0 comments on commit a7635a3

Please sign in to comment.