|
| 1 | +package mcndirs |
| 2 | + |
| 3 | +import ( |
| 4 | + "path" |
| 5 | + "strings" |
| 6 | + "testing" |
| 7 | + |
| 8 | + "github.com/docker/machine/libmachine/mcnutils" |
| 9 | +) |
| 10 | + |
| 11 | +func TestGetBaseDir(t *testing.T) { |
| 12 | + // reset any override env var |
| 13 | + BaseDir = "" |
| 14 | + |
| 15 | + homeDir := mcnutils.GetHomeDir() |
| 16 | + baseDir := GetBaseDir() |
| 17 | + |
| 18 | + if strings.Index(baseDir, homeDir) != 0 { |
| 19 | + t.Fatalf("expected base dir with prefix %s; received %s", homeDir, baseDir) |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | +func TestGetCustomBaseDir(t *testing.T) { |
| 24 | + root := "/tmp" |
| 25 | + BaseDir = root |
| 26 | + baseDir := GetBaseDir() |
| 27 | + |
| 28 | + if strings.Index(baseDir, root) != 0 { |
| 29 | + t.Fatalf("expected base dir with prefix %s; received %s", root, baseDir) |
| 30 | + } |
| 31 | + BaseDir = "" |
| 32 | +} |
| 33 | + |
| 34 | +func TestGetMachineDir(t *testing.T) { |
| 35 | + root := "/tmp" |
| 36 | + BaseDir = root |
| 37 | + machineDir := GetMachineDir() |
| 38 | + |
| 39 | + if strings.Index(machineDir, root) != 0 { |
| 40 | + t.Fatalf("expected machine dir with prefix %s; received %s", root, machineDir) |
| 41 | + } |
| 42 | + |
| 43 | + path, filename := path.Split(machineDir) |
| 44 | + if strings.Index(path, root) != 0 { |
| 45 | + t.Fatalf("expected base path of %s; received %s", root, path) |
| 46 | + } |
| 47 | + if filename != "machines" { |
| 48 | + t.Fatalf("expected machine dir \"machines\"; received %s", filename) |
| 49 | + } |
| 50 | + BaseDir = "" |
| 51 | +} |
| 52 | + |
| 53 | +func TestGetMachineCertDir(t *testing.T) { |
| 54 | + root := "/tmp" |
| 55 | + BaseDir = root |
| 56 | + clientDir := GetMachineCertDir() |
| 57 | + |
| 58 | + if strings.Index(clientDir, root) != 0 { |
| 59 | + t.Fatalf("expected machine client cert dir with prefix %s; received %s", root, clientDir) |
| 60 | + } |
| 61 | + |
| 62 | + path, filename := path.Split(clientDir) |
| 63 | + if strings.Index(path, root) != 0 { |
| 64 | + t.Fatalf("expected base path of %s; received %s", root, path) |
| 65 | + } |
| 66 | + if filename != "certs" { |
| 67 | + t.Fatalf("expected machine client dir \"certs\"; received %s", filename) |
| 68 | + } |
| 69 | + BaseDir = "" |
| 70 | +} |
0 commit comments