aboutsummaryrefslogtreecommitdiff
path: root/config/app_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/app_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/app_test.go')
-rw-r--r--config/app_test.go59
1 files changed, 59 insertions, 0 deletions
diff --git a/config/app_test.go b/config/app_test.go
new file mode 100644
index 0000000..22fb891
--- /dev/null
+++ b/config/app_test.go
@@ -0,0 +1,59 @@
+package config
+
+import (
+ "os"
+ "testing"
+)
+
+func TestAppvalidate(t *testing.T) {
+ // WorkingDirectory
+ t.Cleanup(func() { os.RemoveAll("no_permission/") })
+ if err := os.Mkdir("no_permission/", 0000); err != nil {
+ t.Fatal("Could not create test directory")
+ }
+ app := App{WorkingDirectory: "no_permission/cannot_work"}
+ if err := app.validate(); err == nil {
+ t.Fatal("no_permission/cannot_wor/k should not be a valid working directory")
+ }
+ app = App{WorkingDirectory: "no_permission/"}
+ if err := app.validate(); err == nil {
+ t.Fatal("no_permission/ should not be a valid working directory")
+ }
+
+ // MaxUsers
+ t.Cleanup(func() { os.RemoveAll("var/") })
+ app = App{
+ WorkingDirectory: "var/",
+ MaxUsers: 0,
+ }
+ if err := app.validate(); err == nil {
+ t.Fatal("Negative MaxUsers should not be valid")
+ }
+
+ // AllowRegistration is just a bool, nothing to test
+
+ // MaxNickLen
+ t.Cleanup(func() { os.RemoveAll("var/") })
+ app = App{
+ WorkingDirectory: "var/",
+ MaxUsers: 1,
+ MaxNickLen: 0,
+ }
+ if err := app.validate(); err == nil {
+ t.Fatal("Negative or zero MaxNickLen should not be valid.")
+ }
+
+ //MenuMaxIdleTime
+ t.Cleanup(func() { os.RemoveAll("var/") })
+ app = App{
+ WorkingDirectory: "var/",
+ MaxUsers: 512,
+ MaxNickLen: 15,
+ MenuMaxIdleTime: 0,
+ }
+ if err := app.validate(); err == nil {
+ t.Fatal("Negative or zero MenuMaxIdleTime should not be valid.")
+ }
+
+ //PostLoginCommands is tested from command.go
+}