-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(exp): add
AppendNextActions
function (#440)
This function is used to merge both a single action and the next actions returned by the API.
- Loading branch information
Showing
2 changed files
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |