This change removes the hard-coded credential purpose for the Credential Libraries. It also moves the logic of creating CredentialLibraries from CredentialSources out of the repository and into the targets.Service. This refactor will allow for additional credential purposes to be supported in both the service and the 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, credential.ApplicationPurpose)
|
|
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)
|
|
})
|
|
}
|
|
}
|