-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored based on code review comments (WiP)
Signed-off-by: Mohamed Mohamed <mmohamed@us.ibm.com>
- Loading branch information
Showing
30 changed files
with
387 additions
and
503 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pkg | ||
bin | ||
*coverprofile | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package voldriver | ||
import ( | ||
"github.com/cloudfoundry-incubator/volman/system" | ||
"github.com/cloudfoundry-incubator/volman" | ||
"github.com/pivotal-golang/lager" | ||
"fmt" | ||
) | ||
|
||
type DriverClientCli struct { | ||
UseExec system.Exec | ||
DriversPath string | ||
Name string | ||
} | ||
|
||
func NewDriverClientCli(path string, useExec system.Exec, name string) *DriverClientCli{ | ||
return &DriverClientCli{ | ||
UseExec: useExec, | ||
DriversPath: path, | ||
Name: name, | ||
} | ||
} | ||
|
||
func (client *DriverClientCli) Mount(logger lager.Logger, volumeId string, config string) (string, error) { | ||
logger.Info("start") | ||
defer logger.Info("end") | ||
response := struct { | ||
Path string `json:"path"` | ||
}{} | ||
invoker := NewCliInvoker(client.UseExec, fmt.Sprintf("%s/%s",client.DriversPath,client.Name), "mount", volumeId, config) | ||
err := invoker.InvokeDriver(logger, &response) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return response.Path, nil | ||
} | ||
|
||
|
||
func (client *DriverClientCli) Info(logger lager.Logger) (volman.DriverInfo, error) { | ||
logger.Info("start") | ||
defer logger.Info("end") | ||
response := volman.DriverInfo{} | ||
invoker := NewCliInvoker(client.UseExec, fmt.Sprintf("%s/%s",client.DriversPath,client.Name), "info") | ||
err := invoker.InvokeDriver(logger, &response) | ||
if err != nil { | ||
return volman.DriverInfo{}, err | ||
} | ||
return response, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package voldriver_test | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/cloudfoundry-incubator/volman" | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
"github.com/onsi/gomega/gexec" | ||
|
||
"testing" | ||
) | ||
|
||
var client volman.Manager | ||
var fakeDriverPath string | ||
|
||
func TestDriver(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Driver Suite") | ||
} | ||
|
||
var _ = SynchronizedBeforeSuite(func() []byte { | ||
var err error | ||
|
||
fakeDriverPath, err = gexec.Build("github.com/cloudfoundry-incubator/volman/fakedriver", "-race") | ||
Expect(err).NotTo(HaveOccurred()) | ||
return []byte(strings.Join([]string{fakeDriverPath}, ",")) | ||
}, func(pathsByte []byte) { | ||
path := string(pathsByte) | ||
fakeDriverPath = filepath.Dir(strings.Split(path, ",")[0]) | ||
}) | ||
|
||
var _ = SynchronizedAfterSuite(func() { | ||
|
||
}, func() { | ||
gexec.CleanupBuildArtifacts() | ||
}) | ||
|
||
// testing support types: | ||
|
||
type errCloser struct{ io.Reader } | ||
|
||
func (errCloser) Close() error { return nil } | ||
func (errCloser) Read(p []byte) (n int, err error) { return 0, fmt.Errorf("any") } | ||
|
||
type stringCloser struct{ io.Reader } | ||
|
||
func (stringCloser) Close() error { return nil } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package voldriver_test | ||
|
||
import ( | ||
"bytes" | ||
"io" | ||
|
||
"github.com/cloudfoundry-incubator/volman" | ||
"github.com/cloudfoundry-incubator/volman/voldriver" | ||
"github.com/cloudfoundry-incubator/volman/volmanfakes" | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
"github.com/pivotal-golang/lager/lagertest" | ||
|
||
) | ||
|
||
var _ = Describe("DriverClientCli", func() { | ||
var client volman.DriverPlugin | ||
var fakeCmd *volmanfakes.FakeCmd | ||
var fakeExec *volmanfakes.FakeExec | ||
var validDriverInfoResponse io.ReadCloser | ||
|
||
// Context("when given invalid driver path", func() { | ||
// BeforeEach(func() { | ||
// fakeExec = new(volmanfakes.FakeExec) | ||
// fakeCmd = new(volmanfakes.FakeCmd) | ||
// fakeExec.CommandReturns(fakeCmd) | ||
|
||
// validDriverInfoResponse = stringCloser{bytes.NewBufferString("{\"Name\":\"SomeDriver\"}")} | ||
|
||
// client = &voldriver.DriverClientCli{fakeExec, fakeDriverPath} | ||
// }) | ||
|
||
|
||
// It("should not be able to mount", func() { | ||
// fakeCmd.StdoutPipeReturns(errCloser{bytes.NewBufferString("")}, nil) | ||
// testLogger := lagertest.NewTestLogger("ClientTest") | ||
// driver := volman.Driver{ | ||
// Name: "SomeDriver", | ||
// } | ||
// volumeId := "fake-volume" | ||
// config := "Here is some config!" | ||
|
||
// _, err := client.Mount(testLogger, driver, volumeId, config) | ||
// Expect(err).To(HaveOccurred()) | ||
// }) | ||
// }) | ||
|
||
Context("when given valid driver path", func() { | ||
BeforeEach(func() { | ||
fakeExec = new(volmanfakes.FakeExec) | ||
fakeCmd = new(volmanfakes.FakeCmd) | ||
fakeExec.CommandReturns(fakeCmd) | ||
|
||
validDriverInfoResponse = stringCloser{bytes.NewBufferString("{\"Name\":\"SomeDriver\"}")} | ||
|
||
client = &voldriver.DriverClientCli{fakeExec,fakeDriverPath,"fakedriver"} | ||
}) | ||
|
||
It("should not error on get driver info", func() { | ||
var validDriverMountResponse = stringCloser{bytes.NewBufferString("{\"Path\":\"/MountPoint\"}")} | ||
var stdOutResponses = [...]io.ReadCloser{validDriverMountResponse, validDriverInfoResponse} | ||
|
||
calls := 0 | ||
fakeCmd.StdoutPipeStub = func() (io.ReadCloser, error) { | ||
defer func() { calls++ }() | ||
return stdOutResponses[calls], nil | ||
} | ||
|
||
testLogger := lagertest.NewTestLogger("ClientTest") | ||
|
||
_,err := client.Info(testLogger) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
}) | ||
|
||
It("should be able to mount", func() { | ||
var validDriverMountResponse = stringCloser{bytes.NewBufferString("{\"Path\":\"/MountPoint\"}")} | ||
var stdOutResponses = [...]io.ReadCloser{validDriverMountResponse, validDriverInfoResponse} | ||
|
||
calls := 0 | ||
fakeCmd.StdoutPipeStub = func() (io.ReadCloser, error) { | ||
defer func() { calls++ }() | ||
return stdOutResponses[calls], nil | ||
} | ||
|
||
testLogger := lagertest.NewTestLogger("ClientTest") | ||
volumeId := "fake-volume" | ||
config := "Here is some config!" | ||
|
||
mountPath, err := client.Mount(testLogger, volumeId, config) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(mountPath).To(Equal("/MountPoint")) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.