(t *testing.T)
| 66 | } |
| 67 | |
| 68 | func TestDeleteRun(t *testing.T) { |
| 69 | tests := []struct { |
| 70 | name string |
| 71 | tty bool |
| 72 | deleteErr error |
| 73 | wantErrOut string |
| 74 | wantErr string |
| 75 | }{ |
| 76 | { |
| 77 | name: "tty", |
| 78 | tty: true, |
| 79 | wantErrOut: "✓ Deleted subscription sub_1\n", |
| 80 | }, |
| 81 | { |
| 82 | name: "not tty", |
| 83 | }, |
| 84 | { |
| 85 | name: "missing subscription", |
| 86 | tty: true, |
| 87 | deleteErr: client.ErrSubscriptionNotFound, |
| 88 | wantErr: "subscription sub_1 was not found; it may have expired or been deleted, or you cannot access it", |
| 89 | }, |
| 90 | { |
| 91 | name: "other error", |
| 92 | deleteErr: client.ErrPreviewNotEnabled, |
| 93 | wantErr: "failed to delete subscription: event subscriptions are in preview", |
| 94 | }, |
| 95 | } |
| 96 | |
| 97 | for _, tt := range tests { |
| 98 | t.Run(tt.name, func(t *testing.T) { |
| 99 | ios, _, stdout, stderr := iostreams.Test() |
| 100 | ios.SetStdoutTTY(tt.tty) |
| 101 | ios.SetStderrTTY(tt.tty) |
| 102 | var gotHost, gotID string |
| 103 | opts := &DeleteOptions{ |
| 104 | IO: ios, |
| 105 | Config: func() (gh.Config, error) { return config.NewMockConfig(), nil }, |
| 106 | EventClient: func(host string) (client.EventClient, error) { |
| 107 | gotHost = host |
| 108 | return &client.EventClientMock{ |
| 109 | DeleteSubscriptionFunc: func(_ context.Context, id string) error { |
| 110 | gotID = id |
| 111 | return tt.deleteErr |
| 112 | }, |
| 113 | }, nil |
| 114 | }, |
| 115 | ID: "sub_1", |
| 116 | } |
| 117 | |
| 118 | err := deleteRun(context.Background(), opts) |
| 119 | |
| 120 | assert.Equal(t, "github.com", gotHost) |
| 121 | assert.Equal(t, "sub_1", gotID) |
| 122 | if tt.wantErr != "" { |
| 123 | require.ErrorContains(t, err, tt.wantErr) |
| 124 | } else { |
| 125 | require.NoError(t, err) |
nothing calls this directly
no test coverage detected