Skip to content

Commit

Permalink
add SidecarState to test builder
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhelfand authored and tekton-robot committed Feb 21, 2020
1 parent 255e8d8 commit bb1d197
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
30 changes: 29 additions & 1 deletion test/builder/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,12 @@ type TaskRunOutputsOp func(*v1alpha1.TaskRunOutputs)
// ResolvedTaskResourcesOp is an operation which modify a ResolvedTaskResources struct.
type ResolvedTaskResourcesOp func(*resources.ResolvedTaskResources)

// StepStateOp is an operation which modify a StepStep struct.
// StepStateOp is an operation which modifies a StepState struct.
type StepStateOp func(*v1alpha1.StepState)

// SidecarStateOp is an operation which modifies a SidecarState struct.
type SidecarStateOp func(*v1alpha1.SidecarState)

// VolumeOp is an operation which modify a Volume struct.
type VolumeOp func(*corev1.Volume)

Expand Down Expand Up @@ -349,6 +352,17 @@ func StepState(ops ...StepStateOp) TaskRunStatusOp {
}
}

// SidecarState adds a SidecarState to the TaskRunStatus.
func SidecarState(ops ...SidecarStateOp) TaskRunStatusOp {
return func(s *v1alpha1.TaskRunStatus) {
state := &v1alpha1.SidecarState{}
for _, op := range ops {
op(state)
}
s.Sidecars = append(s.Sidecars, *state)
}
}

// TaskRunStartTime sets the start time to the TaskRunStatus.
func TaskRunStartTime(startTime time.Time) TaskRunStatusOp {
return func(s *v1alpha1.TaskRunStatus) {
Expand Down Expand Up @@ -469,6 +483,20 @@ func SetStepStateWaiting(waiting corev1.ContainerStateWaiting) StepStateOp {
}
}

// SetSidecarStateName sets Name of Sidecar for SidecarState.
func SetSidecarStateName(name string) SidecarStateOp {
return func(s *v1alpha1.SidecarState) {
s.Name = name
}
}

// SetSidecarStateImageID sets ImageID of Sidecar for SidecarState.
func SetSidecarStateImageID(imageID string) SidecarStateOp {
return func(s *v1alpha1.SidecarState) {
s.ImageID = imageID
}
}

// TaskRunOwnerReference sets the OwnerReference, with specified kind and name, to the TaskRun.
func TaskRunOwnerReference(kind, name string, ops ...OwnerReferenceOp) TaskRunOp {
return func(tr *v1alpha1.TaskRun) {
Expand Down
7 changes: 6 additions & 1 deletion test/builder/task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ func TestTaskRunWithTaskRef(t *testing.T) {
tb.PodName("my-pod-name"),
tb.StatusCondition(apis.Condition{Type: apis.ConditionSucceeded}),
tb.StepState(tb.StateTerminated(127)),
tb.SidecarState(
tb.SetSidecarStateName("sidecar"),
tb.SetSidecarStateImageID("ImageID"),
),
),
)
expectedTaskRun := &v1alpha1.TaskRun{
Expand Down Expand Up @@ -281,7 +285,8 @@ func TestTaskRunWithTaskRef(t *testing.T) {
Conditions: []apis.Condition{{Type: apis.ConditionSucceeded}},
},
TaskRunStatusFields: v1alpha1.TaskRunStatusFields{
PodName: "my-pod-name",
PodName: "my-pod-name",
Sidecars: []v1alpha2.SidecarState{{Name: "sidecar", ImageID: "ImageID"}},
Steps: []v1alpha1.StepState{{ContainerState: corev1.ContainerState{
Terminated: &corev1.ContainerStateTerminated{ExitCode: 127},
}}},
Expand Down

0 comments on commit bb1d197

Please sign in to comment.