diff --git a/hcloud/exp/actionutils/actions.go b/hcloud/exp/actionutils/actions.go new file mode 100644 index 00000000..aa08e5c9 --- /dev/null +++ b/hcloud/exp/actionutils/actions.go @@ -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 +} diff --git a/hcloud/exp/actionutils/actions_test.go b/hcloud/exp/actionutils/actions_test.go new file mode 100644 index 00000000..e31b743f --- /dev/null +++ b/hcloud/exp/actionutils/actions_test.go @@ -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) +}