-
Notifications
You must be signed in to change notification settings - Fork 5
/
main_test.go
40 lines (32 loc) · 1.84 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright (c) Rishabh Gupta 2019. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
package main
import (
"testing"
"github.com/openfaas/faas/gateway/requests"
cfunction "github.com/zeerorg/cron-connector/types"
)
func TestGetNewAndDeleteFuncs(t *testing.T) {
newCronFunctions := make(cfunction.CronFunctions, 3)
defaultReq := requests.Function{}
newCronFunctions[0] = cfunction.CronFunction{FuncData: defaultReq, Name: "test_function_unchanged", Schedule: "* * * * *"}
newCronFunctions[1] = cfunction.CronFunction{FuncData: defaultReq, Name: "test_function_to_add", Schedule: "* * * * *"}
newCronFunctions[1] = cfunction.CronFunction{FuncData: defaultReq, Name: "test_function_to_update", Schedule: "*/5 * * * *"}
oldFuncs := make(cfunction.ScheduledFunctions, 3)
oldFuncs[0] = cfunction.ScheduledFunction{Function: cfunction.CronFunction{FuncData: defaultReq, Name: "test_function_unchanged", Schedule: "* * * * *"}, ID: 0}
oldFuncs[1] = cfunction.ScheduledFunction{Function: cfunction.CronFunction{FuncData: defaultReq, Name: "test_function_to_delete", Schedule: "* * * * *"}, ID: 0}
oldFuncs[2] = cfunction.ScheduledFunction{Function: cfunction.CronFunction{FuncData: defaultReq, Name: "test_function_to_update", Schedule: "* * * * *"}, ID: 0}
addFuncs, deleteFuncs := GetNewAndDeleteFuncs(newCronFunctions, oldFuncs)
if !deleteFuncs.Contains(&oldFuncs[1].Function) {
t.Error("function was not deleted")
}
if !addFuncs.Contains(&newCronFunctions[1]) {
t.Error("function was not added")
}
if !deleteFuncs.Contains(&oldFuncs[2].Function) && !addFuncs.Contains(&newCronFunctions[1]) {
t.Error("function will not be updated")
}
if addFuncs.Contains(&newCronFunctions[0]) || deleteFuncs.Contains(&newCronFunctions[0]) {
t.Error("function should be left as it is")
}
}