diff --git a/command/command_test.go b/command/command_test.go index 2a6c202..730ed0b 100644 --- a/command/command_test.go +++ b/command/command_test.go @@ -29,6 +29,28 @@ func TestGetCommand(t *testing.T) { } } +func TestGetCommandExtraArgs(t *testing.T) { + followFlags := []string{"", "-f", "--follow"} + for _, followFlag := range followFlags { + flags := flag.FlagSet{} + flags.Bool("follow", false, "") + commandText := "tail -f -n 10 logs/rest.log" + flags.Parse([]string{"--", followFlag, "dev", commandText}) + app := cli.NewApp() + context := cli.NewContext(app, &flags, nil) + command, extraArgs := getCommand(context, true) + if !command.IsAdHoc() { + t.Errorf("Command name should be ad-hoc, but got %s", command.Name) + } + if command.Command != commandText { + t.Errorf("Command should be %s, but got %s", commandText, command.Command) + } + if extraArgs != "" { + t.Errorf("Extra args should be empty, but got %s", extraArgs) + } + } +} + func TestContainsFollow(t *testing.T) { followFlags := []string{"-f", "--follow"} for _, followFlag := range followFlags { diff --git a/test/README.md b/test/README.md new file mode 100644 index 0000000..d34d9f4 --- /dev/null +++ b/test/README.md @@ -0,0 +1,6 @@ +There are 2 env variables which control where the `vmx` looks for the application config and SSH config. + +They are: `VMX_HOME` and `VMX_SSH_CONFIG_HOME`. + +So the data in this directory is used for testing when the corresponding env variables set to point to `config` and +`ssh` inner directories correspondingly. \ No newline at end of file diff --git a/test/config/commands b/test/config/commands new file mode 100644 index 0000000..bc03d1b --- /dev/null +++ b/test/config/commands @@ -0,0 +1,16 @@ +[logs] +command=cat logs/app.log + +[app-logs] +command=tail -f -n 10 logs/app.log + +[follow-logs] +workingdir=/opt/app1 +command=tail -f -n 10 logs/app1.log +follow=true + +[redeploy!] +command=./redeploy.sh + +[disk-space] +command=df -h diff --git a/test/config/defaults b/test/config/defaults new file mode 100644 index 0000000..37e45df --- /dev/null +++ b/test/config/defaults @@ -0,0 +1,6 @@ +[all] +workingdir=/opt/app + +# +[app2-prod*] +workingdir=/opt/app2 diff --git a/test/config/hosts b/test/config/hosts new file mode 100644 index 0000000..b5b6176 --- /dev/null +++ b/test/config/hosts @@ -0,0 +1,38 @@ +# dev +[dev] +app-dev1 +db-dev1 + +[dev-db] +db-dev1 + +# prod +[prod] +app1-prod1 +app1-prod2 +db-prod1 +db-prod2 + +[prod-db] +db-prod1 +db-prod2 + +[prod-app1] +app1-prod1 +app1-prod2 + +[prod-app2] +app2-prod1 +app2-prod2 + +[all-db:children] +dev-db +prod-db + +[prod-app:children] +prod-app1 +prod-app2 + +[all-prod:children] +prod-app +prod-db \ No newline at end of file diff --git a/test/ssh/config b/test/ssh/config new file mode 100644 index 0000000..a0f6dfe --- /dev/null +++ b/test/ssh/config @@ -0,0 +1,24 @@ +Host app-dev1 + User vmx + Hostname 192.168.1.1 +Host db-dev1 + User vmx + Hostname 192.168.1.2 +Host app1-prod1 + User vmx + Hostname 192.168.1.3 +Host app1-prod2 + User vmx + Hostname 192.168.1.4 +Host db-prod1 + User vmx + Hostname 192.168.1.5 +Host db-prod2 + User vmx + Hostname 192.168.1.6 +Host app2-prod1 + User vmx + Hostname 192.168.1.7 +Host app2-prod2 + User vmx + Hostname 192.168.1.8 \ No newline at end of file