-
Notifications
You must be signed in to change notification settings - Fork 48
/
app_last_status_test.go
122 lines (114 loc) · 3.56 KB
/
app_last_status_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
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// Copyright 2023 Northern.tech AS
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package app
import (
"context"
"testing"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
inventory_mocks "github.com/mendersoftware/deployments/client/inventory/mocks"
workflows_mocks "github.com/mendersoftware/deployments/client/workflows/mocks"
"github.com/mendersoftware/deployments/model"
fs_mocks "github.com/mendersoftware/deployments/storage/mocks"
"github.com/mendersoftware/deployments/store/mocks"
)
func TestGetDeviceDeploymentLastStatus(t *testing.T) {
t.Parallel()
deviceId := uuid.New().String()
lotsOfDevicesIds := make([]string, MaxDeviceArrayLength+1)
for i := 0; i < MaxDeviceArrayLength+1; i++ {
lotsOfDevicesIds[i] = uuid.New().String()
}
testCases := []struct {
Name string
DeviceIds []string
Statuses []model.DeviceDeploymentLastStatus
DbError error
ExpectedError error
}{
{
Name: "ok",
Statuses: []model.DeviceDeploymentLastStatus{
{
DeviceId: deviceId,
DeploymentId: uuid.New().String(),
DeviceDeploymentId: uuid.New().String(),
DeviceDeploymentStatus: model.DeviceDeploymentStatusNoArtifact,
TenantId: uuid.New().String(),
},
},
DeviceIds: []string{deviceId},
},
{
Name: "error no device ids",
Statuses: []model.DeviceDeploymentLastStatus{
{
DeviceId: uuid.New().String(),
DeploymentId: uuid.New().String(),
DeviceDeploymentId: uuid.New().String(),
DeviceDeploymentStatus: model.DeviceDeploymentStatusNoArtifact,
TenantId: uuid.New().String(),
},
},
ExpectedError: ErrNoIdsGiven,
},
{
Name: "error no device ids",
Statuses: []model.DeviceDeploymentLastStatus{
{
DeviceId: uuid.New().String(),
DeploymentId: uuid.New().String(),
DeviceDeploymentId: uuid.New().String(),
DeviceDeploymentStatus: model.DeviceDeploymentStatusNoArtifact,
TenantId: uuid.New().String(),
},
},
DeviceIds: lotsOfDevicesIds,
ExpectedError: ErrArrayTooBig,
},
}
for _, tc := range testCases {
t.Run(tc.Name, func(t *testing.T) {
ctx := context.TODO()
mDStore := &mocks.DataStore{}
mFStore := &fs_mocks.ObjectStorage{}
mWorkflows := &workflows_mocks.Client{}
mInventory := &inventory_mocks.Client{}
dep := &Deployments{
db: mDStore,
objectStorage: mFStore,
workflowsClient: mWorkflows,
inventoryClient: mInventory,
}
mDStore.On(
"GetLastDeviceDeploymentStatus",
ctx,
mock.AnythingOfType("[]string"),
).
Return(
tc.Statuses,
tc.DbError,
)
statuses, err := dep.GetDeviceDeploymentLastStatus(ctx, tc.DeviceIds)
if tc.ExpectedError == nil {
assert.NoError(t, err)
assert.Equal(t, len(tc.Statuses), len(statuses.DeviceDeploymentLastStatuses))
} else {
assert.Error(t, err)
assert.EqualError(t, tc.ExpectedError, err.Error())
}
})
}
}