(t *testing.T)
| 70 | } |
| 71 | |
| 72 | func TestCreateRun(t *testing.T) { |
| 73 | now := time.Date(2026, 1, 2, 3, 0, 0, 0, time.UTC) |
| 74 | sub := &client.Subscription{ID: "sub_1", ResourceURL: resource, EventTypes: []string{"test.a"}, ExpiresAt: now.Add(24 * time.Hour)} |
| 75 | |
| 76 | tests := []struct { |
| 77 | name string |
| 78 | stdoutTTY bool |
| 79 | stderrTTY bool |
| 80 | jsonFields []string |
| 81 | created bool |
| 82 | createErr error |
| 83 | wantOut string |
| 84 | wantErrOut string |
| 85 | wantErr string |
| 86 | }{ |
| 87 | { |
| 88 | name: "created on a tty", |
| 89 | stdoutTTY: true, |
| 90 | stderrTTY: true, |
| 91 | created: true, |
| 92 | wantOut: "sub_1\n", |
| 93 | wantErrOut: "✓ Created subscription sub_1, which expires in about 1 day\n", |
| 94 | }, |
| 95 | { |
| 96 | name: "reused on a tty", |
| 97 | stdoutTTY: true, |
| 98 | stderrTTY: true, |
| 99 | wantOut: "sub_1\n", |
| 100 | wantErrOut: "✓ Reused existing subscription sub_1, which expires in about 1 day\n", |
| 101 | }, |
| 102 | { |
| 103 | name: "stdout captured while stderr is a tty", |
| 104 | stderrTTY: true, |
| 105 | created: true, |
| 106 | wantOut: "sub_1\n", |
| 107 | wantErrOut: "✓ Created subscription sub_1, which expires in about 1 day\n", |
| 108 | }, |
| 109 | { |
| 110 | name: "stderr redirected while stdout is a tty", |
| 111 | stdoutTTY: true, |
| 112 | created: true, |
| 113 | wantOut: "sub_1\n", |
| 114 | }, |
| 115 | { |
| 116 | name: "not tty prints only the ID", |
| 117 | created: true, |
| 118 | wantOut: "sub_1\n", |
| 119 | }, |
| 120 | { |
| 121 | name: "json", |
| 122 | jsonFields: []string{"id", "resourceUrl"}, |
| 123 | wantOut: `{"id":"sub_1","resourceUrl":"https://github.com/OWNER/REPO/pull/1"}` + "\n", |
| 124 | }, |
| 125 | { |
| 126 | name: "missing resource", |
| 127 | createErr: client.ErrResourceNotFound, |
| 128 | wantErr: "could not subscribe to " + resource + "; the resource was not found, or you cannot access it", |
| 129 | }, |
nothing calls this directly
no test coverage detected