|
| 1 | +package codersdk |
| 2 | + |
| 3 | +import "testing" |
| 4 | + |
| 5 | +func TestWorkspaceDisplayStatus(t *testing.T) { |
| 6 | + t.Parallel() |
| 7 | + type args struct { |
| 8 | + jobStatus ProvisionerJobStatus |
| 9 | + transition WorkspaceTransition |
| 10 | + } |
| 11 | + tests := []struct { |
| 12 | + name string |
| 13 | + jobStatus ProvisionerJobStatus |
| 14 | + transition WorkspaceTransition |
| 15 | + want string |
| 16 | + }{ |
| 17 | + { |
| 18 | + name: "SucceededStatusWithStartTransition", |
| 19 | + jobStatus: ProvisionerJobSucceeded, |
| 20 | + transition: WorkspaceTransitionStart, |
| 21 | + want: "Started", |
| 22 | + }, |
| 23 | + { |
| 24 | + name: "SucceededStatusWithStopTransition", |
| 25 | + jobStatus: ProvisionerJobSucceeded, |
| 26 | + transition: WorkspaceTransitionStop, |
| 27 | + want: "Stopped", |
| 28 | + }, |
| 29 | + { |
| 30 | + name: "SucceededStatusWithDeleteTransition", |
| 31 | + jobStatus: ProvisionerJobSucceeded, |
| 32 | + transition: WorkspaceTransitionDelete, |
| 33 | + want: "Deleted", |
| 34 | + }, |
| 35 | + { |
| 36 | + name: "RunningStatusWithStartTransition", |
| 37 | + jobStatus: ProvisionerJobRunning, |
| 38 | + transition: WorkspaceTransitionStart, |
| 39 | + want: "Starting", |
| 40 | + }, |
| 41 | + { |
| 42 | + name: "RunningStatusWithStopTransition", |
| 43 | + jobStatus: ProvisionerJobRunning, |
| 44 | + transition: WorkspaceTransitionStop, |
| 45 | + want: "Stopping", |
| 46 | + }, |
| 47 | + { |
| 48 | + name: "RunningStatusWithDeleteTransition", |
| 49 | + jobStatus: ProvisionerJobRunning, |
| 50 | + transition: WorkspaceTransitionDelete, |
| 51 | + want: "Deleting", |
| 52 | + }, |
| 53 | + { |
| 54 | + name: "PendingStatusWithStartTransition", |
| 55 | + jobStatus: ProvisionerJobPending, |
| 56 | + transition: WorkspaceTransitionStart, |
| 57 | + want: "Queued", |
| 58 | + }, |
| 59 | + { |
| 60 | + name: "CancelingStatusWithStartTransition", |
| 61 | + jobStatus: ProvisionerJobCanceling, |
| 62 | + transition: WorkspaceTransitionStart, |
| 63 | + want: "Canceling action", |
| 64 | + }, |
| 65 | + { |
| 66 | + name: "CanceledStatusWithStartTransition", |
| 67 | + jobStatus: ProvisionerJobCanceled, |
| 68 | + transition: WorkspaceTransitionStart, |
| 69 | + want: "Canceled action", |
| 70 | + }, |
| 71 | + { |
| 72 | + name: "FailedStatusWithDeleteTransition", |
| 73 | + jobStatus: ProvisionerJobFailed, |
| 74 | + transition: WorkspaceTransitionDelete, |
| 75 | + want: "Failed", |
| 76 | + }, |
| 77 | + { |
| 78 | + name: "EmptyStatusWithDeleteTransition", |
| 79 | + jobStatus: "", |
| 80 | + transition: WorkspaceTransitionDelete, |
| 81 | + want: unknownStatus, |
| 82 | + }, |
| 83 | + { |
| 84 | + name: "RunningStatusWithEmptyTransition", |
| 85 | + jobStatus: ProvisionerJobRunning, |
| 86 | + transition: "", |
| 87 | + want: unknownStatus, |
| 88 | + }, |
| 89 | + { |
| 90 | + name: "SucceededStatusWithEmptyTransition", |
| 91 | + jobStatus: ProvisionerJobSucceeded, |
| 92 | + transition: "", |
| 93 | + want: unknownStatus, |
| 94 | + }, |
| 95 | + } |
| 96 | + for _, tt := range tests { |
| 97 | + tt := tt |
| 98 | + t.Run(tt.name, func(t *testing.T) { |
| 99 | + t.Parallel() |
| 100 | + if got := WorkspaceDisplayStatus(tt.jobStatus, tt.transition); got != tt.want { |
| 101 | + t.Errorf("workspaceStatus() = %v, want %v", got, tt.want) |
| 102 | + } |
| 103 | + }) |
| 104 | + } |
| 105 | +} |
0 commit comments