code.gitea.io/gitea@v1.19.3/modules/actions/task_state_test.go (about) 1 // Copyright 2022 The Gitea Authors. All rights reserved. 2 // SPDX-License-Identifier: MIT 3 4 package actions 5 6 import ( 7 "testing" 8 9 actions_model "code.gitea.io/gitea/models/actions" 10 11 "github.com/stretchr/testify/assert" 12 ) 13 14 func TestFullSteps(t *testing.T) { 15 tests := []struct { 16 name string 17 task *actions_model.ActionTask 18 want []*actions_model.ActionTaskStep 19 }{ 20 { 21 name: "regular", 22 task: &actions_model.ActionTask{ 23 Steps: []*actions_model.ActionTaskStep{ 24 {Status: actions_model.StatusSuccess, LogIndex: 10, LogLength: 80, Started: 10010, Stopped: 10090}, 25 }, 26 Status: actions_model.StatusSuccess, 27 Started: 10000, 28 Stopped: 10100, 29 LogLength: 100, 30 }, 31 want: []*actions_model.ActionTaskStep{ 32 {Name: preStepName, Status: actions_model.StatusSuccess, LogIndex: 0, LogLength: 10, Started: 10000, Stopped: 10010}, 33 {Status: actions_model.StatusSuccess, LogIndex: 10, LogLength: 80, Started: 10010, Stopped: 10090}, 34 {Name: postStepName, Status: actions_model.StatusSuccess, LogIndex: 90, LogLength: 10, Started: 10090, Stopped: 10100}, 35 }, 36 }, 37 { 38 name: "failed step", 39 task: &actions_model.ActionTask{ 40 Steps: []*actions_model.ActionTaskStep{ 41 {Status: actions_model.StatusSuccess, LogIndex: 10, LogLength: 20, Started: 10010, Stopped: 10020}, 42 {Status: actions_model.StatusFailure, LogIndex: 30, LogLength: 60, Started: 10020, Stopped: 10090}, 43 {Status: actions_model.StatusCancelled, LogIndex: 0, LogLength: 0, Started: 0, Stopped: 0}, 44 }, 45 Status: actions_model.StatusFailure, 46 Started: 10000, 47 Stopped: 10100, 48 LogLength: 100, 49 }, 50 want: []*actions_model.ActionTaskStep{ 51 {Name: preStepName, Status: actions_model.StatusSuccess, LogIndex: 0, LogLength: 10, Started: 10000, Stopped: 10010}, 52 {Status: actions_model.StatusSuccess, LogIndex: 10, LogLength: 20, Started: 10010, Stopped: 10020}, 53 {Status: actions_model.StatusFailure, LogIndex: 30, LogLength: 60, Started: 10020, Stopped: 10090}, 54 {Status: actions_model.StatusCancelled, LogIndex: 0, LogLength: 0, Started: 0, Stopped: 0}, 55 {Name: postStepName, Status: actions_model.StatusFailure, LogIndex: 90, LogLength: 10, Started: 10090, Stopped: 10100}, 56 }, 57 }, 58 { 59 name: "first step is running", 60 task: &actions_model.ActionTask{ 61 Steps: []*actions_model.ActionTaskStep{ 62 {Status: actions_model.StatusRunning, LogIndex: 10, LogLength: 80, Started: 10010, Stopped: 0}, 63 }, 64 Status: actions_model.StatusRunning, 65 Started: 10000, 66 Stopped: 10100, 67 LogLength: 100, 68 }, 69 want: []*actions_model.ActionTaskStep{ 70 {Name: preStepName, Status: actions_model.StatusSuccess, LogIndex: 0, LogLength: 10, Started: 10000, Stopped: 10010}, 71 {Status: actions_model.StatusRunning, LogIndex: 10, LogLength: 80, Started: 10010, Stopped: 0}, 72 {Name: postStepName, Status: actions_model.StatusWaiting, LogIndex: 0, LogLength: 0, Started: 0, Stopped: 0}, 73 }, 74 }, 75 { 76 name: "first step has canceled", 77 task: &actions_model.ActionTask{ 78 Steps: []*actions_model.ActionTaskStep{ 79 {Status: actions_model.StatusCancelled, LogIndex: 0, LogLength: 0, Started: 0, Stopped: 0}, 80 }, 81 Status: actions_model.StatusFailure, 82 Started: 10000, 83 Stopped: 10100, 84 LogLength: 100, 85 }, 86 want: []*actions_model.ActionTaskStep{ 87 {Name: preStepName, Status: actions_model.StatusFailure, LogIndex: 0, LogLength: 100, Started: 10000, Stopped: 10100}, 88 {Status: actions_model.StatusCancelled, LogIndex: 0, LogLength: 0, Started: 0, Stopped: 0}, 89 {Name: postStepName, Status: actions_model.StatusFailure, LogIndex: 100, LogLength: 0, Started: 10100, Stopped: 10100}, 90 }, 91 }, 92 { 93 name: "empty steps", 94 task: &actions_model.ActionTask{ 95 Steps: []*actions_model.ActionTaskStep{}, 96 Status: actions_model.StatusSuccess, 97 Started: 10000, 98 Stopped: 10100, 99 LogLength: 100, 100 }, 101 want: []*actions_model.ActionTaskStep{ 102 {Name: preStepName, Status: actions_model.StatusSuccess, LogIndex: 0, LogLength: 100, Started: 10000, Stopped: 10100}, 103 {Name: postStepName, Status: actions_model.StatusSuccess, LogIndex: 100, LogLength: 0, Started: 10100, Stopped: 10100}, 104 }, 105 }, 106 } 107 for _, tt := range tests { 108 t.Run(tt.name, func(t *testing.T) { 109 assert.Equalf(t, tt.want, FullSteps(tt.task), "FullSteps(%v)", tt.task) 110 }) 111 } 112 }