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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package app
import (
"testing"
"github.com/mattermost/mattermost-server/model"
"github.com/mattermost/mattermost-server/store"
)
func TestGetJob(t *testing.T) {
th := Setup()
defer th.TearDown()
status := &model.Job{
Id: model.NewId(),
Status: model.NewId(),
}
if result := <-th.App.Srv.Store.Job().Save(status); result.Err != nil {
t.Fatal(result.Err)
}
defer th.App.Srv.Store.Job().Delete(status.Id)
if received, err := th.App.GetJob(status.Id); err != nil {
t.Fatal(err)
} else if received.Id != status.Id || received.Status != status.Status {
t.Fatal("inccorrect job status received")
}
}
func TestGetJobByType(t *testing.T) {
th := Setup()
defer th.TearDown()
jobType := model.NewId()
statuses := []*model.Job{
{
Id: model.NewId(),
Type: jobType,
CreateAt: 1000,
},
{
Id: model.NewId(),
Type: jobType,
CreateAt: 999,
},
{
Id: model.NewId(),
Type: jobType,
CreateAt: 1001,
},
}
for _, status := range statuses {
store.Must(th.App.Srv.Store.Job().Save(status))
defer th.App.Srv.Store.Job().Delete(status.Id)
}
if received, err := th.App.GetJobsByType(jobType, 0, 2); err != nil {
t.Fatal(err)
} else if len(received) != 2 {
t.Fatal("received wrong number of statuses")
} else if received[0].Id != statuses[2].Id {
t.Fatal("should've received newest job first")
} else if received[1].Id != statuses[0].Id {
t.Fatal("should've received second newest job second")
}
if received, err := th.App.GetJobsByType(jobType, 2, 2); err != nil {
t.Fatal(err)
} else if len(received) != 1 {
t.Fatal("received wrong number of statuses")
} else if received[0].Id != statuses[1].Id {
t.Fatal("should've received oldest job last")
}
}
|