(t *testing.T)
| 68 | } |
| 69 | |
| 70 | func Test_listRun(t *testing.T) { |
| 71 | tests := []struct { |
| 72 | name string |
| 73 | opts ListOptions |
| 74 | isTTY bool |
| 75 | wantStdout string |
| 76 | wantStderr string |
| 77 | wantErr bool |
| 78 | }{ |
| 79 | { |
| 80 | name: "list tty", |
| 81 | opts: ListOptions{HTTPClient: func() (*http.Client, error) { |
| 82 | createdAt := time.Now().Add(time.Duration(-24) * time.Hour) |
| 83 | expiresAt, _ := time.Parse(time.RFC3339, "2099-01-01T15:44:24+01:00") |
| 84 | noExpires := time.Time{} |
| 85 | reg := &httpmock.Registry{} |
| 86 | reg.Register( |
| 87 | httpmock.REST("GET", "user/gpg_keys"), |
| 88 | httpmock.StringResponse(fmt.Sprintf(`[ |
| 89 | { |
| 90 | "id": 1234, |
| 91 | "key_id": "ABCDEF1234567890", |
| 92 | "public_key": "xJMEWfoofoofoo", |
| 93 | "emails": [{"email": "johnny@test.com"}], |
| 94 | "created_at": "%[1]s", |
| 95 | "expires_at": "%[2]s" |
| 96 | }, |
| 97 | { |
| 98 | "id": 5678, |
| 99 | "key_id": "1234567890ABCDEF", |
| 100 | "public_key": "xJMEWbarbarbar", |
| 101 | "emails": [{"email": "monalisa@github.com"}], |
| 102 | "created_at": "%[1]s", |
| 103 | "expires_at": "%[3]s" |
| 104 | } |
| 105 | ]`, createdAt.Format(time.RFC3339), |
| 106 | expiresAt.Format(time.RFC3339), |
| 107 | noExpires.Format(time.RFC3339))), |
| 108 | ) |
| 109 | return &http.Client{Transport: reg}, nil |
| 110 | }}, |
| 111 | isTTY: true, |
| 112 | wantStdout: heredoc.Doc(` |
| 113 | EMAIL KEY ID PUBLIC KEY ADDED EXPIRES |
| 114 | johnny@test.com ABCDEF123456... xJMEWfoofoofoo about 1 day ago 2099-01-01 |
| 115 | monalisa@github... 1234567890AB... xJMEWbarbarbar about 1 day ago Never |
| 116 | `), |
| 117 | wantStderr: "", |
| 118 | }, |
| 119 | { |
| 120 | name: "list non-tty", |
| 121 | opts: ListOptions{HTTPClient: func() (*http.Client, error) { |
| 122 | createdAt1, _ := time.Parse(time.RFC3339, "2020-06-11T15:44:24+01:00") |
| 123 | expiresAt, _ := time.Parse(time.RFC3339, "2099-01-01T15:44:24+01:00") |
| 124 | createdAt2, _ := time.Parse(time.RFC3339, "2021-01-11T15:44:24+01:00") |
| 125 | noExpires := time.Time{} |
| 126 | reg := &httpmock.Registry{} |
| 127 | reg.Register( |
nothing calls this directly
no test coverage detected