Add skip daemon flag and send recently authed tokens to daemon (#3883)
* Add skip daemon flag and send recently authed tokens to daemon * Rename flag skip-daemon to skip-cache-daemon * adding option test * move common.Options to base.Option * SocketAddress returns *url.URL, fix search test
This commit is contained in:
1 parent
2f7459fa40
commit
3a7ea64a31
27 files changed
+429
-419
No files matched your search
@@ -1,39 +0,0 @@
|
||||
// Copyright (c) HashiCorp, Inc.
|
||||
// SPDX-License-Identifier: BUSL-1.1
|
||||
|
||||
package common
|
||||
|
||||
// GetOpts - iterate the inbound Options and return a struct.
|
||||
func GetOpts(opt ...Option) (*Options, error) {
|
||||
opts := getDefaultOptions()
|
||||
for _, o := range opt {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
if err := o(opts); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return opts, nil
|
||||
}
|
||||
|
||||
// Option - how Options are passed as arguments.
|
||||
type Option func(*Options) error
|
||||
|
||||
// Options - how Options are represented.
|
||||
type Options struct {
|
||||
WithSkipScopeIdFlag bool
|
||||
}
|
||||
|
||||
func getDefaultOptions() *Options {
|
||||
return &Options{}
|
||||
}
|
||||
|
||||
// WithSkipScopeIdFlag tells a command to not create a scope ID flag (usually
|
||||
// because it's already been defined)
|
||||
func WithSkipScopeIdFlag(with bool) Option {
|
||||
return func(o *Options) error {
|
||||
o.WithSkipScopeIdFlag = with
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
// Copyright (c) HashiCorp, Inc.
|
||||
// SPDX-License-Identifier: BUSL-1.1
|
||||
|
||||
package common
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// Test_GetOpts provides unit tests for GetOpts and all the options
|
||||
func Test_GetOpts(t *testing.T) {
|
||||
t.Parallel()
|
||||
t.Run("nil-options", func(t *testing.T) {
|
||||
assert, require := assert.New(t), require.New(t)
|
||||
opts, err := GetOpts(nil, nil)
|
||||
require.NoError(err)
|
||||
testOpts := getDefaultOptions()
|
||||
assert.Equal(opts, testOpts)
|
||||
})
|
||||
|
||||
t.Run("WithSkipScopeIdFlag", func(t *testing.T) {
|
||||
assert, require := assert.New(t), require.New(t)
|
||||
opts, err := GetOpts(WithSkipScopeIdFlag(true))
|
||||
require.NoError(err)
|
||||
testOpts := getDefaultOptions()
|
||||
testOpts.WithSkipScopeIdFlag = true
|
||||
assert.Equal(opts, testOpts)
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user