Skip to content

Commit

Permalink
Fix existing unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dibyom committed Jul 1, 2019
1 parent 118662b commit 1282b56
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 11 deletions.
7 changes: 4 additions & 3 deletions pkg/reconciler/v1alpha1/pipelinerun/pipelinerun.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,6 @@ func (c *Reconciler) reconcile(ctx context.Context, pr *v1alpha1.PipelineRun) er
return c.conditionLister.Conditions(pr.Namespace).Get(name)
},
p.Spec.Tasks, providedResources,
c.Logger,
)
if err != nil {
// This Run has failed, so we need to mark it as failed and stop reconciling it
Expand Down Expand Up @@ -436,11 +435,13 @@ func updateTaskRunsStatus(pr *v1alpha1.PipelineRun, pipelineState []*resources.R
prtrs = &v1alpha1.PipelineRunTaskRunStatus{
PipelineTaskName: rprt.PipelineTask.Name,
}
} else {
}

if rprt.TaskRun != nil {
prtrs.Status = &rprt.TaskRun.Status
}

if rprt.ResolvedConditionChecks != nil {
if len(rprt.ResolvedConditionChecks) > 0 {
cStatus := make(map[string]*v1alpha1.PipelineRunConditionCheckStatus)
for _, c := range rprt.ResolvedConditionChecks {
cStatus[c.ConditionCheckName] = &v1alpha1.PipelineRunConditionCheckStatus{
Expand Down
1 change: 1 addition & 0 deletions pkg/reconciler/v1alpha1/pipelinerun/pipelinerun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func getPipelineRunController(t *testing.T, d test.Data, recorder record.EventRe
i.ClusterTask,
i.TaskRun,
i.PipelineResource,
i.Condition,
th,
),
Logs: logs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ func ResolvePipelineRun(
getCondition GetCondition,
tasks []v1alpha1.PipelineTask,
providedResources map[string]v1alpha1.PipelineResourceRef,
logger *zap.SugaredLogger,
) (PipelineRunState, error) {

state := []*ResolvedPipelineRunTask{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -898,8 +898,9 @@ func TestResolvePipelineRun(t *testing.T) {
getTaskRun := func(name string) (*v1alpha1.TaskRun, error) { return nil, nil }
getClusterTask := func(name string) (v1alpha1.TaskInterface, error) { return nil, nil }
getResource := func(name string) (*v1alpha1.PipelineResource, error) { return r, nil }
getCondition := func(name string)(*v1alpha1.Condition, error) { return nil, nil}

pipelineState, err := ResolvePipelineRun(pr, getTask, getTaskRun, getClusterTask, getResource, p.Spec.Tasks, providedResources)
pipelineState, err := ResolvePipelineRun(pr, getTask, getTaskRun, getClusterTask, getResource, getCondition, p.Spec.Tasks, providedResources)
if err != nil {
t.Fatalf("Error getting tasks for fake pipeline %s: %s", p.ObjectMeta.Name, err)
}
Expand Down Expand Up @@ -965,12 +966,13 @@ func TestResolvePipelineRun_PipelineTaskHasNoResources(t *testing.T) {
getResource := func(name string) (*v1alpha1.PipelineResource, error) {
return nil, xerrors.New("should not get called")
}
getCondition := func(name string) (*v1alpha1.Condition, error) {return nil, nil}
pr := v1alpha1.PipelineRun{
ObjectMeta: metav1.ObjectMeta{
Name: "pipelinerun",
},
}
pipelineState, err := ResolvePipelineRun(pr, getTask, getTaskRun, getClusterTask, getResource, pts, providedResources)
pipelineState, err := ResolvePipelineRun(pr, getTask, getTaskRun, getClusterTask, getResource, getCondition, pts, providedResources)
if err != nil {
t.Fatalf("Did not expect error when resolving PipelineRun without Resources: %v", err)
}
Expand Down Expand Up @@ -1012,12 +1014,15 @@ func TestResolvePipelineRun_TaskDoesntExist(t *testing.T) {
getResource := func(name string) (*v1alpha1.PipelineResource, error) {
return nil, xerrors.New("should not get called")
}
getCondition := func(name string) (*v1alpha1.Condition, error) {
return nil, nil
}
pr := v1alpha1.PipelineRun{
ObjectMeta: metav1.ObjectMeta{
Name: "pipelinerun",
},
}
_, err := ResolvePipelineRun(pr, getTask, getTaskRun, getClusterTask, getResource, pts, providedResources)
_, err := ResolvePipelineRun(pr, getTask, getTaskRun, getClusterTask, getResource, getCondition, pts, providedResources)
switch err := err.(type) {
case nil:
t.Fatalf("Expected error getting non-existent Tasks for Pipeline %s but got none", p.Name)
Expand Down Expand Up @@ -1058,6 +1063,9 @@ func TestResolvePipelineRun_ResourceBindingsDontExist(t *testing.T) {
getResource := func(name string) (*v1alpha1.PipelineResource, error) {
return nil, xerrors.New("shouldnt be called")
}
getCondition := func(name string) (*v1alpha1.Condition, error) {
return nil, nil
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand All @@ -1066,7 +1074,7 @@ func TestResolvePipelineRun_ResourceBindingsDontExist(t *testing.T) {
Name: "pipelinerun",
},
}
_, err := ResolvePipelineRun(pr, getTask, getTaskRun, getClusterTask, getResource, tt.p.Spec.Tasks, providedResources)
_, err := ResolvePipelineRun(pr, getTask, getTaskRun, getClusterTask, getResource, getCondition, tt.p.Spec.Tasks, providedResources)
if err == nil {
t.Fatalf("Expected error when bindings are in incorrect state for Pipeline %s but got none", p.Name)
}
Expand Down Expand Up @@ -1108,6 +1116,9 @@ func TestResolvePipelineRun_ResourcesDontExist(t *testing.T) {
getResource := func(name string) (*v1alpha1.PipelineResource, error) {
return nil, errors.NewNotFound(v1alpha1.Resource("pipelineresource"), name)
}
getCondition := func(name string) (*v1alpha1.Condition, error) {
return nil, nil
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand All @@ -1116,7 +1127,7 @@ func TestResolvePipelineRun_ResourcesDontExist(t *testing.T) {
Name: "pipelinerun",
},
}
_, err := ResolvePipelineRun(pr, getTask, getTaskRun, getClusterTask, getResource, tt.p.Spec.Tasks, providedResources)
_, err := ResolvePipelineRun(pr, getTask, getTaskRun, getClusterTask, getResource, getCondition, tt.p.Spec.Tasks, providedResources)
switch err := err.(type) {
case nil:
t.Fatalf("Expected error getting non-existent Resources for Pipeline %s but got none", p.Name)
Expand Down Expand Up @@ -1348,8 +1359,8 @@ func TestResolvePipelineRun_withExistingTaskRuns(t *testing.T) {
getClusterTask := func(name string) (v1alpha1.TaskInterface, error) { return nil, nil }
getTaskRun := func(name string) (*v1alpha1.TaskRun, error) { return nil, nil }
getResource := func(name string) (*v1alpha1.PipelineResource, error) { return r, nil }

pipelineState, err := ResolvePipelineRun(pr, getTask, getTaskRun, getClusterTask, getResource, p.Spec.Tasks, providedResources)
getCondition := func(name string)(*v1alpha1.Condition, error) {return nil, nil}
pipelineState, err := ResolvePipelineRun(pr, getTask, getTaskRun, getClusterTask, getResource, getCondition, p.Spec.Tasks, providedResources)
if err != nil {
t.Fatalf("Error getting tasks for fake pipeline %s: %s", p.ObjectMeta.Name, err)
}
Expand Down
8 changes: 8 additions & 0 deletions test/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type Data struct {
Tasks []*v1alpha1.Task
ClusterTasks []*v1alpha1.ClusterTask
PipelineResources []*v1alpha1.PipelineResource
Conditions []*v1alpha1.Condition
Pods []*corev1.Pod
Namespaces []*corev1.Namespace
}
Expand All @@ -65,6 +66,7 @@ type Informers struct {
Task informersv1alpha1.TaskInformer
ClusterTask informersv1alpha1.ClusterTaskInformer
PipelineResource informersv1alpha1.PipelineResourceInformer
Condition informersv1alpha1.ConditionInformer
Pod coreinformers.PodInformer
}

Expand Down Expand Up @@ -120,6 +122,7 @@ func SeedTestData(t *testing.T, d Data) (Clients, Informers) {
Task: sharedInformer.Tekton().V1alpha1().Tasks(),
ClusterTask: sharedInformer.Tekton().V1alpha1().ClusterTasks(),
PipelineResource: sharedInformer.Tekton().V1alpha1().PipelineResources(),
Condition: sharedInformer.Tekton().V1alpha1().Conditions(),
Pod: kubeInformer.Core().V1().Pods(),
}

Expand Down Expand Up @@ -153,6 +156,11 @@ func SeedTestData(t *testing.T, d Data) (Clients, Informers) {
t.Fatal(err)
}
}
for _, r := range d.Conditions {
if err := i.Condition.Informer().GetIndexer().Add(r); err != nil {
t.Fatal(err)
}
}
for _, p := range d.Pods {
if err := i.Pod.Informer().GetIndexer().Add(p); err != nil {
t.Fatal(err)
Expand Down

0 comments on commit 1282b56

Please sign in to comment.