Files
threshold/internal/auth/password/account_test.go
T
Michael GaffneyandJeff Mitchell 94cb79bbdd See how Boundary would look with gofumpt applied (#853)
* See how Boundary would look with https://github.com/mvdan/gofumpt applied

Results of running `gofumpt -w -s .`

* Update tools file and Makefile for gofumpt

Co-authored-by: Jeff Mitchell <jeffrey.mitchell@gmail.com>
2021-01-07 10:02:32 -05:00

115 lines
2.2 KiB
Go

package password
import (
"testing"
"github.com/hashicorp/boundary/internal/auth/password/store"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/iam"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestAccount_New(t *testing.T) {
conn, _ := db.TestSetup(t, "postgres")
wrapper := db.TestWrapper(t)
o, _ := iam.TestScopes(t, iam.TestRepo(t, conn, wrapper))
auts := TestAuthMethods(t, conn, o.GetPublicId(), 1)
aut := auts[0]
type args struct {
authMethodId string
opts []Option
}
tests := []struct {
name string
args args
want *Account
wantErr bool
}{
{
name: "blank-authMethodId",
args: args{
authMethodId: "",
},
want: nil,
wantErr: true,
},
{
name: "valid-no-options",
args: args{
authMethodId: aut.GetPublicId(),
},
want: &Account{
Account: &store.Account{
AuthMethodId: aut.GetPublicId(),
},
},
},
{
name: "valid-with-user-name",
args: args{
authMethodId: aut.GetPublicId(),
opts: []Option{
WithLoginName("kazmierczak1"),
},
},
want: &Account{
Account: &store.Account{
AuthMethodId: aut.GetPublicId(),
LoginName: "kazmierczak1",
},
},
},
{
name: "valid-with-name",
args: args{
authMethodId: aut.GetPublicId(),
opts: []Option{
WithName("test-name"),
},
},
want: &Account{
Account: &store.Account{
AuthMethodId: aut.GetPublicId(),
Name: "test-name",
},
},
},
{
name: "valid-with-description",
args: args{
authMethodId: aut.GetPublicId(),
opts: []Option{
WithDescription("test-description"),
},
},
want: &Account{
Account: &store.Account{
AuthMethodId: aut.GetPublicId(),
Description: "test-description",
},
},
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
assert, require := assert.New(t), require.New(t)
got, err := NewAccount(tt.args.authMethodId, tt.args.opts...)
if tt.wantErr {
assert.Error(err)
require.Nil(got)
return
}
assert.NoError(err)
require.NotNil(got)
assert.Emptyf(got.PublicId, "PublicId set")
assert.Equal(tt.want, got)
})
}
}