aboutsummaryrefslogtreecommitdiff
path: root/pkg/config/app_test.go
diff options
context:
space:
mode:
authorJulien Dessaux2021-11-17 10:13:06 +0100
committerJulien Dessaux2021-11-17 10:13:06 +0100
commitc3263c03776401ad1263a9fb8f5a44a8ed44d61b (patch)
tree7dac91753cb4428ede2ba72fb09eca9ba6c2daab /pkg/config/app_test.go
parentUpdated dependencies (diff)
downloadshell-game-launcher-c3263c03776401ad1263a9fb8f5a44a8ed44d61b.tar.gz
shell-game-launcher-c3263c03776401ad1263a9fb8f5a44a8ed44d61b.tar.bz2
shell-game-launcher-c3263c03776401ad1263a9fb8f5a44a8ed44d61b.zip
Refactored package structure
Diffstat (limited to 'pkg/config/app_test.go')
-rw-r--r--pkg/config/app_test.go90
1 files changed, 90 insertions, 0 deletions
diff --git a/pkg/config/app_test.go b/pkg/config/app_test.go
new file mode 100644
index 0000000..5a6cf41
--- /dev/null
+++ b/pkg/config/app_test.go
@@ -0,0 +1,90 @@
+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 are mostly tested from command_test.go
+ app = App{
+ WorkingDirectory: "var/",
+ MaxUsers: 512,
+ MaxNickLen: 15,
+ MenuMaxIdleTime: 60,
+ }
+ if err := app.validate(); err != nil {
+ t.Fatal("Empty PostLoginCommands list should be valid")
+ }
+ app = App{
+ WorkingDirectory: "var/",
+ MaxUsers: 512,
+ MaxNickLen: 15,
+ MenuMaxIdleTime: 60,
+ PostLoginCommands: []string{"invalid"},
+ }
+ if err := app.validate(); err == nil {
+ t.Fatal("Invalid command in PostLoginCommands should not be valid")
+ }
+
+ // A valid App
+ app = App{
+ WorkingDirectory: "var/",
+ MaxUsers: 512,
+ MaxNickLen: 15,
+ MenuMaxIdleTime: 60,
+ PostLoginCommands: []string{"wait"},
+ }
+ if err := app.validate(); err != nil {
+ t.Fatal("A valid app should pass")
+ }
+}