mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-12 05:37:32 +00:00
cmd/tailscale/cli: add beginnings of tailscale set
Signed-off-by: Maisem Ali <maisem@tailscale.com>
This commit is contained in:

committed by
Brad Fitzpatrick

parent
a471681e28
commit
19b5586573
15
ipn/prefs.go
15
ipn/prefs.go
@@ -244,6 +244,21 @@ func (p *Prefs) ApplyEdits(m *MaskedPrefs) {
|
||||
}
|
||||
}
|
||||
|
||||
// IsEmpty reports whether there are no masks set or if m is nil.
|
||||
func (m *MaskedPrefs) IsEmpty() bool {
|
||||
if m == nil {
|
||||
return true
|
||||
}
|
||||
mv := reflect.ValueOf(m).Elem()
|
||||
fields := mv.NumField()
|
||||
for i := 1; i < fields; i++ {
|
||||
if mv.Field(i).Bool() {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (m *MaskedPrefs) Pretty() string {
|
||||
if m == nil {
|
||||
return "MaskedPrefs{<nil>}"
|
||||
|
@@ -826,3 +826,48 @@ func TestControlURLOrDefault(t *testing.T) {
|
||||
t.Errorf("got %q; want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMaskedPrefsIsEmpty(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
mp *MaskedPrefs
|
||||
wantEmpty bool
|
||||
}{
|
||||
{
|
||||
name: "nil",
|
||||
wantEmpty: true,
|
||||
},
|
||||
{
|
||||
name: "empty",
|
||||
wantEmpty: true,
|
||||
mp: &MaskedPrefs{},
|
||||
},
|
||||
{
|
||||
name: "no-masks",
|
||||
wantEmpty: true,
|
||||
mp: &MaskedPrefs{
|
||||
Prefs: Prefs{
|
||||
WantRunning: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "with-mask",
|
||||
wantEmpty: false,
|
||||
mp: &MaskedPrefs{
|
||||
Prefs: Prefs{
|
||||
WantRunning: true,
|
||||
},
|
||||
WantRunningSet: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
got := tc.mp.IsEmpty()
|
||||
if got != tc.wantEmpty {
|
||||
t.Fatalf("mp.IsEmpty = %t; want %t", got, tc.wantEmpty)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user