|
1 | 1 | package system |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "context" |
5 | | - "testing" |
| 4 | + "context" |
| 5 | + "testing" |
6 | 6 |
|
7 | | - "github.com/stretchr/testify/assert" |
8 | | - "google.golang.org/grpc/metadata" |
| 7 | + "github.com/stretchr/testify/assert" |
| 8 | + "google.golang.org/grpc/metadata" |
9 | 9 | ) |
10 | 10 |
|
| 11 | +func TestInfo_CopyFlagsFrom(t *testing.T) { |
| 12 | + origin := &Info{} |
| 13 | + serverSSHAllowed := true |
| 14 | + origin.SetFlags( |
| 15 | + true, // RosenpassEnabled |
| 16 | + false, // RosenpassPermissive |
| 17 | + &serverSSHAllowed, |
| 18 | + true, // DisableClientRoutes |
| 19 | + false, // DisableServerRoutes |
| 20 | + true, // DisableDNS |
| 21 | + false, // DisableFirewall |
| 22 | + true, // BlockLANAccess |
| 23 | + false, // BlockInbound |
| 24 | + true, // LazyConnectionEnabled |
| 25 | + ) |
| 26 | + |
| 27 | + got := &Info{} |
| 28 | + got.CopyFlagsFrom(origin) |
| 29 | + |
| 30 | + if got.RosenpassEnabled != true { |
| 31 | + t.Fatalf("RosenpassEnabled not copied: got %v", got.RosenpassEnabled) |
| 32 | + } |
| 33 | + if got.RosenpassPermissive != false { |
| 34 | + t.Fatalf("RosenpassPermissive not copied: got %v", got.RosenpassPermissive) |
| 35 | + } |
| 36 | + if got.ServerSSHAllowed != true { |
| 37 | + t.Fatalf("ServerSSHAllowed not copied: got %v", got.ServerSSHAllowed) |
| 38 | + } |
| 39 | + if got.DisableClientRoutes != true { |
| 40 | + t.Fatalf("DisableClientRoutes not copied: got %v", got.DisableClientRoutes) |
| 41 | + } |
| 42 | + if got.DisableServerRoutes != false { |
| 43 | + t.Fatalf("DisableServerRoutes not copied: got %v", got.DisableServerRoutes) |
| 44 | + } |
| 45 | + if got.DisableDNS != true { |
| 46 | + t.Fatalf("DisableDNS not copied: got %v", got.DisableDNS) |
| 47 | + } |
| 48 | + if got.DisableFirewall != false { |
| 49 | + t.Fatalf("DisableFirewall not copied: got %v", got.DisableFirewall) |
| 50 | + } |
| 51 | + if got.BlockLANAccess != true { |
| 52 | + t.Fatalf("BlockLANAccess not copied: got %v", got.BlockLANAccess) |
| 53 | + } |
| 54 | + if got.BlockInbound != false { |
| 55 | + t.Fatalf("BlockInbound not copied: got %v", got.BlockInbound) |
| 56 | + } |
| 57 | + if got.LazyConnectionEnabled != true { |
| 58 | + t.Fatalf("LazyConnectionEnabled not copied: got %v", got.LazyConnectionEnabled) |
| 59 | + } |
| 60 | + |
| 61 | + // ensure CopyFlagsFrom does not touch unrelated fields |
| 62 | + origin.Hostname = "host-a" |
| 63 | + got.Hostname = "host-b" |
| 64 | + got.CopyFlagsFrom(origin) |
| 65 | + if got.Hostname != "host-b" { |
| 66 | + t.Fatalf("CopyFlagsFrom should not overwrite non-flag fields, got Hostname=%q", got.Hostname) |
| 67 | + } |
| 68 | +} |
| 69 | + |
11 | 70 | func Test_LocalWTVersion(t *testing.T) { |
12 | 71 | got := GetInfo(context.TODO()) |
13 | 72 | want := "development" |
|
0 commit comments