Skip to content

Commit

Permalink
Merge pull request mendersoftware#647 from kjaskiewiczz/fix-single-de…
Browse files Browse the repository at this point in the history
…vice-deployment

fix single device deployment handling
  • Loading branch information
kjaskiewiczz authored Nov 25, 2021
2 parents d61f0f2 + 22ce8e8 commit 63a9742
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,9 @@ func (d *Deployments) CreateDeployment(ctx context.Context,
deployment.DeviceList = constructor.Devices
deployment.MaxDevices = len(constructor.Devices)
deployment.Type = model.DeploymentTypeSoftware
deployment.Groups = []string{constructor.Group}
if len(constructor.Group) > 0 {
deployment.Groups = []string{constructor.Group}
}

// single device deployment case
if len(deployment.Groups) == 0 && len(constructor.Devices) == 1 {
Expand Down
15 changes: 15 additions & 0 deletions app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ func TestDeploymentModelCreateDeployment(t *testing.T) {
SearchError error
GetFilterError error

CallGetDeviceGroups bool
InventoryGroups []string
GetDeviceGroupsError error

ReportingService bool

OutputError error
Expand All @@ -183,6 +187,7 @@ func TestDeploymentModelCreateDeployment(t *testing.T) {
Devices: []string{"b532b01a-9313-404f-8d19-e7fcbe5cc347"},
},
InputDeploymentStorageInsertError: errors.New("insert error"),
CallGetDeviceGroups: true,

OutputError: errors.New("Storing deployment data: insert error"),
},
Expand All @@ -192,6 +197,8 @@ func TestDeploymentModelCreateDeployment(t *testing.T) {
ArtifactName: "App 123",
Devices: []string{"b532b01a-9313-404f-8d19-e7fcbe5cc347"},
},
CallGetDeviceGroups: true,
InventoryGroups: []string{"foo", "bar"},

OutputBody: true,
},
Expand Down Expand Up @@ -304,6 +311,14 @@ func TestDeploymentModelCreateDeployment(t *testing.T) {
ds := NewDeployments(&db, fs, "")

mockInventoryClient := &inventory_mocks.Client{}
if testCase.CallGetDeviceGroups {
mockInventoryClient.On("GetDeviceGroups",
ctx,
mock.AnythingOfType("string"),
mock.AnythingOfType("string")).
Return(testCase.InventoryGroups, testCase.GetDeviceGroupsError)
}

mockReportingClient := &reporting_mocks.Client{}
if testCase.InputConstructor != nil && testCase.InputConstructor.Group != "" && len(testCase.InputConstructor.Devices) == 0 {
if testCase.ReportingService {
Expand Down

0 comments on commit 63a9742

Please sign in to comment.