Skip to content

Commit

Permalink
[#66] Package slices conflict with the current go version (#67)
Browse files Browse the repository at this point in the history
Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov3@bosch.com>
  • Loading branch information
dimitar-dimitrow authored Jun 6, 2024
1 parent 40e7225 commit 0b23c81
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
10 changes: 10 additions & 0 deletions api/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,13 @@ func FixActivationActionStatus(action *types.Action) *types.Action {
Message: action.Message,
}
}

// Contains checks if the given value is in the slice.
func Contains[T comparable](slice []T, value T) bool {
for _, v := range slice {
if value == v {
return true
}
}
return false
}
10 changes: 10 additions & 0 deletions api/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,13 @@ func TestFixActivationActionStatus(t *testing.T) {
}

}

func TestContains(t *testing.T) {
assert.True(t, Contains([]int{2, 5, 9}, 2))
assert.False(t, Contains([]int{2, -3, 9}, 3))
assert.False(t, Contains([]int{}, 3))
assert.True(t, Contains([]string{"", "text", "string"}, "text"))
assert.False(t, Contains([]string{"", "text", "string"}, "number"))
assert.True(t, Contains([]types.CommandType{types.CommandActivate, types.CommandDownload, types.CommandUpdate}, types.CommandUpdate))
assert.False(t, Contains([]types.CommandType{types.CommandActivate, types.CommandDownload, types.CommandUpdate}, types.CommandRollback))
}
6 changes: 3 additions & 3 deletions updatem/orchestration/update_orchestrator_apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ package orchestration
import (
"context"
"fmt"
"slices"
"time"

"github.com/eclipse-kanto/update-manager/api"
"github.com/eclipse-kanto/update-manager/api/types"
"github.com/eclipse-kanto/update-manager/api/util"
"github.com/eclipse-kanto/update-manager/logger"
)

Expand Down Expand Up @@ -111,7 +111,7 @@ func handleCommandSignal(ctx context.Context, command types.CommandType, orchest

executeCommand := func(statuses ...types.StatusType) {
for domain, domainStatus := range orchestrator.operation.domains {
if slices.Contains(statuses, domainStatus) {
if util.Contains(statuses, domainStatus) {
orchestrator.command(ctx, orchestrator.operation.activityID, domain, command)
}
}
Expand All @@ -134,7 +134,7 @@ func handleCommandSignal(ctx context.Context, command types.CommandType, orchest
}

func (orchestrator *updateOrchestrator) getOwnerConsent(ctx context.Context, command types.CommandType) error {
if command == "" || !slices.Contains(orchestrator.cfg.OwnerConsentCommands, command) {
if command == "" || !util.Contains(orchestrator.cfg.OwnerConsentCommands, command) {
return nil
}
if command == types.CommandRollback || command == types.CommandCleanup {
Expand Down

0 comments on commit 0b23c81

Please sign in to comment.