refact(action): Make ActionSet behave as a set instead of a list
This switches the implementation of an ActionSet from a slice to a map to ensure the elements in an ActionSet are unique. This allows for other packages to perform set operations such as a union or difference without needing to account for duplicates.
This commit is contained in:
52 files changed
+1401
-274
No files matched your search
@@ -225,6 +225,9 @@ func TestList(t *testing.T) {
|
||||
cmpopts.SortSlices(func(a, b *authmethods.AuthMethod) bool {
|
||||
return a.Name < b.Name
|
||||
}),
|
||||
cmpopts.SortSlices(func(a, b string) bool {
|
||||
return a < b
|
||||
}),
|
||||
),
|
||||
)
|
||||
|
||||
@@ -251,6 +254,9 @@ func TestList(t *testing.T) {
|
||||
cmpopts.SortSlices(func(a, b *authmethods.AuthMethod) bool {
|
||||
return a.Name < b.Name
|
||||
}),
|
||||
cmpopts.SortSlices(func(a, b string) bool {
|
||||
return a < b
|
||||
}),
|
||||
),
|
||||
)
|
||||
|
||||
@@ -274,6 +280,9 @@ func TestList(t *testing.T) {
|
||||
cmpopts.SortSlices(func(a, b *authmethods.AuthMethod) bool {
|
||||
return a.Name < b.Name
|
||||
}),
|
||||
cmpopts.SortSlices(func(a, b string) bool {
|
||||
return a < b
|
||||
}),
|
||||
),
|
||||
)
|
||||
|
||||
@@ -281,7 +290,14 @@ func TestList(t *testing.T) {
|
||||
authmethods.WithFilter(`"/item/attributes/client_id"=="client-id"`))
|
||||
require.NoError(err)
|
||||
require.Len(result.Items, 1)
|
||||
assert.Empty(cmp.Diff(oidcAM.Item, result.Items[0], cmpopts.IgnoreUnexported(authmethods.AuthMethod{})))
|
||||
assert.Empty(cmp.Diff(
|
||||
oidcAM.Item,
|
||||
result.Items[0],
|
||||
cmpopts.IgnoreUnexported(authmethods.AuthMethod{}),
|
||||
cmpopts.SortSlices(func(a, b string) bool {
|
||||
return a < b
|
||||
}),
|
||||
))
|
||||
|
||||
result, err = amClient.List(tc.Context(), global,
|
||||
authmethods.WithFilter(`"/item/attributes/min_login_name_length"==3`))
|
||||
@@ -295,6 +311,9 @@ func TestList(t *testing.T) {
|
||||
cmpopts.SortSlices(func(a, b *authmethods.AuthMethod) bool {
|
||||
return a.Name < b.Name
|
||||
}),
|
||||
cmpopts.SortSlices(func(a, b string) bool {
|
||||
return a < b
|
||||
}),
|
||||
),
|
||||
)
|
||||
|
||||
@@ -302,7 +321,14 @@ func TestList(t *testing.T) {
|
||||
authmethods.WithFilter(`"/item/attributes/min_password_length"==10`))
|
||||
require.NoError(err)
|
||||
require.Len(result.Items, 1)
|
||||
assert.Empty(cmp.Diff(pwAM.Item, result.Items[0], cmpopts.IgnoreUnexported(authmethods.AuthMethod{})))
|
||||
assert.Empty(cmp.Diff(
|
||||
pwAM.Item,
|
||||
result.Items[0],
|
||||
cmpopts.IgnoreUnexported(authmethods.AuthMethod{}),
|
||||
cmpopts.SortSlices(func(a, b string) bool {
|
||||
return a < b
|
||||
}),
|
||||
))
|
||||
}
|
||||
|
||||
func TestCustomMethods(t *testing.T) {
|
||||
|
||||
@@ -9,6 +9,8 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/google/go-cmp/cmp/cmpopts"
|
||||
"github.com/hashicorp/boundary/api"
|
||||
"github.com/hashicorp/boundary/api/hostcatalogs"
|
||||
"github.com/hashicorp/boundary/api/hosts"
|
||||
@@ -125,7 +127,17 @@ func TestPluginHosts(t *testing.T) {
|
||||
|
||||
h, err := hClient.Read(tc.Context(), hl.Items[0].Id)
|
||||
require.NoError(err)
|
||||
assert.Equal(hl.Items[0], h.Item)
|
||||
assert.Empty(
|
||||
cmp.Diff(
|
||||
hl.Items[0],
|
||||
h.Item,
|
||||
cmpopts.IgnoreUnexported(hosts.Host{}),
|
||||
cmpopts.IgnoreFields(hosts.Host{}, "Version", "UpdatedTime"),
|
||||
cmpopts.SortSlices(func(a, b string) bool {
|
||||
return a < b
|
||||
}),
|
||||
),
|
||||
)
|
||||
|
||||
_, err = hClient.Update(tc.Context(), h.Item.Id, h.Item.Version, hosts.WithName("foo"))
|
||||
require.Error(err)
|
||||
|
||||
@@ -146,6 +146,9 @@ func TestList_Plugin(t *testing.T) {
|
||||
comparableSetSlice(ul.Items),
|
||||
cmpopts.IgnoreUnexported(hostsets.HostSet{}),
|
||||
cmpopts.IgnoreFields(hostsets.HostSet{}, "Version", "UpdatedTime"),
|
||||
cmpopts.SortSlices(func(a, b string) bool {
|
||||
return a < b
|
||||
}),
|
||||
),
|
||||
)
|
||||
|
||||
@@ -165,6 +168,9 @@ func TestList_Plugin(t *testing.T) {
|
||||
cmpopts.SortSlices(func(x, y *hostsets.HostSet) bool {
|
||||
return x.Id < y.Id
|
||||
}),
|
||||
cmpopts.SortSlices(func(a, b string) bool {
|
||||
return a < b
|
||||
}),
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
Reference in new issue
Block a user