Skip to content

Commit 5ccb0e8

Browse files
author
Joshua Anderson
committed
test(deisctl): add tests for CMD package
1 parent 7576748 commit 5ccb0e8

5 files changed

Lines changed: 379 additions & 60 deletions

File tree

deisctl/client/client.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/deis/deis/deisctl/backend"
99
"github.com/deis/deis/deisctl/backend/fleet"
1010
"github.com/deis/deis/deisctl/cmd"
11+
"github.com/deis/deis/deisctl/units"
1112

1213
docopt "github.com/docopt/docopt-go"
1314
)
@@ -126,7 +127,7 @@ Usage:
126127
return err
127128
}
128129

129-
return cmd.Install(args["<target>"].([]string), c.Backend)
130+
return cmd.Install(args["<target>"].([]string), c.Backend, cmd.CheckRequiredKeys)
130131
}
131132

132133
// Journal prints log output for the specified components.
@@ -186,7 +187,7 @@ Options:
186187
os.Exit(2)
187188
}
188189

189-
return cmd.RefreshUnits(args["--path"].(string), args["--tag"].(string))
190+
return cmd.RefreshUnits(args["--path"].(string), args["--tag"].(string), units.URL)
190191
}
191192

192193
// Restart stops and then starts components.

deisctl/cmd/cmd.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@ func ListUnits(b backend.Backend) error {
3131
}
3232

3333
// ListUnitFiles prints the contents of all defined unit files.
34-
func ListUnitFiles(argv []string, b backend.Backend) error {
35-
err := b.ListUnitFiles()
36-
return err
34+
func ListUnitFiles(b backend.Backend) error {
35+
return b.ListUnitFiles()
3736
}
3837

3938
// Scale grows or shrinks the number of running components.
@@ -50,9 +49,9 @@ func Scale(targets []string, b backend.Backend) error {
5049
if err != nil {
5150
return err
5251
}
53-
// the router is the only component that can scale at the moment
52+
// the router, registry, and store-gateway are the only component that can scale at the moment
5453
if !strings.Contains(component, "router") && !strings.Contains(component, "registry") && !strings.Contains(component, "store-gateway") {
55-
return fmt.Errorf("cannot scale %s components", component)
54+
return fmt.Errorf("cannot scale %s component", component)
5655
}
5756
b.Scale(component, num, &wg, outchan, errchan)
5857
wg.Wait()
@@ -88,8 +87,8 @@ func Start(targets []string, b backend.Backend) error {
8887
return nil
8988
}
9089

91-
// checkRequiredKeys exist in etcd
92-
func checkRequiredKeys() error {
90+
// CheckRequiredKeys exist in etcd
91+
func CheckRequiredKeys() error {
9392
if err := config.CheckConfig("/deis/platform/", "domain"); err != nil {
9493
return fmt.Errorf(`Missing platform domain, use:
9594
deisctl config platform set domain=<your-domain>`)
@@ -243,12 +242,12 @@ func Journal(targets []string, b backend.Backend) error {
243242

244243
// Install loads the definitions of components from local unit files.
245244
// After Install, the components will be available to Start.
246-
func Install(targets []string, b backend.Backend) error {
245+
func Install(targets []string, b backend.Backend, checkKeys func() error) error {
247246

248247
// if target is platform, install all services
249248
if len(targets) == 1 {
250249
if targets[0] == PlatformCommand {
251-
return InstallPlatform(b)
250+
return InstallPlatform(b, checkKeys)
252251
}
253252
if targets[0] == swarm {
254253
return InstallSwarm(b)
@@ -290,6 +289,7 @@ func installDefaultServices(b backend.Backend, wg *sync.WaitGroup, outchan chan
290289
outchan <- fmt.Sprintf("Routing mesh...")
291290
b.Create([]string{"router@1", "router@2", "router@3"}, wg, outchan, errchan)
292291
wg.Wait()
292+
293293
}
294294

295295
// Uninstall unloads the definitions of the specified components.
@@ -405,16 +405,15 @@ func Config(target string, action string, key []string) error {
405405
// RefreshUnits overwrites local unit files with those requested.
406406
// Downloading from the Deis project GitHub URL by tag or SHA is the only mechanism
407407
// currently supported.
408-
func RefreshUnits(dir string, tag string) error {
408+
func RefreshUnits(dir, tag, url string) error {
409409
dir = utils.ResolvePath(dir)
410410
// create the target dir if necessary
411411
if err := os.MkdirAll(dir, 0755); err != nil {
412412
return err
413413
}
414414
// download and save the unit files to the specified path
415-
rootURL := "https://raw.githubusercontent.com/deis/deis/"
416415
for _, unit := range units.Names {
417-
src := rootURL + tag + "/deisctl/units/" + unit + ".service"
416+
src := fmt.Sprintf(url, tag, unit)
418417
dest := filepath.Join(dir, unit+".service")
419418
res, err := http.Get(src)
420419
if err != nil {

0 commit comments

Comments
 (0)