aboutsummaryrefslogtreecommitdiff
path: root/config/command_test.go
diff options
context:
space:
mode:
authorJulien Dessaux2020-12-24 15:18:24 +0100
committerJulien Dessaux2020-12-24 15:18:24 +0100
commitb4dc5d6841f7ded5995e5f308509b1a3a034cbed (patch)
tree254466925238c53bd51372a57558ec68fdf78205 /config/command_test.go
parentImplemented the configuration file format (diff)
downloadshell-game-launcher-b4dc5d6841f7ded5995e5f308509b1a3a034cbed.tar.gz
shell-game-launcher-b4dc5d6841f7ded5995e5f308509b1a3a034cbed.tar.bz2
shell-game-launcher-b4dc5d6841f7ded5995e5f308509b1a3a034cbed.zip
Began implementing config validation
Diffstat (limited to 'config/command_test.go')
-rw-r--r--config/command_test.go51
1 files changed, 51 insertions, 0 deletions
diff --git a/config/command_test.go b/config/command_test.go
new file mode 100644
index 0000000..7e07956
--- /dev/null
+++ b/config/command_test.go
@@ -0,0 +1,51 @@
+package config
+
+import "testing"
+
+func TestCommandValidate(t *testing.T) {
+ // Empty command
+ if err := validateCommand(""); err == nil {
+ t.Fatal("An command cannot be empty")
+ }
+ // invalid command
+ if err := validateCommand("invalid"); err == nil {
+ t.Fatal("An command cannot be empty")
+ }
+ // cp
+ if err := validateCommand("cp"); err == nil {
+ t.Fatal("cp command needs arguments")
+ }
+ if err := validateCommand("cp test"); err == nil {
+ t.Fatal("cp command needs exactly 2 arguments")
+ }
+ if err := validateCommand("cp test test test"); err == nil {
+ t.Fatal("cp command needs exactly 2 arguments")
+ }
+ if err := validateCommand("exec test test"); err != nil {
+ t.Fatal("valid exec command should be accepted")
+ }
+ // exec
+ if err := validateCommand("exec"); err == nil {
+ t.Fatal("exec command needs arguments")
+ }
+ if err := validateCommand("exec test"); err != nil {
+ t.Fatal("valid exec command should be accepted")
+ }
+ // mkdir
+ if err := validateCommand("mkdir"); err == nil {
+ t.Fatal("mkdir command needs exactly 1 argument")
+ }
+ if err := validateCommand("mkdir testtest "); err == nil {
+ t.Fatal("mkdir command needs exactly 1 argument")
+ }
+ if err := validateCommand("mkdir test"); err != nil {
+ t.Fatal("valid mkdir command should be accepted")
+ }
+ // wait
+ if err := validateCommand("wait test"); err == nil {
+ t.Fatal("wait command needs no arguments")
+ }
+ if err := validateCommand("wait"); err != nil {
+ t.Fatal("valid wait command should be accepted")
+ }
+}