Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jsafrane committed Feb 15, 2019
1 parent 1aea6cb commit 9c8de49
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
38 changes: 30 additions & 8 deletions pkg/connection/connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ package connection
import (
"context"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"reflect"
"testing"

Expand Down Expand Up @@ -52,7 +55,15 @@ func pbMatch(x interface{}) gomock.Matcher {
return &pbMatcher{v}
}

func createMockServer(t *testing.T) (*gomock.Controller, *driver.MockCSIDriver, *driver.MockIdentityServer, *driver.MockControllerServer, CSIConnection, error) {
func tempDir(t *testing.T) string {
dir, err := ioutil.TempDir("", "external-attacher-test-")
if err != nil {
t.Fatalf("Cannot create temporary directory: %s", err)
}
return dir
}

func createMockServer(t *testing.T, tmpdir string) (*gomock.Controller, *driver.MockCSIDriver, *driver.MockIdentityServer, *driver.MockControllerServer, CSIConnection, error) {
// Start the mock server
mockController := gomock.NewController(t)
identityServer := driver.NewMockIdentityServer(mockController)
Expand All @@ -61,11 +72,12 @@ func createMockServer(t *testing.T) (*gomock.Controller, *driver.MockCSIDriver,
Identity: identityServer,
Controller: controllerServer,
})
drv.Start()
drv.StartOnAddress("unix", filepath.Join(tmpdir, "csi.sock"))

// Create a client connection to it
addr := drv.Address()
csiConn, err := New(addr, 10)
t.Logf("adds: %s", addr)
csiConn, err := New(addr)
if err != nil {
return nil, nil, nil, nil, nil, err
}
Expand Down Expand Up @@ -106,7 +118,9 @@ func TestGetPluginInfo(t *testing.T) {
},
}

mockController, driver, identityServer, _, csiConn, err := createMockServer(t)
tmpdir := tempDir(t)
defer os.RemoveAll(tmpdir)
mockController, driver, identityServer, _, csiConn, err := createMockServer(t, tmpdir)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -244,7 +258,9 @@ func TestSupportsControllerPublish(t *testing.T) {
},
}

mockController, driver, _, controllerServer, csiConn, err := createMockServer(t)
tmpdir := tempDir(t)
defer os.RemoveAll(tmpdir)
mockController, driver, _, controllerServer, csiConn, err := createMockServer(t, tmpdir)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -351,7 +367,9 @@ func TestSupportsPluginControllerService(t *testing.T) {
},
}

mockController, driver, identityServer, _, csiConn, err := createMockServer(t)
tmpdir := tempDir(t)
defer os.RemoveAll(tmpdir)
mockController, driver, identityServer, _, csiConn, err := createMockServer(t, tmpdir)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -530,7 +548,9 @@ func TestAttach(t *testing.T) {
},
}

mockController, driver, _, controllerServer, csiConn, err := createMockServer(t)
tmpdir := tempDir(t)
defer os.RemoveAll(tmpdir)
mockController, driver, _, controllerServer, csiConn, err := createMockServer(t, tmpdir)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -635,7 +655,9 @@ func TestDetachAttach(t *testing.T) {
},
}

mockController, driver, _, controllerServer, csiConn, err := createMockServer(t)
tmpdir := tempDir(t)
defer os.RemoveAll(tmpdir)
mockController, driver, _, controllerServer, csiConn, err := createMockServer(t, tmpdir)
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/framework_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,6 @@ func (f *fakeCSIConnection) Close() error {
return fmt.Errorf("Not implemented")
}

func (f *fakeCSIConnection) Probe(ctx context.Context) error {
func (f *fakeCSIConnection) Probe(timeout time.Duration) error {
return nil
}

0 comments on commit 9c8de49

Please sign in to comment.