summaryrefslogtreecommitdiffstats
path: root/model/job_test.go
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2016-06-03 09:33:59 -0400
committerJoram Wilander <jwawilander@gmail.com>2016-06-03 09:33:59 -0400
commitea3342aa6c93579d41de3f6005c12a201b21ee6e (patch)
tree560ab58429ead414ffd3eb730d462e687db48d7f /model/job_test.go
parent87f357a54d0dccf09b6b6f20f64b08ef3ca2e1f2 (diff)
downloadchat-ea3342aa6c93579d41de3f6005c12a201b21ee6e.tar.gz
chat-ea3342aa6c93579d41de3f6005c12a201b21ee6e.tar.bz2
chat-ea3342aa6c93579d41de3f6005c12a201b21ee6e.zip
Adding LDAP Syncronization (#3219)
Diffstat (limited to 'model/job_test.go')
-rw-r--r--model/job_test.go128
1 files changed, 128 insertions, 0 deletions
diff --git a/model/job_test.go b/model/job_test.go
new file mode 100644
index 000000000..2a307de1e
--- /dev/null
+++ b/model/job_test.go
@@ -0,0 +1,128 @@
+// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+package model
+
+import (
+ "testing"
+ "time"
+)
+
+func TestCreateTask(t *testing.T) {
+ TASK_NAME := "Test Task"
+ TASK_TIME := time.Second * 3
+
+ testValue := 0
+ testFunc := func() {
+ testValue = 1
+ }
+
+ task := CreateTask(TASK_NAME, testFunc, TASK_TIME)
+ if testValue != 0 {
+ t.Fatal("Unexpected execuition of task")
+ }
+
+ time.Sleep(TASK_TIME + time.Second)
+
+ if testValue != 1 {
+ t.Fatal("Task did not execute")
+ }
+
+ if task.Name != TASK_NAME {
+ t.Fatal("Bad name")
+ }
+
+ if task.Interval != TASK_TIME {
+ t.Fatal("Bad interval")
+ }
+
+ if task.Recurring != false {
+ t.Fatal("should not reccur")
+ }
+}
+
+func TestCreateRecurringTask(t *testing.T) {
+ TASK_NAME := "Test Recurring Task"
+ TASK_TIME := time.Second * 3
+
+ testValue := 0
+ testFunc := func() {
+ testValue += 1
+ }
+
+ task := CreateRecurringTask(TASK_NAME, testFunc, TASK_TIME)
+ if testValue != 0 {
+ t.Fatal("Unexpected execuition of task")
+ }
+
+ time.Sleep(TASK_TIME + time.Second)
+
+ if testValue != 1 {
+ t.Fatal("Task did not execute")
+ }
+
+ time.Sleep(TASK_TIME)
+
+ if testValue != 2 {
+ t.Fatal("Task did not re-execute")
+ }
+
+ if task.Name != TASK_NAME {
+ t.Fatal("Bad name")
+ }
+
+ if task.Interval != TASK_TIME {
+ t.Fatal("Bad interval")
+ }
+
+ if task.Recurring != true {
+ t.Fatal("should reccur")
+ }
+
+ task.Cancel()
+}
+
+func TestCancelTask(t *testing.T) {
+ TASK_NAME := "Test Task"
+ TASK_TIME := time.Second * 3
+
+ testValue := 0
+ testFunc := func() {
+ testValue = 1
+ }
+
+ task := CreateTask(TASK_NAME, testFunc, TASK_TIME)
+ if testValue != 0 {
+ t.Fatal("Unexpected execuition of task")
+ }
+ task.Cancel()
+
+ time.Sleep(TASK_TIME + time.Second)
+
+ if testValue != 0 {
+ t.Fatal("Unexpected execuition of task")
+ }
+}
+
+func TestGetAllTasks(t *testing.T) {
+ doNothing := func() {}
+
+ CreateTask("Task1", doNothing, time.Hour)
+ CreateTask("Task2", doNothing, time.Second)
+ CreateRecurringTask("Task3", doNothing, time.Second)
+ task4 := CreateRecurringTask("Task4", doNothing, time.Second)
+
+ task4.Cancel()
+
+ time.Sleep(time.Second * 3)
+
+ tasks := *GetAllTasks()
+ if len(tasks) != 2 {
+ t.Fatal("Wrong number of tasks got: ", len(tasks))
+ }
+ for _, task := range tasks {
+ if task.Name != "Task1" && task.Name != "Task3" {
+ t.Fatal("Wrong tasks")
+ }
+ }
+}