(t *testing.T)
| 15 | ) |
| 16 | |
| 17 | func Test_listRun(t *testing.T) { |
| 18 | tests := []struct { |
| 19 | name string |
| 20 | opts ListOptions |
| 21 | isTTY bool |
| 22 | wantStdout string |
| 23 | wantStderr string |
| 24 | wantErr bool |
| 25 | }{ |
| 26 | { |
| 27 | name: "list tty", |
| 28 | opts: ListOptions{HTTPClient: func() (*http.Client, error) { |
| 29 | createdAt := time.Now().Add(time.Duration(-24) * time.Hour) |
| 30 | expiresAt, _ := time.Parse(time.RFC3339, "2099-01-01T15:44:24+01:00") |
| 31 | noExpires := time.Time{} |
| 32 | reg := &httpmock.Registry{} |
| 33 | reg.Register( |
| 34 | httpmock.REST("GET", "user/gpg_keys"), |
| 35 | httpmock.StringResponse(fmt.Sprintf(`[ |
| 36 | { |
| 37 | "id": 1234, |
| 38 | "key_id": "ABCDEF1234567890", |
| 39 | "public_key": "xJMEWfoofoofoo", |
| 40 | "emails": [{"email": "johnny@test.com"}], |
| 41 | "created_at": "%[1]s", |
| 42 | "expires_at": "%[2]s" |
| 43 | }, |
| 44 | { |
| 45 | "id": 5678, |
| 46 | "key_id": "1234567890ABCDEF", |
| 47 | "public_key": "xJMEWbarbarbar", |
| 48 | "emails": [{"email": "monalisa@github.com"}], |
| 49 | "created_at": "%[1]s", |
| 50 | "expires_at": "%[3]s" |
| 51 | } |
| 52 | ]`, createdAt.Format(time.RFC3339), |
| 53 | expiresAt.Format(time.RFC3339), |
| 54 | noExpires.Format(time.RFC3339))), |
| 55 | ) |
| 56 | return &http.Client{Transport: reg}, nil |
| 57 | }}, |
| 58 | isTTY: true, |
| 59 | wantStdout: heredoc.Doc(` |
| 60 | EMAIL KEY ID PUBLIC KEY ADDED EXPIRES |
| 61 | johnny@test.com ABCDEF123456... xJMEWfoofoofoo about 1 day ago 2099-01-01 |
| 62 | monalisa@github... 1234567890AB... xJMEWbarbarbar about 1 day ago Never |
| 63 | `), |
| 64 | wantStderr: "", |
| 65 | }, |
| 66 | { |
| 67 | name: "list non-tty", |
| 68 | opts: ListOptions{HTTPClient: func() (*http.Client, error) { |
| 69 | createdAt1, _ := time.Parse(time.RFC3339, "2020-06-11T15:44:24+01:00") |
| 70 | expiresAt, _ := time.Parse(time.RFC3339, "2099-01-01T15:44:24+01:00") |
| 71 | createdAt2, _ := time.Parse(time.RFC3339, "2021-01-11T15:44:24+01:00") |
| 72 | noExpires := time.Time{} |
| 73 | reg := &httpmock.Registry{} |
| 74 | reg.Register( |
nothing calls this directly
no test coverage detected