github.com/leg100/ots@v0.0.7-0.20210919080622-034055ced4bd/run_test.go (about)

     1  package ots
     2  
     3  import (
     4  	"testing"
     5  
     6  	tfe "github.com/leg100/go-tfe"
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  // TestRun_UpdateStatus tests that UpdateStatus correctly updates the status of
    11  // the run's plan and apply (there is little point to testing the status of the
    12  // run itself because there is no conditional logic to this assignment).
    13  func TestRun_UpdateStatus(t *testing.T) {
    14  	tests := []struct {
    15  		name            string
    16  		fromStatus      tfe.RunStatus
    17  		toStatus        tfe.RunStatus
    18  		wantPlanStatus  tfe.PlanStatus
    19  		wantApplyStatus tfe.ApplyStatus
    20  	}{
    21  		{
    22  			name:           "plan error",
    23  			fromStatus:     tfe.RunPlanning,
    24  			toStatus:       tfe.RunErrored,
    25  			wantPlanStatus: tfe.PlanErrored,
    26  		},
    27  		{
    28  			name:           "plan canceled",
    29  			fromStatus:     tfe.RunPlanning,
    30  			toStatus:       tfe.RunCanceled,
    31  			wantPlanStatus: tfe.PlanCanceled,
    32  		},
    33  		{
    34  			name:            "apply error",
    35  			fromStatus:      tfe.RunApplying,
    36  			toStatus:        tfe.RunErrored,
    37  			wantApplyStatus: tfe.ApplyErrored,
    38  		},
    39  		{
    40  			name:            "apply canceled",
    41  			fromStatus:      tfe.RunApplying,
    42  			toStatus:        tfe.RunCanceled,
    43  			wantApplyStatus: tfe.ApplyCanceled,
    44  		},
    45  	}
    46  	for _, tt := range tests {
    47  		t.Run(tt.name, func(t *testing.T) {
    48  			r := &Run{
    49  				Status:           tt.fromStatus,
    50  				StatusTimestamps: &tfe.RunStatusTimestamps{},
    51  				Plan: &Plan{
    52  					StatusTimestamps: &tfe.PlanStatusTimestamps{},
    53  				},
    54  				Apply: &Apply{
    55  					StatusTimestamps: &tfe.ApplyStatusTimestamps{},
    56  				},
    57  			}
    58  
    59  			r.UpdateStatus(tt.toStatus)
    60  
    61  			assert.Equal(t, tt.wantPlanStatus, r.Plan.Status)
    62  			assert.Equal(t, tt.wantApplyStatus, r.Apply.Status)
    63  		})
    64  	}
    65  }