Skip to content

Commit c231fd2

Browse files
committed
test: Add e2e tests for the implementation
In this commit, e2e tests for the implementation are added. Signed-off-by: Hayato Kiwata <haytok@amazon.co.jp>
1 parent 4133789 commit c231fd2

5 files changed

+30
-5
lines changed

e2e/vm/config_darwin_test.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ import (
2222
"github.com/runfinch/finch/pkg/config"
2323
)
2424

25-
var finchConfigFilePath = os.Getenv("HOME") + "/.finch/finch.yaml"
25+
var (
26+
finchConfigFilePath = os.Getenv("HOME") + "/.finch/finch.yaml"
27+
finchConfigJSONPath = os.Getenv("HOME") + "/.finch/config.json"
28+
)
2629

2730
func limaDataDirPath(installed bool) string {
2831
limaConfigFilePath := defaultLimaDataDirPath

e2e/vm/config_windows_test.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,7 @@ import (
99
"path/filepath"
1010
)
1111

12-
var finchConfigFilePath = filepath.Join(os.Getenv("LOCALAPPDATA"), ".finch", "finch.yaml")
12+
var (
13+
finchConfigFilePath = filepath.Join(os.Getenv("LOCALAPPDATA"), ".finch", "finch.yaml")
14+
finchConfigJSONPath = filepath.Join(os.Getenv("LOCALAPPDATA"), ".finch", "config.json")
15+
)

e2e/vm/finch_config_file_test.go

+20-1
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,18 @@ import (
2020

2121
// testFinchConfigFile makes sure that DOCKER_CONFIG is properly set to ~/.finch so that related information
2222
// is written to ~/.finch/config.json file.
23-
var testFinchConfigFile = func(o *option.Option) {
23+
var testFinchConfigFile = func(o *option.Option, installed bool) {
2424
ginkgo.Describe("finch config file", func() {
25+
var vmType string
26+
27+
ginkgo.BeforeEach(func() {
28+
if runtime.GOOS == "windows" {
29+
vmType = "wsl2"
30+
} else {
31+
vmType = "vz"
32+
}
33+
})
34+
2535
ginkgo.It("should store login credentials", func() {
2636
filename := "htpasswd"
2737
registryImage := "public.ecr.aws/docker/library/registry:2"
@@ -74,5 +84,14 @@ var testFinchConfigFile = func(o *option.Option) {
7484
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
7585
gomega.Expect(string(configContent)).ShouldNot(gomega.ContainSubstring(registry))
7686
})
87+
88+
ginkgo.It("should refresh config.json if creds_helpers is not set in finch.yaml, but config.json is configured with credsStore", func() {
89+
resetVM(o)
90+
resetDisks(o, installed)
91+
writeFile(finchConfigFilePath, []byte(fmt.Sprintf("cpus: 6\nmemory: 4GiB\nvmType: %s\nrosetta: true", vmType)))
92+
writeFile(finchConfigJSONPath, []byte(`{"credsStore":"ecr-login"}`))
93+
command.New(o, virtualMachineRootCmd, "init").WithoutCheckingExitCode().WithTimeoutInSeconds(160).Run()
94+
gomega.Expect(string(readFile(finchConfigJSONPath))).Should(gomega.Equal(`{"auths":{}}`))
95+
})
7796
})
7897
}

e2e/vm/vm_darwin_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func TestVM(t *testing.T) {
6464
testVMLifecycle(o)
6565
testAdditionalDisk(o, *e2e.Installed)
6666
testConfig(o, *e2e.Installed)
67-
testFinchConfigFile(o)
67+
testFinchConfigFile(o, *e2e.Installed)
6868
testVersion(o)
6969
testNonDefaultOptions(o, *e2e.Installed)
7070
testSupportBundle(o)

e2e/vm/vm_windows_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func TestVM(t *testing.T) {
4444
ginkgo.Describe("", func() {
4545
testVMLifecycle(o)
4646
testAdditionalDisk(o, *e2e.Installed)
47-
testFinchConfigFile(o)
47+
testFinchConfigFile(o, *e2e.Installed)
4848
testVersion(o)
4949
testSupportBundle(o)
5050
testCredHelper(o, *e2e.Installed, *e2e.Registry)

0 commit comments

Comments
 (0)