summaryrefslogtreecommitdiff
path: root/branding/motd-cli/motd_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'branding/motd-cli/motd_test.go')
-rw-r--r--branding/motd-cli/motd_test.go83
1 files changed, 83 insertions, 0 deletions
diff --git a/branding/motd-cli/motd_test.go b/branding/motd-cli/motd_test.go
new file mode 100644
index 0000000..ed11661
--- /dev/null
+++ b/branding/motd-cli/motd_test.go
@@ -0,0 +1,83 @@
+package main
+
+import (
+ "testing"
+)
+
+func TestGoodMotd(t *testing.T) {
+ m, err := parseFile(defaultFile)
+ if err != nil {
+ t.Errorf("error parsing default file")
+ }
+ if m.Length() == 0 {
+ t.Errorf("zero messages in file")
+ }
+ for _, msg := range m.Messages {
+ if !msg.IsValid() {
+ t.Errorf("invalid motd json at %s", defaultFile)
+ }
+ }
+}
+
+const emptyDate = `
+{
+ "motd": [{
+ "begin": "",
+ "end": "",
+ "type": "daily",
+ "platform": "all",
+ "urgency": "normal",
+ "text": [
+ { "lang": "en",
+ "str": "test"
+ }]
+ }]
+}`
+
+func TestEmptyDateFails(t *testing.T) {
+ m, err := parseJsonStr([]byte(emptyDate))
+ if err != nil {
+ t.Errorf("error parsing json")
+ }
+ if allValid(t, m) {
+ t.Errorf("empty string should not be valid")
+ }
+}
+
+const badEnd = `
+{
+ "motd": [{
+ "begin": "02 Jan 21 00:00 +0100",
+ "end": "01 Jan 21 00:00 +0100",
+ "type": "daily",
+ "platform": "all",
+ "urgency": "normal",
+ "text": [
+ { "lang": "en",
+ "str": "test"
+ }]
+ }]
+}`
+
+func TestBadEnd(t *testing.T) {
+ m, err := parseJsonStr([]byte(badEnd))
+ if err != nil {
+ t.Errorf("error parsing json")
+ }
+ if allValid(t, m) {
+ t.Errorf("begin > end must fail")
+ }
+}
+
+func allValid(t *testing.T, m Messages) bool {
+ if m.Length() == 0 {
+ t.Errorf("expected at least one message")
+
+ }
+ for _, msg := range m.Messages {
+ if !msg.IsValid() {
+ return false
+ }
+ }
+ return true
+}