Skip to content

Commit

Permalink
Adding integration tests (#77)
Browse files Browse the repository at this point in the history
* fix staticcheck issues

Signed-off-by: Amelia Downs <[email protected]>
Co-authored-by: Amelia Downs <[email protected]>

* add integration tests from docker_driver_integration_tests repo

Signed-off-by: Amelia Downs <[email protected]>
Co-authored-by: Amelia Downs <[email protected]>

* vendor dependancies

Signed-off-by: Amin Jamali <[email protected]>
Co-authored-by: Amin Jamali <[email protected]>

* Use a single config for running integration

Signed-off-by: Amelia Downs <[email protected]>
Co-authored-by: Amelia Downs <[email protected]>

* Various fixes for test suites to run properly

Signed-off-by: Amelia Downs <[email protected]>
Co-authored-by: Amelia Downs <[email protected]>

* Update test to skip for smb when running nfs fixture

Signed-off-by: Amelia Downs <[email protected]>
Co-authored-by: Amelia Downs <[email protected]>

* Add bin/test.bash

* fix more staticcheck errors

* Add scripts dir for local testing

---------

Signed-off-by: Amelia Downs <[email protected]>
Signed-off-by: Amin Jamali <[email protected]>
Co-authored-by: Amelia Downs <[email protected]>
  • Loading branch information
winkingturtle-vmw and ameowlia authored Aug 19, 2024
1 parent 441e44b commit 9ef6bef
Show file tree
Hide file tree
Showing 921 changed files with 538,485 additions and 91 deletions.
8 changes: 8 additions & 0 deletions bin/test.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

set -eu
set -o pipefail

# shellcheck disable=SC2068
# Double-quoting array expansion here causes ginkgo to fail
go run github.com/onsi/ginkgo/v2/ginkgo ${@} --skip-package integration
1 change: 1 addition & 0 deletions driverhttp/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func EnvWithMonitor(logger lager.Logger, ctx context.Context, res http.ResponseW

env := NewHttpDriverEnv(logger, cancelCtx)

//lint:ignore SA1019 "too lazy to fix right now"
if closer, ok := res.(http.CloseNotifier); ok {
// Note: make calls in this thread to ensure reference on context
doneOrTimeoutChannel := ctx.Done()
Expand Down
117 changes: 37 additions & 80 deletions driverhttp/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,11 @@ var _ = Describe("Docker Driver Handlers", func() {
driver.ActivateStub = func(env dockerdriver.Env) dockerdriver.ActivateResponse {
ctx := env.Context()
logger := env.Logger()
for true {
time.Sleep(time.Second * 1)

select {
case <-ctx.Done():
logger.Error("from-ctx", ctx.Err())
return dockerdriver.ActivateResponse{Err: ctx.Err().Error()}
}
}
return dockerdriver.ActivateResponse{}
time.Sleep(time.Second * 1)

<-ctx.Done()
logger.Error("from-ctx", ctx.Err())
return dockerdriver.ActivateResponse{Err: ctx.Err().Error()}
}
wg.Add(2)

Expand Down Expand Up @@ -229,16 +224,10 @@ var _ = Describe("Docker Driver Handlers", func() {
driver.ListStub = func(env dockerdriver.Env) dockerdriver.ListResponse {
ctx := env.Context()
logger := env.Logger()
for true {
time.Sleep(time.Second * 1)

select {
case <-ctx.Done():
logger.Error("from-ctx", ctx.Err())
return dockerdriver.ListResponse{Err: ctx.Err().Error()}
}
}
return dockerdriver.ListResponse{}
time.Sleep(time.Second * 1)
<-ctx.Done()
logger.Error("from-ctx", ctx.Err())
return dockerdriver.ListResponse{Err: ctx.Err().Error()}
}
wg.Add(2)

Expand Down Expand Up @@ -285,6 +274,7 @@ var _ = Describe("Docker Driver Handlers", func() {
var ExpectMountPointToEqual = func(value string) dockerdriver.MountResponse {
mountResponse := dockerdriver.MountResponse{}
body, err := io.ReadAll(res.Body)
Expect(err).ToNot(HaveOccurred())

err = json.Unmarshal(body, &mountResponse)
Expect(err).ToNot(HaveOccurred())
Expand Down Expand Up @@ -347,16 +337,10 @@ var _ = Describe("Docker Driver Handlers", func() {
driver.MountStub = func(env dockerdriver.Env, mountRequest dockerdriver.MountRequest) dockerdriver.MountResponse {
ctx := env.Context()
logger := env.Logger()
for true {
time.Sleep(time.Second * 1)

select {
case <-ctx.Done():
logger.Error("from-ctx", ctx.Err())
return dockerdriver.MountResponse{Err: ctx.Err().Error()}
}
}
return dockerdriver.MountResponse{}
time.Sleep(time.Second * 1)
<-ctx.Done()
logger.Error("from-ctx", ctx.Err())
return dockerdriver.MountResponse{Err: ctx.Err().Error()}
}
wg.Add(2)

Expand Down Expand Up @@ -440,16 +424,10 @@ var _ = Describe("Docker Driver Handlers", func() {
driver.UnmountStub = func(env dockerdriver.Env, unmountRequest dockerdriver.UnmountRequest) dockerdriver.ErrorResponse {
ctx := env.Context()
logger := env.Logger()
for true {
time.Sleep(time.Second * 1)

select {
case <-ctx.Done():
logger.Error("from-ctx", ctx.Err())
return dockerdriver.ErrorResponse{Err: ctx.Err().Error()}
}
}
return dockerdriver.ErrorResponse{}
time.Sleep(time.Second * 1)
<-ctx.Done()
logger.Error("from-ctx", ctx.Err())
return dockerdriver.ErrorResponse{Err: ctx.Err().Error()}
}
wg.Add(2)

Expand Down Expand Up @@ -530,6 +508,7 @@ var _ = Describe("Docker Driver Handlers", func() {

getResponse := dockerdriver.GetResponse{}
body, err := io.ReadAll(res.Body)
Expect(err).ToNot(HaveOccurred())
err = json.Unmarshal(body, &getResponse)
Expect(err).ToNot(HaveOccurred())

Expand All @@ -543,16 +522,10 @@ var _ = Describe("Docker Driver Handlers", func() {
driver.GetStub = func(env dockerdriver.Env, getRequest dockerdriver.GetRequest) dockerdriver.GetResponse {
ctx := env.Context()
logger := env.Logger()
for true {
time.Sleep(time.Second * 1)

select {
case <-ctx.Done():
logger.Error("from-ctx", ctx.Err())
return dockerdriver.GetResponse{Err: ctx.Err().Error()}
}
}
return dockerdriver.GetResponse{}
time.Sleep(time.Second * 1)
<-ctx.Done()
logger.Error("from-ctx", ctx.Err())
return dockerdriver.GetResponse{Err: ctx.Err().Error()}
}
wg.Add(2)

Expand Down Expand Up @@ -634,6 +607,7 @@ var _ = Describe("Docker Driver Handlers", func() {

pathResponse := dockerdriver.PathResponse{}
body, err := io.ReadAll(res.Body)
Expect(err).ToNot(HaveOccurred())
err = json.Unmarshal(body, &pathResponse)
Expect(err).ToNot(HaveOccurred())

Expand All @@ -646,16 +620,10 @@ var _ = Describe("Docker Driver Handlers", func() {
driver.PathStub = func(env dockerdriver.Env, pathRequest dockerdriver.PathRequest) dockerdriver.PathResponse {
ctx := env.Context()
logger := env.Logger()
for true {
time.Sleep(time.Second * 1)

select {
case <-ctx.Done():
logger.Error("from-ctx", ctx.Err())
return dockerdriver.PathResponse{Err: ctx.Err().Error()}
}
}
return dockerdriver.PathResponse{}
time.Sleep(time.Second * 1)
<-ctx.Done()
logger.Error("from-ctx", ctx.Err())
return dockerdriver.PathResponse{Err: ctx.Err().Error()}
}
wg.Add(2)

Expand Down Expand Up @@ -743,16 +711,10 @@ var _ = Describe("Docker Driver Handlers", func() {
driver.CreateStub = func(env dockerdriver.Env, createRequest dockerdriver.CreateRequest) dockerdriver.ErrorResponse {
ctx := env.Context()
logger := env.Logger()
for true {
time.Sleep(time.Second * 1)

select {
case <-ctx.Done():
logger.Error("from-ctx", ctx.Err())
return dockerdriver.ErrorResponse{Err: ctx.Err().Error()}
}
}
return dockerdriver.ErrorResponse{}
time.Sleep(time.Second * 1)
<-ctx.Done()
logger.Error("from-ctx", ctx.Err())
return dockerdriver.ErrorResponse{Err: ctx.Err().Error()}
}
wg.Add(2)

Expand Down Expand Up @@ -840,16 +802,10 @@ var _ = Describe("Docker Driver Handlers", func() {
driver.RemoveStub = func(env dockerdriver.Env, removeRequest dockerdriver.RemoveRequest) dockerdriver.ErrorResponse {
ctx := env.Context()
logger := env.Logger()
for true {
time.Sleep(time.Second * 1)

select {
case <-ctx.Done():
logger.Error("from-ctx", ctx.Err())
return dockerdriver.ErrorResponse{Err: ctx.Err().Error()}
}
}
return dockerdriver.ErrorResponse{}
time.Sleep(time.Second * 1)
<-ctx.Done()
logger.Error("from-ctx", ctx.Err())
return dockerdriver.ErrorResponse{Err: ctx.Err().Error()}
}
wg.Add(2)

Expand Down Expand Up @@ -925,6 +881,7 @@ var _ = Describe("Docker Driver Handlers", func() {

capabilitiesResponse := dockerdriver.CapabilitiesResponse{}
body, err := io.ReadAll(res.Body)
Expect(err).ToNot(HaveOccurred())
err = json.Unmarshal(body, &capabilitiesResponse)
Expect(err).ToNot(HaveOccurred())

Expand Down
2 changes: 1 addition & 1 deletion driverhttp/remote_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ func (r *remoteClient) Path(env dockerdriver.Env, pathRequest dockerdriver.PathR
}

func (r *remoteClient) Unmount(env dockerdriver.Env, unmountRequest dockerdriver.UnmountRequest) dockerdriver.ErrorResponse {
logger := env.Logger().Session("mount")
logger := env.Logger().Session("unmount")
logger.Info("start")
defer logger.Info("end")

Expand Down
2 changes: 1 addition & 1 deletion driverhttp/remote_client_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ func NewRemoteClientFactory() RemoteClientFactory {

type remoteClientFactory struct{}

func (_ *remoteClientFactory) NewRemoteClient(url string, tls *dockerdriver.TLSConfig) (dockerdriver.Driver, error) {
func (*remoteClientFactory) NewRemoteClient(url string, tls *dockerdriver.TLSConfig) (dockerdriver.Driver, error) {
return NewRemoteClient(url, tls)
}
7 changes: 0 additions & 7 deletions driverhttp/remote_client_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,10 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
"github.com/tedsuo/ifrit"
ginkgomon "github.com/tedsuo/ifrit/ginkgomon_v2"
)

var debugServerAddress string
var localDriverPath string

var fakedriverServerPort int
var fakedriverProcess ifrit.Process
var tcpRunner *ginkgomon.Runner

func TestDriver(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Docker Driver Remote Client and Handlers Suite")
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ require (

require (
github.com/bmizerany/pat v0.0.0-20210406213842-e4b6760bdd6f // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
github.com/google/go-cmp v0.6.0 // indirect
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -673,8 +673,9 @@ github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90/go.mod h1:R/bRT+9gY/
github.com/fogleman/gg v1.3.0/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/go-fonts/dejavu v0.1.0/go.mod h1:4Wt4I4OU2Nq9asgDCteaAaWZOV24E+0/Pwo0gppep4g=
github.com/go-fonts/latin-modern v0.2.0/go.mod h1:rQVLdDMK+mK1xscDwsqM5J8U2jrRa3T0ecnM9pNujks=
Expand Down
38 changes: 38 additions & 0 deletions integration/compatibility/compatibility_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package compatibility_test

import (
"os/exec"
"testing"

"code.cloudfoundry.org/dockerdriver/integration"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gbytes"
"github.com/onsi/gomega/gexec"
)

var (
session *gexec.Session
)

func TestCompatibility(t *testing.T) {

RegisterFailHandler(Fail)
RunSpecs(t, "Compatibility Suite")
}

var _ = BeforeSuite(func() {

config, err := integration.LoadConfig()
Expect(err).NotTo(HaveOccurred())

cmd := exec.Command(config.Driver, config.DriverArgs...)

session, err = gexec.Start(cmd, GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())
Eventually(session.Out).Should(gbytes.Say("driver-server.started"))
})
var _ = AfterSuite(func() {
session.Interrupt()
Eventually(session).Should(gexec.Exit())
})
Loading

0 comments on commit 9ef6bef

Please sign in to comment.