Skip to content

Commit 515f112

Browse files
committed
linting
1 parent b9fd441 commit 515f112

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

cli/clibase/values.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func (i *Validator[T]) UnmarshalJSON(b []byte) error {
7979
return json.Unmarshal(b, i.Value)
8080
}
8181

82-
func (*Validator[T]) IsValidator() {}
82+
func (i *Validator[T]) Underlying() pflag.Value { return i.Value }
8383

8484
// values.go contains a standard set of value types that can be used as
8585
// Option Values.

cli/clibase/yaml.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"strings"
77

88
"github.com/mitchellh/go-wordwrap"
9+
"github.com/spf13/pflag"
910
"golang.org/x/xerrors"
1011
"gopkg.in/yaml.v3"
1112
)
@@ -75,7 +76,7 @@ func (optSet *OptionSet) MarshalYAML() (any, error) {
7576
HeadComment: comment,
7677
}
7778

78-
_, isValidator := opt.Value.(interface{ IsValidator() })
79+
_, isValidator := opt.Value.(interface{ Underlying() pflag.Value })
7980
var valueNode yaml.Node
8081
if opt.Value == nil {
8182
valueNode = yaml.Node{

cli/server_test.go

+13
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"time"
3030

3131
"github.com/go-chi/chi/v5"
32+
"github.com/spf13/pflag"
3233
"github.com/stretchr/testify/assert"
3334
"github.com/stretchr/testify/require"
3435
"go.uber.org/goleak"
@@ -1552,6 +1553,18 @@ func TestServer(t *testing.T) {
15521553
// ValueSource is not going to be correct on the `want`, so just
15531554
// match that field.
15541555
wantConfig.Options[i].ValueSource = gotConfig.Options[i].ValueSource
1556+
1557+
// If there is a wrapped value with a validator, unwrap it.
1558+
// The underlying doesn't compare well since it compares go pointers,
1559+
// and not the actual value.
1560+
if validator, isValidator := wantConfig.Options[i].Value.(interface{ Underlying() pflag.Value }); isValidator {
1561+
wantConfig.Options[i].Value = validator.Underlying()
1562+
}
1563+
1564+
if validator, isValidator := gotConfig.Options[i].Value.(interface{ Underlying() pflag.Value }); isValidator {
1565+
gotConfig.Options[i].Value = validator.Underlying()
1566+
}
1567+
15551568
assert.Equal(
15561569
t, wantConfig.Options[i],
15571570
gotConfig.Options[i],

0 commit comments

Comments
 (0)