mirror of https://github.com/hashicorp/boundary
clientcache commands now can output curl strings (#4042)
parent
b71d134e06
commit
9aab26e91b
@ -0,0 +1,39 @@
|
||||
// Copyright (c) HashiCorp, Inc.
|
||||
// SPDX-License-Identifier: BUSL-1.1
|
||||
|
||||
package client
|
||||
|
||||
// GetOpts - iterate the inbound Options and return a struct.
|
||||
func getOpts(opt ...Option) (options, error) {
|
||||
opts := getDefaultOptions()
|
||||
for _, o := range opt {
|
||||
if o != nil {
|
||||
err := o(&opts)
|
||||
if err != nil {
|
||||
return opts, err
|
||||
}
|
||||
}
|
||||
}
|
||||
return opts, nil
|
||||
}
|
||||
|
||||
// Option - how Options are passed as arguments.
|
||||
type Option func(*options) error
|
||||
|
||||
// options - how options are represented.
|
||||
type options struct {
|
||||
withOutputCurlString bool
|
||||
}
|
||||
|
||||
func getDefaultOptions() options {
|
||||
return options{}
|
||||
}
|
||||
|
||||
// WithOutputCurlString specifies that the client should return an
|
||||
// OutputStringError that prints out the curl string for the request being generated.
|
||||
func WithOutputCurlString() Option {
|
||||
return func(o *options) error {
|
||||
o.withOutputCurlString = true
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
// Copyright (c) HashiCorp, Inc.
|
||||
// SPDX-License-Identifier: BUSL-1.1
|
||||
|
||||
package client
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func Test_GetOpts(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
t.Run("default", func(t *testing.T) {
|
||||
opts, err := getOpts()
|
||||
assert.NoError(t, err)
|
||||
testOpts := options{}
|
||||
assert.Equal(t, opts, testOpts)
|
||||
})
|
||||
t.Run("WithOutputCurlString", func(t *testing.T) {
|
||||
opts, err := getOpts(WithOutputCurlString())
|
||||
assert.NoError(t, err)
|
||||
testOpts := getDefaultOptions()
|
||||
testOpts.withOutputCurlString = true
|
||||
assert.Equal(t, opts, testOpts)
|
||||
})
|
||||
}
|
||||
Loading…
Reference in new issue