(t *testing.T)
| 16 | ) |
| 17 | |
| 18 | func TestResolveWorkspaceHome(t *testing.T) { |
| 19 | t.Parallel() |
| 20 | |
| 21 | tests := []struct { |
| 22 | name string |
| 23 | resp workspacesdk.LSResponse |
| 24 | lsErr error |
| 25 | want string |
| 26 | wantErr bool |
| 27 | errMatch string |
| 28 | }{ |
| 29 | { |
| 30 | name: "StandardLinuxHome", |
| 31 | resp: workspacesdk.LSResponse{AbsolutePathString: "/home/coder"}, |
| 32 | want: "/home/coder", |
| 33 | }, |
| 34 | { |
| 35 | name: "NonStandardHome", |
| 36 | resp: workspacesdk.LSResponse{AbsolutePathString: "/Users/dev"}, |
| 37 | want: "/Users/dev", |
| 38 | }, |
| 39 | { |
| 40 | name: "LSError", |
| 41 | lsErr: xerrors.New("list failed"), |
| 42 | wantErr: true, |
| 43 | errMatch: "list failed", |
| 44 | }, |
| 45 | { |
| 46 | name: "EmptyAbsolutePathString", |
| 47 | resp: workspacesdk.LSResponse{AbsolutePathString: ""}, |
| 48 | wantErr: true, |
| 49 | errMatch: "workspace home path is empty", |
| 50 | }, |
| 51 | { |
| 52 | name: "WhitespaceOnlyAbsolutePathString", |
| 53 | resp: workspacesdk.LSResponse{AbsolutePathString: " \t\n "}, |
| 54 | wantErr: true, |
| 55 | errMatch: "workspace home path is empty", |
| 56 | }, |
| 57 | } |
| 58 | |
| 59 | for _, testCase := range tests { |
| 60 | t.Run(testCase.name, func(t *testing.T) { |
| 61 | t.Parallel() |
| 62 | |
| 63 | ctrl := gomock.NewController(t) |
| 64 | conn := agentconnmock.NewMockAgentConn(ctrl) |
| 65 | |
| 66 | conn.EXPECT().LS( |
| 67 | gomock.Any(), |
| 68 | "", |
| 69 | workspacesdk.LSRequest{ |
| 70 | Path: []string{}, |
| 71 | Relativity: workspacesdk.LSRelativityHome, |
| 72 | }, |
| 73 | ).Return(testCase.resp, testCase.lsErr) |
| 74 | |
| 75 | got, err := chattool.ResolveWorkspaceHome(context.Background(), conn) |
nothing calls this directly
no test coverage detected