|
| 1 | +package codespace |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/cli/cli/v2/internal/codespaces/api" |
| 8 | + "github.com/cli/cli/v2/pkg/iostreams" |
| 9 | +) |
| 10 | + |
| 11 | +func TestPendingOperationDisallowsListPorts(t *testing.T) { |
| 12 | + app := testingPortsApp() |
| 13 | + |
| 14 | + if err := app.ListPorts(context.Background(), "disabledCodespace", nil); err != nil { |
| 15 | + if err.Error() != "codespace is disabled while it has a pending operation: Some pending operation" { |
| 16 | + t.Errorf("expected pending operation error, but got: %v", err) |
| 17 | + } |
| 18 | + } else { |
| 19 | + t.Error("expected pending operation error, but got nothing") |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | +func TestPendingOperationDisallowsUpdatePortVisability(t *testing.T) { |
| 24 | + app := testingPortsApp() |
| 25 | + |
| 26 | + if err := app.UpdatePortVisibility(context.Background(), "disabledCodespace", nil); err != nil { |
| 27 | + if err.Error() != "codespace is disabled while it has a pending operation: Some pending operation" { |
| 28 | + t.Errorf("expected pending operation error, but got: %v", err) |
| 29 | + } |
| 30 | + } else { |
| 31 | + t.Error("expected pending operation error, but got nothing") |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +func TestPendingOperationDisallowsForwardPorts(t *testing.T) { |
| 36 | + app := testingPortsApp() |
| 37 | + |
| 38 | + if err := app.ForwardPorts(context.Background(), "disabledCodespace", nil); err != nil { |
| 39 | + if err.Error() != "codespace is disabled while it has a pending operation: Some pending operation" { |
| 40 | + t.Errorf("expected pending operation error, but got: %v", err) |
| 41 | + } |
| 42 | + } else { |
| 43 | + t.Error("expected pending operation error, but got nothing") |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +func testingPortsApp() *App { |
| 48 | + user := &api.User{Login: "monalisa"} |
| 49 | + disabledCodespace := &api.Codespace{ |
| 50 | + Name: "disabledCodespace", |
| 51 | + PendingOperation: true, |
| 52 | + PendingOperationDisabledReason: "Some pending operation", |
| 53 | + } |
| 54 | + apiMock := &apiClientMock{ |
| 55 | + GetCodespaceFunc: func(_ context.Context, name string, _ bool) (*api.Codespace, error) { |
| 56 | + if name == "disabledCodespace" { |
| 57 | + return disabledCodespace, nil |
| 58 | + } |
| 59 | + return nil, nil |
| 60 | + }, |
| 61 | + GetUserFunc: func(_ context.Context) (*api.User, error) { |
| 62 | + return user, nil |
| 63 | + }, |
| 64 | + AuthorizedKeysFunc: func(_ context.Context, _ string) ([]byte, error) { |
| 65 | + return []byte{}, nil |
| 66 | + }, |
| 67 | + } |
| 68 | + |
| 69 | + io, _, _, _ := iostreams.Test() |
| 70 | + return NewApp(io, nil, apiMock, nil) |
| 71 | +} |
0 commit comments