(t *testing.T)
| 14 | ) |
| 15 | |
| 16 | func TestListRun(t *testing.T) { |
| 17 | tests := []struct { |
| 18 | name string |
| 19 | opts ListOptions |
| 20 | isTTY bool |
| 21 | wantStdout string |
| 22 | wantStderr string |
| 23 | wantErr bool |
| 24 | }{ |
| 25 | { |
| 26 | name: "list authentication and signing keys; in tty", |
| 27 | opts: ListOptions{ |
| 28 | HTTPClient: func() (*http.Client, error) { |
| 29 | createdAt := time.Now().Add(time.Duration(-24) * time.Hour) |
| 30 | reg := &httpmock.Registry{} |
| 31 | reg.Register( |
| 32 | httpmock.REST("GET", "user/keys"), |
| 33 | httpmock.StringResponse(fmt.Sprintf(`[ |
| 34 | { |
| 35 | "id": 1234, |
| 36 | "key": "ssh-rsa AAAABbBB123", |
| 37 | "title": "Mac", |
| 38 | "created_at": "%[1]s" |
| 39 | }, |
| 40 | { |
| 41 | "id": 5678, |
| 42 | "key": "ssh-rsa EEEEEEEK247", |
| 43 | "title": "hubot@Windows", |
| 44 | "created_at": "%[1]s" |
| 45 | } |
| 46 | ]`, createdAt.Format(time.RFC3339))), |
| 47 | ) |
| 48 | reg.Register( |
| 49 | httpmock.REST("GET", "user/ssh_signing_keys"), |
| 50 | httpmock.StringResponse(fmt.Sprintf(`[ |
| 51 | { |
| 52 | "id": 321, |
| 53 | "key": "ssh-rsa AAAABbBB123", |
| 54 | "title": "Mac Signing", |
| 55 | "created_at": "%[1]s" |
| 56 | } |
| 57 | ]`, createdAt.Format(time.RFC3339))), |
| 58 | ) |
| 59 | return &http.Client{Transport: reg}, nil |
| 60 | }, |
| 61 | }, |
| 62 | isTTY: true, |
| 63 | wantStdout: heredoc.Doc(` |
| 64 | TITLE ID KEY TYPE ADDED |
| 65 | Mac 1234 ssh-rsa AAAABbBB123 authentication about 1 day ago |
| 66 | hubot@Windows 5678 ssh-rsa EEEEEEEK247 authentication about 1 day ago |
| 67 | Mac Signing 321 ssh-rsa AAAABbBB123 signing about 1 day ago |
| 68 | `), |
| 69 | wantStderr: "", |
| 70 | }, |
| 71 | { |
| 72 | name: "list authentication and signing keys; in non-tty", |
| 73 | opts: ListOptions{ |
nothing calls this directly
no test coverage detected