File tree 3 files changed +16
-2
lines changed
3 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -79,7 +79,7 @@ func (i *Validator[T]) UnmarshalJSON(b []byte) error {
79
79
return json .Unmarshal (b , i .Value )
80
80
}
81
81
82
- func (* Validator [T ]) IsValidator () { }
82
+ func (i * Validator [T ]) Underlying () pflag. Value { return i . Value }
83
83
84
84
// values.go contains a standard set of value types that can be used as
85
85
// Option Values.
Original file line number Diff line number Diff line change 6
6
"strings"
7
7
8
8
"github.com/mitchellh/go-wordwrap"
9
+ "github.com/spf13/pflag"
9
10
"golang.org/x/xerrors"
10
11
"gopkg.in/yaml.v3"
11
12
)
@@ -75,7 +76,7 @@ func (optSet *OptionSet) MarshalYAML() (any, error) {
75
76
HeadComment : comment ,
76
77
}
77
78
78
- _ , isValidator := opt .Value .(interface { IsValidator () })
79
+ _ , isValidator := opt .Value .(interface { Underlying () pflag. Value })
79
80
var valueNode yaml.Node
80
81
if opt .Value == nil {
81
82
valueNode = yaml.Node {
Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ import (
29
29
"time"
30
30
31
31
"github.com/go-chi/chi/v5"
32
+ "github.com/spf13/pflag"
32
33
"github.com/stretchr/testify/assert"
33
34
"github.com/stretchr/testify/require"
34
35
"go.uber.org/goleak"
@@ -1552,6 +1553,18 @@ func TestServer(t *testing.T) {
1552
1553
// ValueSource is not going to be correct on the `want`, so just
1553
1554
// match that field.
1554
1555
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
+
1555
1568
assert .Equal (
1556
1569
t , wantConfig .Options [i ],
1557
1570
gotConfig .Options [i ],
You can’t perform that action at this time.
0 commit comments