-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle nested parameters in granted settings set command (#690)
* add more robust way to update settings including nested attributes * comments * Add failing test coverage * fix config setting for keychain * fix test --------- Co-authored-by: JoshuaWilkes <[email protected]>
- Loading branch information
1 parent
faf4112
commit 151c4c4
Showing
2 changed files
with
191 additions
and
32 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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package settings | ||
|
||
import ( | ||
"slices" | ||
"testing" | ||
|
||
"github.com/common-fate/grab" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestFieldOptions(t *testing.T) { | ||
type input struct { | ||
A string | ||
B struct { | ||
C string | ||
D *string | ||
} | ||
} | ||
tests := []struct { | ||
name string | ||
input any | ||
want []string | ||
want1 map[string]field | ||
}{ | ||
{ | ||
name: "ok", | ||
input: input{}, | ||
want: []string{"A", "B.C"}, | ||
}, | ||
{ | ||
name: "ok", | ||
input: &input{}, | ||
want: []string{"A", "B.C"}, | ||
}, | ||
{ | ||
name: "ok", | ||
input: &input{ | ||
A: "A", | ||
B: struct { | ||
C string | ||
D *string | ||
}{ | ||
C: "C", | ||
D: grab.Ptr("D"), | ||
}, | ||
}, | ||
want: []string{"A", "B.C", "B.D"}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got := FieldOptions(tt.input) | ||
keys := make([]string, 0, len(got)) | ||
for k := range got { | ||
keys = append(keys, k) | ||
} | ||
|
||
//sort to make sure the keys are in the correct order for the test | ||
slices.Sort(keys) | ||
|
||
assert.Equal(t, tt.want, keys) | ||
}) | ||
} | ||
} |