Skip to content

Commit 5afd5a7

Browse files
committed
chore: add e2e tests
Signed-off-by: Arjun Raja Yogidas <[email protected]>
1 parent 55afe5b commit 5afd5a7

File tree

4 files changed

+177
-3
lines changed

4 files changed

+177
-3
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,5 @@ jobs:
109109
run: sudo bin/finch-daemon --debug --socket-owner $UID &
110110
- name: Run e2e test
111111
run: sudo make test-e2e
112+
- name: Run opa e2e tests
113+
run: sudo make test-e2e-opa

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,14 @@ test-e2e: linux
114114
TEST_E2E=1 \
115115
$(GINKGO) $(GFLAGS) ./e2e/...
116116

117+
.PHONY: test-e2e-opa
118+
test-e2e-opa: linux
119+
DOCKER_HOST="unix:///run/finch.sock" \
120+
DOCKER_API_VERSION="v1.41" \
121+
OPA_E2E=1 \
122+
TEST_E2E=1 \
123+
$(GINKGO) $(GFLAGS) ./e2e/...
124+
117125
.PHONY: licenses
118126
licenses:
119127
PATH=$(BIN):$(PATH) go-licenses report --template="scripts/third-party-license.tpl" --ignore github.com/runfinch ./... > THIRD_PARTY_LICENSES

e2e/e2e_test.go

Lines changed: 97 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package e2e
55

66
import (
7+
"fmt"
78
"os"
89
"testing"
910

@@ -15,11 +16,104 @@ import (
1516
"github.com/runfinch/finch-daemon/e2e/tests"
1617
)
1718

19+
// func TestRun(t *testing.T) {
20+
// if os.Getenv("TEST_E2E") != "1" {
21+
// t.Skip("E2E tests skipped. Set TEST_E2E=1 to run these tests")
22+
// }
23+
// // TODO : Make this configurable
24+
// runtimeExe := "nerdctl"
25+
// opt, _ := option.New([]string{runtimeExe, "-n", "finch"})
26+
27+
// ginkgo.SynchronizedBeforeSuite(func() []byte {
28+
// tests.SetupLocalRegistry(opt)
29+
// return nil
30+
// }, func(bytes []byte) {})
31+
32+
// ginkgo.SynchronizedAfterSuite(func() {
33+
// tests.CleanupLocalRegistry(opt)
34+
// // clean up everything after the local registry is cleaned up
35+
// command.RemoveAll(opt)
36+
// }, func() {})
37+
38+
// const description = "Finch Daemon Functional test"
39+
// ginkgo.Describe(description, func() {
40+
// // functional test for container APIs
41+
// tests.ContainerCreate(opt)
42+
// tests.ContainerStart(opt)
43+
// tests.ContainerStop(opt)
44+
// tests.ContainerRestart(opt)
45+
// tests.ContainerRemove(opt)
46+
// tests.ContainerList(opt)
47+
// tests.ContainerRename(opt)
48+
// tests.ContainerStats(opt)
49+
// tests.ContainerAttach(opt)
50+
// tests.ContainerLogs(opt)
51+
// tests.ContainerKill(opt)
52+
53+
// // functional test for volume APIs
54+
// tests.VolumeList(opt)
55+
// tests.VolumeInspect(opt)
56+
// tests.VolumeRemove(opt)
57+
58+
// // functional test for network APIs
59+
// tests.NetworkCreate(opt)
60+
// tests.NetworkRemove(opt)
61+
// tests.NetworkList(opt)
62+
// tests.NetworkInspect(opt)
63+
64+
// // functional test for image APIs
65+
// tests.ImageRemove(opt)
66+
// tests.ImagePush(opt)
67+
// tests.ImagePull(opt)
68+
69+
// // functional test for system api
70+
// tests.SystemVersion(opt)
71+
// tests.SystemEvents(opt)
72+
73+
// // functional test for distribution api
74+
// tests.DistributionInspect(opt)
75+
// })
76+
77+
// gomega.RegisterFailHandler(ginkgo.Fail)
78+
// ginkgo.RunSpecs(t, description)
79+
// }
80+
1881
func TestRun(t *testing.T) {
19-
if os.Getenv("TEST_E2E") != "1" {
20-
t.Skip("E2E tests skipped. Set TEST_E2E=1 to run these tests")
82+
if os.Getenv("OPA_E2E") == "1" {
83+
runOPATests(t)
84+
} else if os.Getenv("TEST_E2E") == "1" {
85+
runE2ETests(t)
86+
} else {
87+
t.Skip("E2E tests skipped. Set TEST_E2E=1 to run regular E2E tests or OPA_E2E=1 to run OPA tests")
2188
}
22-
// TODO : Make this configurable
89+
}
90+
91+
func runOPATests(t *testing.T) {
92+
runtimeExe := "nerdctl"
93+
opt, _ := option.New([]string{runtimeExe, "-n", "finch"})
94+
95+
ginkgo.SynchronizedBeforeSuite(func() []byte {
96+
tests.SetupLocalRegistry(opt)
97+
return nil
98+
}, func(bytes []byte) {})
99+
100+
ginkgo.SynchronizedAfterSuite(func() {
101+
tests.CleanupLocalRegistry(opt)
102+
// clean up everything after the local registry is cleaned up
103+
command.RemoveAll(opt)
104+
}, func() {})
105+
106+
const description = "Finch Daemon OPA E2E Tests"
107+
ginkgo.Describe(description, func() {
108+
tests.OpaMiddlewareTest(opt)
109+
fmt.Print(opt)
110+
})
111+
112+
gomega.RegisterFailHandler(ginkgo.Fail)
113+
ginkgo.RunSpecs(t, description)
114+
}
115+
116+
func runE2ETests(t *testing.T) {
23117
runtimeExe := "nerdctl"
24118
opt, _ := option.New([]string{runtimeExe, "-n", "finch"})
25119

e2e/tests/opa_middleware.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package tests
5+
6+
import (
7+
"encoding/json"
8+
"fmt"
9+
"net/http"
10+
11+
. "github.com/onsi/ginkgo/v2"
12+
. "github.com/onsi/gomega"
13+
"github.com/runfinch/common-tests/command"
14+
"github.com/runfinch/common-tests/option"
15+
16+
"github.com/runfinch/finch-daemon/api/types"
17+
"github.com/runfinch/finch-daemon/e2e/client"
18+
)
19+
20+
// OpaMiddlewareTest tests the OPA functionality.
21+
func OpaMiddlewareTest(opt *option.Option) {
22+
Describe("test opa middleware functionality", func() {
23+
var (
24+
uClient *http.Client
25+
version string
26+
wantContainerName string
27+
)
28+
BeforeEach(func() {
29+
// create a custom client to use http over unix sockets
30+
uClient = client.NewClient(GetDockerHostUrl())
31+
// get the docker api version that will be tested
32+
version = GetDockerApiVersion()
33+
wantContainerName = fmt.Sprintf("/%s", testContainerName)
34+
})
35+
AfterEach(func() {
36+
command.RemoveAll(opt)
37+
})
38+
It("should allow GET version API request", func() {
39+
res, err := uClient.Get(client.ConvertToFinchUrl("", "/version"))
40+
Expect(err).ShouldNot(HaveOccurred())
41+
jd := json.NewDecoder(res.Body)
42+
var v types.VersionInfo
43+
err = jd.Decode(&v)
44+
Expect(err).ShouldNot(HaveOccurred())
45+
Expect(v.Version).ShouldNot(BeNil())
46+
Expect(v.ApiVersion).Should(Equal("1.43"))
47+
fmt.Println(version)
48+
})
49+
50+
It("shold allow GET containers API request", func() {
51+
id := command.StdoutStr(opt, "run", "-d", "--name", testContainerName, defaultImage, "sleep", "infinity")
52+
want := []types.ContainerListItem{
53+
{
54+
Id: id[:12],
55+
Names: []string{wantContainerName},
56+
},
57+
}
58+
59+
res, err := uClient.Get(client.ConvertToFinchUrl(version, "/containers/json"))
60+
Expect(err).Should(BeNil())
61+
Expect(res.StatusCode).Should(Equal(http.StatusOK))
62+
var got []types.ContainerListItem
63+
err = json.NewDecoder(res.Body).Decode(&got)
64+
Expect(err).Should(BeNil())
65+
Expect(len(got)).Should(Equal(2))
66+
got = filterContainerList(got)
67+
Expect(got).Should(ContainElements(want))
68+
})
69+
})
70+
}

0 commit comments

Comments
 (0)