This moves all of the tcp target functionality into a tcp package. It also establishes a Register function in the target package to allow specific target types to be registered at initilazation time. When registering, a target type needs to provide its Subtype, as well as some RepositoryHooks that are used by the target Repository.
70 lines
1.6 KiB
Go
70 lines
1.6 KiB
Go
package target_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/hashicorp/boundary/internal/credential"
|
|
"github.com/hashicorp/boundary/internal/errors"
|
|
"github.com/hashicorp/boundary/internal/target"
|
|
"github.com/hashicorp/boundary/internal/target/store"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestCredentialLibrary_New(t *testing.T) {
|
|
type args struct {
|
|
targetId string
|
|
libraryId string
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want *target.CredentialLibrary
|
|
wantErr errors.Code
|
|
}{
|
|
{
|
|
name: "no-targetId",
|
|
args: args{
|
|
libraryId: "lib_0000000",
|
|
},
|
|
wantErr: errors.InvalidParameter,
|
|
},
|
|
{
|
|
name: "no-libraryId",
|
|
args: args{
|
|
targetId: "targ_0000000",
|
|
},
|
|
wantErr: errors.InvalidParameter,
|
|
},
|
|
{
|
|
name: "valid",
|
|
args: args{
|
|
targetId: "targ_0000000",
|
|
libraryId: "lib_0000000",
|
|
},
|
|
want: &target.CredentialLibrary{
|
|
CredentialLibrary: &store.CredentialLibrary{
|
|
TargetId: "targ_0000000",
|
|
CredentialLibraryId: "lib_0000000",
|
|
CredentialPurpose: string(credential.ApplicationPurpose),
|
|
},
|
|
},
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
tt := tt
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
assert, require := assert.New(t), require.New(t)
|
|
got, err := target.NewCredentialLibrary(tt.args.targetId, tt.args.libraryId)
|
|
if tt.wantErr != 0 {
|
|
assert.Truef(errors.Match(errors.T(tt.wantErr), err), "want err: %q got: %q", tt.wantErr, err)
|
|
assert.Nil(got)
|
|
return
|
|
}
|
|
require.NoError(err)
|
|
require.NotNil(got)
|
|
assert.EqualValues(tt.want, got)
|
|
})
|
|
}
|
|
}
|