-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor for self contained domain logic
- Loading branch information
1 parent
e98b892
commit be119eb
Showing
48 changed files
with
719 additions
and
399 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
//go:build cgo | ||
// +build cgo | ||
|
||
package cache | ||
package db | ||
|
||
import ( | ||
_ "gorm.io/driver/sqlite" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
//go:build !cgo | ||
// +build !cgo | ||
|
||
package cache | ||
package db | ||
|
||
import ( | ||
_ "github.com/glebarez/go-sqlite" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 12 additions & 18 deletions
30
internal/cmd/commands/daemon/options_test.go → internal/cache/db/options_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,40 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
|
||
package daemon | ||
package db | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/hashicorp/boundary/api/authtokens" | ||
"github.com/hashicorp/boundary/internal/daemon/cache" | ||
"github.com/hashicorp/go-dbw" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_GetOpts(t *testing.T) { | ||
t.Parallel() | ||
ctx := context.Background() | ||
|
||
t.Run("default", func(t *testing.T) { | ||
opts, err := getOpts() | ||
require.NoError(t, err) | ||
testOpts := options{} | ||
testOpts := options{ | ||
withDbType: dbw.Sqlite, | ||
} | ||
assert.Equal(t, opts, testOpts) | ||
}) | ||
t.Run("WithDebug", func(t *testing.T) { | ||
opts, err := getOpts(WithDebug(ctx, true)) | ||
t.Run("WithUrl", func(t *testing.T) { | ||
url := "something" | ||
opts, err := getOpts(WithUrl(url)) | ||
require.NoError(t, err) | ||
testOpts := getDefaultOptions() | ||
testOpts.withDebug = true | ||
testOpts.withUrl = url | ||
assert.Equal(t, opts, testOpts) | ||
}) | ||
t.Run("WithBoundaryTokenReaderFunc", func(t *testing.T) { | ||
var f cache.BoundaryTokenReaderFn = func(ctx context.Context, addr, token string) (*authtokens.AuthToken, error) { | ||
return nil, nil | ||
} | ||
opts, err := getOpts(WithBoundaryTokenReaderFunc(ctx, f)) | ||
t.Run("WithDebug", func(t *testing.T) { | ||
opts, err := getOpts(WithDebug(true)) | ||
require.NoError(t, err) | ||
|
||
assert.NotNil(t, opts.withBoundaryTokenReaderFunc) | ||
opts.withBoundaryTokenReaderFunc = nil | ||
|
||
testOpts := getDefaultOptions() | ||
testOpts.withDebug = true | ||
assert.Equal(t, opts, testOpts) | ||
}) | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
|
||
package cache | ||
|
||
import ( | ||
"github.com/hashicorp/go-dbw" | ||
) | ||
|
||
type options struct { | ||
withUpdateLastAccessedTime bool | ||
withDbType dbw.DbType | ||
withTargetRetrievalFunc TargetRetrievalFunc | ||
withSessionRetrievalFunc SessionRetrievalFunc | ||
} | ||
|
||
// Option - how options are passed as args | ||
type Option func(*options) error | ||
|
||
func getDefaultOptions() options { | ||
return options{ | ||
withDbType: dbw.Sqlite, | ||
} | ||
} | ||
|
||
func getOpts(opt ...Option) (options, error) { | ||
opts := getDefaultOptions() | ||
|
||
for _, o := range opt { | ||
if err := o(&opts); err != nil { | ||
return opts, err | ||
} | ||
} | ||
return opts, nil | ||
} | ||
|
||
// WithUpdateLastAccessedTime provides an option for updating the last access time | ||
func WithUpdateLastAccessedTime(b bool) Option { | ||
return func(o *options) error { | ||
o.withUpdateLastAccessedTime = b | ||
return nil | ||
} | ||
} | ||
|
||
// WithTargetRetrievalFunc provides an option for specifying a targetRetrievalFunc | ||
func WithTargetRetrievalFunc(fn TargetRetrievalFunc) Option { | ||
return func(o *options) error { | ||
o.withTargetRetrievalFunc = fn | ||
return nil | ||
} | ||
} | ||
|
||
// WithSessionRetrievalFunc provides an option for specifying a sessionRetrievalFunc | ||
func WithSessionRetrievalFunc(fn SessionRetrievalFunc) Option { | ||
return func(o *options) error { | ||
o.withSessionRetrievalFunc = fn | ||
return nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
|
||
package cache | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/hashicorp/boundary/api/sessions" | ||
"github.com/hashicorp/boundary/api/targets" | ||
"github.com/hashicorp/go-dbw" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_GetOpts(t *testing.T) { | ||
t.Parallel() | ||
|
||
t.Run("default", func(t *testing.T) { | ||
opts, err := getOpts() | ||
require.NoError(t, err) | ||
testOpts := options{ | ||
withDbType: dbw.Sqlite, | ||
} | ||
assert.Equal(t, opts, testOpts) | ||
}) | ||
t.Run("WithUpdateLastAccessedTime", func(t *testing.T) { | ||
opts, err := getOpts(WithUpdateLastAccessedTime(true)) | ||
require.NoError(t, err) | ||
testOpts := getDefaultOptions() | ||
testOpts.withUpdateLastAccessedTime = true | ||
assert.Equal(t, opts, testOpts) | ||
}) | ||
t.Run("WithTargetRetrievalFunc", func(t *testing.T) { | ||
var f TargetRetrievalFunc = func(ctx context.Context, keyringstring, tokenName string) ([]*targets.Target, error) { return nil, nil } | ||
opts, err := getOpts(WithTargetRetrievalFunc(f)) | ||
require.NoError(t, err) | ||
|
||
assert.NotNil(t, opts.withTargetRetrievalFunc) | ||
opts.withTargetRetrievalFunc = nil | ||
|
||
testOpts := getDefaultOptions() | ||
assert.Equal(t, opts, testOpts) | ||
}) | ||
t.Run("WithSessionRetrievalFunc", func(t *testing.T) { | ||
var f SessionRetrievalFunc = func(ctx context.Context, keyringstring, tokenName string) ([]*sessions.Session, error) { | ||
return nil, nil | ||
} | ||
opts, err := getOpts(WithSessionRetrievalFunc(f)) | ||
require.NoError(t, err) | ||
|
||
assert.NotNil(t, opts.withSessionRetrievalFunc) | ||
opts.withSessionRetrievalFunc = nil | ||
|
||
testOpts := getDefaultOptions() | ||
assert.Equal(t, opts, testOpts) | ||
}) | ||
} |
Oops, something went wrong.