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