Add Host Set CUDLR handler and SDK (#290)
This commit is contained in:
1 parent
e423b6589e
commit
c4d3414016
16 files changed
+2307
-446
No files matched your search
@@ -47,7 +47,7 @@ func TestCatalog_List(t *testing.T) {
|
||||
ul, apiErr, err = catalogClient.List(tc.Context())
|
||||
assert.NoError(err)
|
||||
assert.Nil(apiErr)
|
||||
assert.ElementsMatch(comparableSlice(expected[:1]), comparableSlice(ul))
|
||||
assert.ElementsMatch(comparableCatalogSlice(expected[:1]), comparableCatalogSlice(ul))
|
||||
|
||||
for i := 1; i < 10; i++ {
|
||||
expected[i], apiErr, err = catalogClient.Create(tc.Context(), "static", hosts.WithName(expected[i].Name))
|
||||
@@ -57,10 +57,10 @@ func TestCatalog_List(t *testing.T) {
|
||||
ul, apiErr, err = catalogClient.List(tc.Context())
|
||||
require.NoError(err)
|
||||
assert.Nil(apiErr)
|
||||
assert.ElementsMatch(comparableSlice(expected), comparableSlice(ul))
|
||||
assert.ElementsMatch(comparableCatalogSlice(expected), comparableCatalogSlice(ul))
|
||||
}
|
||||
|
||||
func comparableSlice(in []*hosts.HostCatalog) []hosts.HostCatalog {
|
||||
func comparableCatalogSlice(in []*hosts.HostCatalog) []hosts.HostCatalog {
|
||||
var filtered []hosts.HostCatalog
|
||||
for _, i := range in {
|
||||
p := hosts.HostCatalog{
|
||||
|
||||
+11
-10
@@ -14,16 +14,17 @@ import (
|
||||
)
|
||||
|
||||
type HostSet struct {
|
||||
Id string `json:"id,omitempty"`
|
||||
Scope *scopes.ScopeInfo `json:"scope,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
CreatedTime time.Time `json:"created_time,omitempty"`
|
||||
UpdatedTime time.Time `json:"updated_time,omitempty"`
|
||||
Version uint32 `json:"version,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
Size uint32 `json:"size,omitempty"`
|
||||
Hosts []*Host `json:"hosts,omitempty"`
|
||||
Id string `json:"id,omitempty"`
|
||||
Scope *scopes.ScopeInfo `json:"scope,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
CreatedTime time.Time `json:"created_time,omitempty"`
|
||||
UpdatedTime time.Time `json:"updated_time,omitempty"`
|
||||
Version uint32 `json:"version,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
HostCatalogId string `json:"host_catalog_id,omitempty"`
|
||||
HostIds []string `json:"host_ids,omitempty"`
|
||||
Attributes map[string]interface{} `json:"attributes,omitempty"`
|
||||
}
|
||||
|
||||
type HostSetsClient struct {
|
||||
|
||||
@@ -0,0 +1,184 @@
|
||||
package hosts_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/boundary/api"
|
||||
"github.com/hashicorp/boundary/api/hosts"
|
||||
"github.com/hashicorp/boundary/internal/host/static"
|
||||
"github.com/hashicorp/boundary/internal/iam"
|
||||
"github.com/hashicorp/boundary/internal/servers/controller"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestSet_List(t *testing.T) {
|
||||
assert, require := assert.New(t), require.New(t)
|
||||
amId := "paum_1234567890"
|
||||
tc := controller.NewTestController(t, &controller.TestControllerOpts{
|
||||
DisableAuthorizationFailures: true,
|
||||
DefaultAuthMethodId: amId,
|
||||
DefaultLoginName: "user",
|
||||
DefaultPassword: "passpass",
|
||||
})
|
||||
defer tc.Shutdown()
|
||||
|
||||
client := tc.Client()
|
||||
_, proj := iam.TestScopes(t, tc.IamRepo())
|
||||
client.SetScopeId(proj.GetPublicId())
|
||||
|
||||
hc, apiErr, err := hosts.NewHostCatalogsClient(client).Create(tc.Context(), "static")
|
||||
require.NoError(err)
|
||||
require.Nil(apiErr)
|
||||
require.NotNil(hc)
|
||||
|
||||
hClient := hosts.NewHostSetsClient(client)
|
||||
|
||||
ul, apiErr, err := hClient.List(tc.Context(), hc.Id)
|
||||
assert.NoError(err)
|
||||
assert.Nil(apiErr)
|
||||
assert.Empty(ul)
|
||||
|
||||
var expected []*hosts.HostSet
|
||||
for i := 0; i < 10; i++ {
|
||||
expected = append(expected, &hosts.HostSet{Name: fmt.Sprint(i)})
|
||||
}
|
||||
|
||||
expected[0], apiErr, err = hClient.Create(tc.Context(), hc.Id, hosts.WithName(expected[0].Name))
|
||||
assert.NoError(err)
|
||||
assert.Nil(apiErr)
|
||||
|
||||
ul, apiErr, err = hClient.List(tc.Context(), hc.Id)
|
||||
assert.NoError(err)
|
||||
assert.Nil(apiErr)
|
||||
assert.ElementsMatch(comparableSetSlice(expected[:1]), comparableSetSlice(ul))
|
||||
|
||||
for i := 1; i < 10; i++ {
|
||||
expected[i], apiErr, err = hClient.Create(tc.Context(), hc.Id, hosts.WithName(expected[i].Name))
|
||||
assert.NoError(err)
|
||||
assert.Nil(apiErr)
|
||||
}
|
||||
ul, apiErr, err = hClient.List(tc.Context(), hc.Id)
|
||||
require.NoError(err)
|
||||
assert.Nil(apiErr)
|
||||
assert.ElementsMatch(comparableSetSlice(expected), comparableSetSlice(ul))
|
||||
}
|
||||
|
||||
func comparableSetSlice(in []*hosts.HostSet) []hosts.HostSet {
|
||||
var filtered []hosts.HostSet
|
||||
for _, i := range in {
|
||||
p := hosts.HostSet{
|
||||
Id: i.Id,
|
||||
Name: i.Name,
|
||||
Description: i.Description,
|
||||
CreatedTime: i.CreatedTime,
|
||||
UpdatedTime: i.UpdatedTime,
|
||||
}
|
||||
filtered = append(filtered, p)
|
||||
}
|
||||
return filtered
|
||||
}
|
||||
|
||||
func TestSet_Crud(t *testing.T) {
|
||||
assert, require := assert.New(t), require.New(t)
|
||||
amId := "paum_1234567890"
|
||||
tc := controller.NewTestController(t, &controller.TestControllerOpts{
|
||||
DisableAuthorizationFailures: true,
|
||||
DefaultAuthMethodId: amId,
|
||||
DefaultLoginName: "user",
|
||||
DefaultPassword: "passpass",
|
||||
})
|
||||
defer tc.Shutdown()
|
||||
|
||||
client := tc.Client()
|
||||
org, proj := iam.TestScopes(t, tc.IamRepo())
|
||||
client.SetScopeId(org.GetPublicId())
|
||||
projClient := client.Clone()
|
||||
projClient.SetScopeId(proj.GetPublicId())
|
||||
|
||||
hc, apiErr, err := hosts.NewHostCatalogsClient(projClient).Create(tc.Context(), "static")
|
||||
require.NoError(err)
|
||||
require.Nil(apiErr)
|
||||
require.NotNil(hc)
|
||||
|
||||
checkHost := func(step string, h *hosts.HostSet, apiErr *api.Error, err error, wantedName string, wantVersion uint32) {
|
||||
require.NoError(err, step)
|
||||
if !assert.Nil(apiErr, step) && apiErr.Message != "" {
|
||||
t.Errorf("ApiError message: %q", apiErr.Message)
|
||||
}
|
||||
assert.NotNil(h, "returned no resource", step)
|
||||
gotName := ""
|
||||
if h.Name != "" {
|
||||
gotName = h.Name
|
||||
}
|
||||
assert.Equal(wantedName, gotName, step)
|
||||
assert.Equal(wantVersion, h.Version)
|
||||
}
|
||||
|
||||
hClient := hosts.NewHostSetsClient(projClient)
|
||||
|
||||
h, apiErr, err := hClient.Create(tc.Context(), hc.Id, hosts.WithName("foo"))
|
||||
checkHost("create", h, apiErr, err, "foo", 1)
|
||||
|
||||
h, apiErr, err = hClient.Read(tc.Context(), hc.Id, h.Id)
|
||||
checkHost("read", h, apiErr, err, "foo", 1)
|
||||
|
||||
h, apiErr, err = hClient.Update(tc.Context(), hc.Id, h.Id, h.Version, hosts.WithName("bar"))
|
||||
checkHost("update", h, apiErr, err, "bar", 2)
|
||||
|
||||
h, apiErr, err = hClient.Update(tc.Context(), hc.Id, h.Id, h.Version, hosts.DefaultName())
|
||||
checkHost("update", h, apiErr, err, "", 3)
|
||||
|
||||
existed, apiErr, err := hClient.Delete(tc.Context(), hc.Id, h.Id)
|
||||
assert.NoError(err)
|
||||
assert.True(existed, "Expected existing catalog when deleted, but it wasn't.")
|
||||
|
||||
existed, apiErr, err = hClient.Delete(tc.Context(), hc.Id, h.Id)
|
||||
assert.NoError(err)
|
||||
assert.False(existed, "Expected catalog to not exist when deleted, but it did.")
|
||||
}
|
||||
|
||||
// TODO: Get better coverage for expected errors and error formats.
|
||||
func TestSet_Errors(t *testing.T) {
|
||||
assert, require := assert.New(t), require.New(t)
|
||||
amId := "paum_1234567890"
|
||||
tc := controller.NewTestController(t, &controller.TestControllerOpts{
|
||||
DisableAuthorizationFailures: true,
|
||||
DefaultAuthMethodId: amId,
|
||||
DefaultLoginName: "user",
|
||||
DefaultPassword: "passpass",
|
||||
})
|
||||
defer tc.Shutdown()
|
||||
|
||||
client := tc.Client()
|
||||
_, proj := iam.TestScopes(t, tc.IamRepo())
|
||||
client.SetScopeId(proj.GetPublicId())
|
||||
|
||||
hc, apiErr, err := hosts.NewHostCatalogsClient(client).Create(tc.Context(), "static")
|
||||
require.NoError(err)
|
||||
require.Nil(apiErr)
|
||||
require.NotNil(hc)
|
||||
|
||||
hClient := hosts.NewHostSetsClient(client)
|
||||
|
||||
h, apiErr, err := hClient.Create(tc.Context(), hc.Id, hosts.WithName("foo"))
|
||||
require.NoError(err)
|
||||
require.Nil(apiErr)
|
||||
assert.NotNil(h)
|
||||
|
||||
_, apiErr, err = hClient.Create(tc.Context(), hc.Id, hosts.WithName("foo"))
|
||||
require.NoError(err)
|
||||
assert.NotNil(apiErr)
|
||||
|
||||
_, apiErr, err = hClient.Read(tc.Context(), hc.Id, static.HostSetPrefix+"_doesntexis")
|
||||
require.NoError(err)
|
||||
assert.NotNil(apiErr)
|
||||
assert.EqualValues(apiErr.Status, http.StatusNotFound)
|
||||
|
||||
_, apiErr, err = hClient.Read(tc.Context(), hc.Id, "invalid id")
|
||||
require.NoError(err)
|
||||
assert.NotNil(apiErr)
|
||||
assert.EqualValues(http.StatusForbidden, apiErr.Status)
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package hosts_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
@@ -13,6 +14,73 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestHost_List(t *testing.T) {
|
||||
assert, require := assert.New(t), require.New(t)
|
||||
amId := "paum_1234567890"
|
||||
tc := controller.NewTestController(t, &controller.TestControllerOpts{
|
||||
DisableAuthorizationFailures: true,
|
||||
DefaultAuthMethodId: amId,
|
||||
DefaultLoginName: "user",
|
||||
DefaultPassword: "passpass",
|
||||
})
|
||||
defer tc.Shutdown()
|
||||
|
||||
client := tc.Client()
|
||||
_, proj := iam.TestScopes(t, tc.IamRepo())
|
||||
client.SetScopeId(proj.GetPublicId())
|
||||
|
||||
hc, apiErr, err := hosts.NewHostCatalogsClient(client).Create(tc.Context(), "static")
|
||||
require.NoError(err)
|
||||
require.Nil(apiErr)
|
||||
require.NotNil(hc)
|
||||
|
||||
hClient := hosts.NewHostsClient(client)
|
||||
|
||||
ul, apiErr, err := hClient.List(tc.Context(), hc.Id)
|
||||
assert.NoError(err)
|
||||
assert.Nil(apiErr)
|
||||
assert.Empty(ul)
|
||||
|
||||
var expected []*hosts.Host
|
||||
for i := 0; i < 10; i++ {
|
||||
expected = append(expected, &hosts.Host{Name: fmt.Sprint(i)})
|
||||
}
|
||||
|
||||
expected[0], apiErr, err = hClient.Create(tc.Context(), hc.Id, hosts.WithName(expected[0].Name), hosts.WithStaticHostAddress("someaddress"))
|
||||
assert.NoError(err)
|
||||
assert.Nil(apiErr)
|
||||
|
||||
ul, apiErr, err = hClient.List(tc.Context(), hc.Id)
|
||||
assert.NoError(err)
|
||||
assert.Nil(apiErr)
|
||||
assert.ElementsMatch(comparableHostSlice(expected[:1]), comparableHostSlice(ul))
|
||||
|
||||
for i := 1; i < 10; i++ {
|
||||
expected[i], apiErr, err = hClient.Create(tc.Context(), hc.Id, hosts.WithName(expected[i].Name), hosts.WithStaticHostAddress("someaddress"))
|
||||
assert.NoError(err)
|
||||
assert.Nil(apiErr)
|
||||
}
|
||||
ul, apiErr, err = hClient.List(tc.Context(), hc.Id)
|
||||
require.NoError(err)
|
||||
assert.Nil(apiErr)
|
||||
assert.ElementsMatch(comparableHostSlice(expected), comparableHostSlice(ul))
|
||||
}
|
||||
|
||||
func comparableHostSlice(in []*hosts.Host) []hosts.Host {
|
||||
var filtered []hosts.Host
|
||||
for _, i := range in {
|
||||
p := hosts.Host{
|
||||
Id: i.Id,
|
||||
Name: i.Name,
|
||||
Description: i.Description,
|
||||
CreatedTime: i.CreatedTime,
|
||||
UpdatedTime: i.UpdatedTime,
|
||||
}
|
||||
filtered = append(filtered, p)
|
||||
}
|
||||
return filtered
|
||||
}
|
||||
|
||||
func TestHost_Crud(t *testing.T) {
|
||||
assert, require := assert.New(t), require.New(t)
|
||||
amId := "paum_1234567890"
|
||||
|
||||
Reference in new issue
Block a user