Skip to content

Commit

Permalink
feat(exp): add AppendNextActions function (#440)
Browse files Browse the repository at this point in the history
This function is used to merge both a single action and the next actions
returned by the API.
  • Loading branch information
jooola authored May 24, 2024
1 parent fc7f3ff commit b07d7ad
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
11 changes: 11 additions & 0 deletions hcloud/exp/actionutils/actions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package actionutils

import "github.com/hetznercloud/hcloud-go/v2/hcloud"

// AppendNextActions return the action and the next actions in a new slice.
func AppendNextActions(action *hcloud.Action, nextActions []*hcloud.Action) []*hcloud.Action {
all := make([]*hcloud.Action, 0, 1+len(nextActions))
all = append(all, action)
all = append(all, nextActions...)
return all
}
18 changes: 18 additions & 0 deletions hcloud/exp/actionutils/actions_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package actionutils

import (
"testing"

"github.com/stretchr/testify/assert"

"github.com/hetznercloud/hcloud-go/v2/hcloud"
)

func TestAppendNextActions(t *testing.T) {
action := &hcloud.Action{ID: 1}
nextActions := []*hcloud.Action{{ID: 2}, {ID: 3}}

actions := AppendNextActions(action, nextActions)

assert.Equal(t, []*hcloud.Action{{ID: 1}, {ID: 2}, {ID: 3}}, actions)
}

0 comments on commit b07d7ad

Please sign in to comment.