Revise CommandLine interface to contain libmachine client and store

Signed-off-by: Nathan LeClaire <nathan.leclaire@gmail.com>
This commit is contained in:
Nathan LeClaire 2015-11-13 13:26:31 -08:00
parent d65e23600e
commit 7b483fe0ee
3 changed files with 23 additions and 17 deletions

View File

@ -128,7 +128,6 @@ func main() {
},
}
// TODO: Close plugin servers in case of client panic.
if err := app.Run(os.Args); err != nil {
log.Error(err)
}

View File

@ -122,7 +122,6 @@ func (d *Driver) GetURL() (string, error) {
}
func (d *Driver) GetState() (state.State, error) {
address := net.JoinHostPort(d.IPAddress, strconv.Itoa(d.SSHPort))
_, err := net.DialTimeout("tcp", address, defaultTimeout)
var st state.State

View File

@ -3,16 +3,29 @@ package persist
import (
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
"testing"
"github.com/docker/machine/commands/mcndirs"
_ "github.com/docker/machine/drivers/none"
"github.com/docker/machine/drivers/none"
"github.com/docker/machine/libmachine/drivers"
"github.com/docker/machine/libmachine/hosttest"
"github.com/stretchr/testify/assert"
)
const (
storedDriverURL = "1.2.3.4"
)
type FakePluginDriverFactory struct {
drivers.Driver
}
func (fpdf *FakePluginDriverFactory) NewPluginDriver(string, []byte) (drivers.Driver, error) {
return fpdf.Driver, nil
}
func cleanup() {
os.RemoveAll(os.Getenv("MACHINE_STORAGE_PATH"))
}
@ -30,6 +43,11 @@ func getTestStore() Filestore {
Path: tmpDir,
CaCertPath: filepath.Join(tmpDir, "certs", "ca-cert.pem"),
CaPrivateKeyPath: filepath.Join(tmpDir, "certs", "ca-key.pem"),
PluginDriverFactory: &FakePluginDriverFactory{
&none.Driver{
URL: storedDriverURL,
},
},
}
}
@ -147,13 +165,9 @@ func TestStoreExists(t *testing.T) {
}
}
func TestStoreLoad(t *testing.T) {
func TestStoreSaveLoad(t *testing.T) {
defer cleanup()
expectedURL := "unix:///foo/baz"
flags := hosttest.GetTestDriverFlags()
flags.Data["url"] = expectedURL
store := getTestStore()
h, err := hosttest.GetDefaultTestHost()
@ -161,17 +175,13 @@ func TestStoreLoad(t *testing.T) {
t.Fatal(err)
}
if err := h.Driver.SetConfigFromFlags(flags); err != nil {
t.Fatal(err)
}
if err := store.Save(h); err != nil {
t.Fatal(err)
}
h, err = store.Load(h.Name)
if err != nil {
log.Fatal(err)
t.Fatal(err)
}
actualURL, err := h.GetURL()
@ -179,7 +189,5 @@ func TestStoreLoad(t *testing.T) {
t.Fatal(err)
}
if actualURL != expectedURL {
t.Fatalf("GetURL is not %q, got %q", expectedURL, actualURL)
}
assert.Equal(t, storedDriverURL, actualURL)
}