Skip to content

Commit 5e0bbf2

Browse files
authored
ci: minor e2e test improvements (#1687)
Signed-off-by: ayush-panta <ayushkp@amazon.com>
1 parent 6d6445a commit 5e0bbf2

File tree

6 files changed

+54
-1
lines changed

6 files changed

+54
-1
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ test-e2e-daemon:
333333
-@$(OUTDIR)/bin/$(BINARYNAME) vm stop -f || true
334334
-@$(OUTDIR)/bin/$(BINARYNAME) vm remove -f
335335
-@$(OUTDIR)/bin/$(BINARYNAME) vm init
336+
@echo '{}' > $(HOME)/.finch/config.json
336337

337338
cd $(FINCH_CORE_DIR)/src/finch-daemon && \
338339
STATIC=1 GOOS=linux GOARCH=$(GOARCH) make && \

e2e/container/container_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ package container
66

77
import (
88
"fmt"
9+
"os"
910
"os/exec"
11+
"path/filepath"
1012
"regexp"
1113
"runtime"
1214
"testing"
@@ -31,6 +33,20 @@ func TestContainer(t *testing.T) {
3133
}
3234

3335
ginkgo.SynchronizedBeforeSuite(func() []byte {
36+
// Set DOCKER_CONFIG to /.finch
37+
var finchConfigDir string
38+
if runtime.GOOS == "windows" {
39+
finchConfigDir = filepath.Join(os.Getenv("LOCALAPPDATA"), ".finch")
40+
} else {
41+
homeDir, _ := os.UserHomeDir()
42+
finchConfigDir = filepath.Join(homeDir, ".finch")
43+
}
44+
_ = os.MkdirAll(finchConfigDir, 0o700)
45+
o.UpdateEnv("DOCKER_CONFIG", finchConfigDir)
46+
// Ensure empty /.finch/config.json
47+
configPath := filepath.Join(finchConfigDir, "config.json")
48+
_ = os.WriteFile(configPath, []byte("{}"), 0o644)
49+
3450
if runtime.GOOS != "linux" {
3551
command.New(o, "vm", "stop", "-f").WithoutCheckingExitCode().WithTimeoutInSeconds(30).Run()
3652
time.Sleep(1 * time.Second)

e2e/container/cosign_test.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"os"
99
"path/filepath"
10+
"time"
1011

1112
"github.com/onsi/ginkgo/v2"
1213
"github.com/onsi/gomega"
@@ -45,14 +46,25 @@ var testCosign = func(o *option.Option) {
4546
htpasswdDir := filepath.Dir(ffs.CreateTempFile(filename, htpasswd))
4647
ginkgo.DeferCleanup(os.RemoveAll, htpasswdDir)
4748
port = fnet.GetFreePort()
48-
command.Run(o, "run",
49+
containerID := command.StdoutStr(o, "run",
4950
"-dp", fmt.Sprintf("%d:5000", port),
5051
"--name", "registry",
5152
"-v", fmt.Sprintf("%s:/auth", htpasswdDir),
5253
"-e", "REGISTRY_AUTH=htpasswd",
5354
"-e", "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm",
5455
"-e", fmt.Sprintf("REGISTRY_AUTH_HTPASSWD_PATH=/auth/%s", filename),
5556
registryImage)
57+
// Wait for container to be running
58+
tries := 0
59+
for command.StdoutStr(o, "inspect", "-f", "{{.State.Running}}", containerID) != "true" {
60+
if tries >= 5 {
61+
ginkgo.Fail("Registry container failed to start after 5 seconds")
62+
}
63+
time.Sleep(1 * time.Second)
64+
tries++
65+
}
66+
// Wait for registry service to be ready
67+
time.Sleep(10 * time.Second)
5668
registry = fmt.Sprintf(`localhost:%d`, port)
5769
tag = fmt.Sprintf(`%s/test-login:tag`, registry)
5870
})

e2e/vm/finch_config_file_remote_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,13 @@ var testFinchConfigFile = func(o *option.Option) {
4949
registryImage)
5050
ginkgo.DeferCleanup(command.Run, o, "rmi", "-f", registryImage)
5151
ginkgo.DeferCleanup(command.Run, o, "rm", "-f", registryContainer)
52+
tries := 0
5253
for command.StdoutStr(o, "inspect", "-f", "{{.State.Running}}", containerID) != "true" {
54+
if tries >= 5 {
55+
ginkgo.Fail("Registry container failed to start after 5 seconds")
56+
}
5357
time.Sleep(1 * time.Second)
58+
tries++
5459
}
5560
time.Sleep(10 * time.Second)
5661
registry := fmt.Sprintf(`localhost:%d`, port)

e2e/vm/vm_darwin_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ func TestVM(t *testing.T) {
3737
// Test Stopped -> Nonexistent
3838
// Test Nonexistent -> Running
3939
ginkgo.SynchronizedBeforeSuite(func() []byte {
40+
// Set DOCKER_CONFIG to /.finch
41+
homeDir, err := os.UserHomeDir()
42+
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
43+
finchConfigDir := filepath.Join(homeDir, ".finch")
44+
_ = os.MkdirAll(finchConfigDir, 0o700)
45+
o.UpdateEnv("DOCKER_CONFIG", finchConfigDir)
46+
// Ensure empty /.finch/config.json
47+
configPath := filepath.Join(finchConfigDir, "config.json")
48+
_ = os.WriteFile(configPath, []byte("{}"), 0o644)
49+
4050
resetDisks(o, *e2e.Installed)
4151
command.New(o, "vm", "stop", "-f").WithoutCheckingExitCode().WithTimeoutInSeconds(30).Run()
4252
time.Sleep(1 * time.Second)

e2e/vm/vm_windows_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ func TestVM(t *testing.T) {
3737
// Test Stopped -> Nonexistent
3838
// Test Nonexistent -> Running
3939
ginkgo.SynchronizedBeforeSuite(func() []byte {
40+
// Ensure DOCKER_CONFIG is set to %LOCALAPPDATA%\.finch
41+
finchRootDir := os.Getenv("LOCALAPPDATA")
42+
finchConfigDir := filepath.Join(finchRootDir, ".finch")
43+
_ = os.MkdirAll(finchConfigDir, 0o700)
44+
o.UpdateEnv("DOCKER_CONFIG", finchConfigDir)
45+
// Ensure empty /.finch/config.json
46+
configPath := filepath.Join(finchConfigDir, "config.json")
47+
_ = os.WriteFile(configPath, []byte("{}"), 0o644)
48+
4049
resetDisks(o, *e2e.Installed)
4150
command.New(o, "vm", "stop", "-f").WithoutCheckingExitCode().WithTimeoutInSeconds(30).Run()
4251
time.Sleep(1 * time.Second)

0 commit comments

Comments
 (0)