Skip to content

Commit c155d25

Browse files
author
Matthew Fisher
committed
Merge pull request #2770 from bacongobbler/hookup-deisctl-tests
Hookup deisctl tests
2 parents 9d5ad5b + 697c5ec commit c155d25

10 files changed

Lines changed: 48 additions & 24 deletions

File tree

Makefile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,14 @@ release: check-registry
6767

6868
deploy: build dev-release restart
6969

70-
test: test-components push test-integration
70+
test: test-unit test-functional push test-integration
7171

72-
test-components:
73-
@$(foreach C, $(COMPONENTS), $(MAKE) -C $(C) test &&) echo done
72+
test-functional:
73+
@$(foreach C, $(COMPONENTS), $(MAKE) -C $(C) test-functional &&) echo done
74+
75+
test-unit:
76+
@$(foreach C, $(COMPONENTS), $(MAKE) -C $(C) test-unit &&) echo done
77+
@$(foreach C, $(CLIENTS), $(MAKE) -C $(C) test-unit &&) echo done
7478

7579
test-integration:
7680
$(MAKE) -C tests/ test-full

client/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,6 @@ setup-venv:
3636

3737
test-style: setup-venv
3838
venv/bin/flake8
39+
40+
test-unit:
41+
@echo no unit tests

deisctl/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,7 @@ test-style:
3636
go vet ./...
3737
-golint ./...
3838

39-
test: test-style
39+
test-unit:
4040
godep go test -v -cover ./...
41+
42+
test: test-style test-unit

deisctl/backend/fleet/ssh.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
func runCommand(cmd string, machID string) (retcode int) {
1818
var err error
1919
if machine.IsLocalMachineID(machID) {
20-
err, retcode = runLocalCommand(cmd)
20+
retcode, err = runLocalCommand(cmd)
2121
if err != nil {
2222
fmt.Printf("Error running local command: %v\n", err)
2323
}
@@ -27,7 +27,7 @@ func runCommand(cmd string, machID string) (retcode int) {
2727
fmt.Printf("Error getting machine IP: %v\n", err)
2828
} else {
2929
sshTimeout := time.Duration(Flags.SSHTimeout*1000) * time.Millisecond
30-
err, retcode = runRemoteCommand(cmd, ms.PublicIP, sshTimeout)
30+
retcode, err = runRemoteCommand(cmd, ms.PublicIP, sshTimeout)
3131
if err != nil {
3232
fmt.Printf("Error running remote command: %v\n", err)
3333
}
@@ -37,7 +37,7 @@ func runCommand(cmd string, machID string) (retcode int) {
3737
}
3838

3939
// runLocalCommand runs the given command locally and returns any error encountered and the exit code of the command
40-
func runLocalCommand(cmd string) (error, int) {
40+
func runLocalCommand(cmd string) (int, error) {
4141
cmdSlice := strings.Split(cmd, " ")
4242
osCmd := exec.Command(cmdSlice[0], cmdSlice[1:]...)
4343
osCmd.Stderr = os.Stderr
@@ -48,31 +48,32 @@ func runLocalCommand(cmd string) (error, int) {
4848
// Get the command's exit status if we can
4949
if exiterr, ok := err.(*exec.ExitError); ok {
5050
if status, ok := exiterr.Sys().(syscall.WaitStatus); ok {
51-
return nil, status.ExitStatus()
51+
return status.ExitStatus(), nil
5252
}
5353
}
5454
// Otherwise, generic command error
55-
return err, -1
55+
return -1, err
5656
}
57-
return nil, 0
57+
return 0, nil
5858
}
5959

6060
// runRemoteCommand runs the given command over SSH on the given IP, and returns
6161
// any error encountered and the exit status of the command
62-
func runRemoteCommand(cmd string, addr string, timeout time.Duration) (err error, exit int) {
62+
func runRemoteCommand(cmd string, addr string, timeout time.Duration) (exit int, err error) {
6363
var sshClient *ssh.SSHForwardingClient
6464
if tun := getTunnelFlag(); tun != "" {
6565
sshClient, err = ssh.NewTunnelledSSHClient("core", tun, addr, getChecker(), false, timeout)
6666
} else {
6767
sshClient, err = ssh.NewSSHClient("core", addr, getChecker(), false, timeout)
6868
}
6969
if err != nil {
70-
return err, -1
70+
return -1, err
7171
}
7272

7373
defer sshClient.Close()
7474

75-
return ssh.Execute(sshClient, cmd)
75+
err, exit = ssh.Execute(sshClient, cmd)
76+
return
7677
}
7778

7879
func machineState(machID string) (*machine.MachineState, error) {

deisctl/deisctl.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,8 @@ Options:
6363
if helpFlag {
6464
fmt.Print(usage)
6565
return 0
66-
} else {
67-
return 1
6866
}
67+
return 1
6968
}
7069
command := args["<command>"]
7170
setTunnel := true
@@ -181,7 +180,7 @@ func parseArgs(argv []string) ([]string, bool) {
181180
// removeGlobalArgs returns the given args without any global option flags, to make
182181
// re-parsing by subcommands easier.
183182
func removeGlobalArgs(argv []string) []string {
184-
v := make([]string, 0)
183+
var v []string
185184
for _, a := range argv {
186185
if !isGlobalArg(a) {
187186
v = append(v, a)

deisctl/deisctl_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func TestHelp(t *testing.T) {
3535
out := ""
3636
for _, args := range allArgs {
3737
out = commandOutput(args)
38-
if !strings.Contains(out, "Usage: deisctl <command> [<args>...] [options]") ||
38+
if !strings.Contains(out, "Usage: deisctl [options] <command> [<args>...]") ||
3939
!strings.Contains(out, "Commands, use \"deisctl help <command>\" to learn more") {
4040
t.Error(out)
4141
}
@@ -45,7 +45,7 @@ func TestHelp(t *testing.T) {
4545
// TestUsage ensures that deisctl prints a short usage string when no arguments were provided.
4646
func TestUsage(t *testing.T) {
4747
out := commandOutput(nil)
48-
if out != "Usage: deisctl <command> [<args>...] [options]\n" {
48+
if out != "Usage: deisctl [options] <command> [<args>...]\n" {
4949
t.Error(out)
5050
}
5151
}

publisher/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ stop: check-deisctl
4949

5050
test: test-unit
5151

52+
test-functional:
53+
@echo no functional tests
54+
5255
test-unit:
5356
godep go test -v ./...
5457

tests/bin/test-acceptance.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ log_phase "Running documentation tests"
2222
# test building documentation
2323
make -C docs/ test
2424

25+
log_phase "Running unit tests"
26+
27+
make test-unit
28+
2529
log_phase "Building from current source tree"
2630

2731
# build all docker images and client binaries
@@ -30,9 +34,9 @@ make build
3034
# use the built client binaries
3135
export PATH=$DEIS_ROOT/deisctl:$DEIS_ROOT/client/dist:$PATH
3236

33-
log_phase "Running unit and functional tests"
37+
log_phase "Running functional tests"
3438

35-
make test-components
39+
make test-functional
3640

3741
log_phase "Provisioning 3-node CoreOS"
3842

tests/bin/test-integration.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ log_phase "Running documentation tests"
2222
# test building documentation
2323
make -C docs/ test
2424

25+
log_phase "Running unit tests"
26+
27+
make test-unit
28+
2529
log_phase "Building from current source tree"
2630

2731
# build all docker images and client binaries
@@ -30,9 +34,9 @@ make build
3034
# use the built client binaries
3135
export PATH=$DEIS_ROOT/deisctl:$DEIS_ROOT/client/dist:$PATH
3236

33-
log_phase "Running unit and functional tests"
37+
log_phase "Running functional tests"
3438

35-
make test-components
39+
make test-functional
3640

3741
log_phase "Provisioning 3-node CoreOS"
3842

tests/bin/test-smoke.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ log_phase "Running documentation tests"
2222
# test building documentation
2323
make -C docs/ test
2424

25+
log_phase "Running unit tests"
26+
27+
make test-unit
28+
2529
log_phase "Building from current source tree"
2630

2731
# build all docker images and client binaries
@@ -30,9 +34,9 @@ make build
3034
# use the built client binaries
3135
export PATH=$DEIS_ROOT/deisctl:$DEIS_ROOT/client/dist:$PATH
3236

33-
log_phase "Running unit and functional tests"
37+
log_phase "Running functional tests"
3438

35-
make test-components
39+
make test-functional
3640

3741
log_phase "Provisioning 3-node CoreOS"
3842

0 commit comments

Comments
 (0)