(t *testing.T)
| 14 | ) |
| 15 | |
| 16 | func TestVPNDaemonRun(t *testing.T) { |
| 17 | t.Parallel() |
| 18 | |
| 19 | t.Run("InvalidFlags", func(t *testing.T) { |
| 20 | t.Parallel() |
| 21 | |
| 22 | cases := []struct { |
| 23 | Name string |
| 24 | Args []string |
| 25 | ErrorContains string |
| 26 | }{ |
| 27 | { |
| 28 | Name: "NoReadHandle", |
| 29 | Args: []string{"--rpc-write-handle", "10"}, |
| 30 | ErrorContains: "rpc-read-handle", |
| 31 | }, |
| 32 | { |
| 33 | Name: "NoWriteHandle", |
| 34 | Args: []string{"--rpc-read-handle", "10"}, |
| 35 | ErrorContains: "rpc-write-handle", |
| 36 | }, |
| 37 | { |
| 38 | Name: "NegativeReadHandle", |
| 39 | Args: []string{"--rpc-read-handle", "-1", "--rpc-write-handle", "10"}, |
| 40 | ErrorContains: "rpc-read-handle", |
| 41 | }, |
| 42 | { |
| 43 | Name: "NegativeWriteHandle", |
| 44 | Args: []string{"--rpc-read-handle", "10", "--rpc-write-handle", "-1"}, |
| 45 | ErrorContains: "rpc-write-handle", |
| 46 | }, |
| 47 | { |
| 48 | Name: "SameHandles", |
| 49 | Args: []string{"--rpc-read-handle", "10", "--rpc-write-handle", "10"}, |
| 50 | ErrorContains: "rpc-read-handle", |
| 51 | }, |
| 52 | } |
| 53 | |
| 54 | for _, c := range cases { |
| 55 | t.Run(c.Name, func(t *testing.T) { |
| 56 | t.Parallel() |
| 57 | ctx := testutil.Context(t, testutil.WaitLong) |
| 58 | inv, _ := clitest.New(t, append([]string{"vpn-daemon", "run"}, c.Args...)...) |
| 59 | err := inv.WithContext(ctx).Run() |
| 60 | require.ErrorContains(t, err, c.ErrorContains) |
| 61 | }) |
| 62 | } |
| 63 | }) |
| 64 | |
| 65 | t.Run("StartsTunnel", func(t *testing.T) { |
| 66 | t.Parallel() |
| 67 | |
| 68 | r1, w1, err := os.Pipe() |
| 69 | require.NoError(t, err) |
| 70 | defer w1.Close() |
| 71 | |
| 72 | r2, w2, err := os.Pipe() |
| 73 | require.NoError(t, err) |
nothing calls this directly
no test coverage detected