Skip to content

Commit

Permalink
Add "pretty" library for testing
Browse files Browse the repository at this point in the history
Adds the "pretty" library for easier debugging.

See below:

```sh
--- FAIL: TestListWithDetailedStatus (0.00s)
    service_test.go:482:  [
          {
           TypeMeta: {
            Kind: "Service",
            APIVersion: "odo.openshift.io/v1alpha1",
           },
           ObjectMeta: {
            Name: "mysql-persistent",
            GenerateName: "",
            Namespace: "",
            SelfLink: "",
            UID: "",
            ResourceVersion: "",
            Generation: 0,
            CreationTimestamp: {
             Time: 0001-01-01 00:00:00 +0000 UTC,
            },
            DeletionTimestamp: nil,
            DeletionGracePeriodSeconds: nil,
            Labels: {
            },
            Annotations: {
            },
            OwnerReferences: [
            ],
            Initializers: nil,
            Finalizers: [
            ],
            ClusterName: "",
           },
           Spec: {
            Type: "mysql-persistent",
            Plan: "default",
           },
           Status: {
        -   Status: "ProvisionedSuccessfully",
        +   Status: "ProvisionedAndLinked",
           },
```

Vs:

```
--- FAIL: TestListWithDetailedStatus (0.00s)
    service_test.go:481: expected output: []service.Service{service.Service{TypeMeta:v1.TypeMeta{Kind:"Service", APIVersion:"odo.openshift.io/v1alpha1"}, ObjectMeta:v1.ObjectMeta{Name:"mysql-persistent", GenerateName:"", Namespace:"", SelfLink:"", UID:"", ResourceVersion:"", Generation:0, CreationTimestamp:v1.Time{Time:time.Time{wall:0x0, ext:0, loc:(*time.Locati
on)(nil)}}, DeletionTimestamp:(*v1.Time)(nil), DeletionGracePeriodSeconds:(*int64)(nil), Labels:map[string]string(nil), Annotations:map[string]string(nil), OwnerReferences:[]v1.OwnerReference(nil), Initializers:(*v1.Initializers)(nil), Finalizers:[]string(nil), ClusterName:""}, Spec:service.ServiceSpec{Type:"mysql-persistent", Plan:"default"}, Status:service.Serv
iceStatus{Status:"ProvisionedSuccessfully"}}, service.Service{TypeMeta:v1.TypeMeta{Kind:"Service", APIVersion:"odo.openshift.io/v1alpha1"}, ObjectMeta:v1.ObjectMeta{Name:"postgresql-ephemeral", GenerateName:"", Namespace:"", SelfLink:"", UID:"", ResourceVersion:"", Generation:0, CreationTimestamp:v1.Time{Time:time.Time{wall:0x0, ext:0, loc:(*time.Location)(nil)}}
, DeletionTimestamp:(*v1.Time)(nil), DeletionGracePeriodSeconds:(*int64)(nil), Labels:map[string]string(nil), Annotations:map[string]string(nil), OwnerReferences:[]v1.OwnerReference(nil), Initializers:(*v1.Initializers)(nil), Finalizers:[]string(nil), ClusterName:""}, Spec:service.ServiceSpec{Type:"postgresql-ephemeral", Plan:"default"}, Status:service.ServiceSta
tus{Status:"ProvisionedSuccessfully"}}, service.Service{TypeMeta:v1.TypeMeta{Kind:"Service", APIVersion:"odo.openshift.io/v1alpha1"}, ObjectMeta:v1.ObjectMeta{Name:"mongodb", GenerateName:"", Namespace:"", SelfLink:"", UID:"", ResourceVersion:"", Generation:0, CreationTimestamp:v1.Time{Time:time.Time{wall:0x0, ext:0, loc:(*time.Location)(nil)}}, DeletionTimestamp
:(*v1.Time)(nil), DeletionGracePeriodSeconds:(*int64)(nil), Labels:map[string]string(nil), Annotations:map[string]string(nil), OwnerReferences:[]v1.OwnerReference(nil), Initializers:(*v1.Initializers)(nil), Finalizers:[]string(nil), ClusterName:""}, Spec:service.ServiceSpec{Type:"mongodb", Plan:"default"}, Status:service.ServiceStatus{Status:"ProvisionedSuccessfu
lly"}}, service.Service{TypeMeta:v1.TypeMeta{Kind:"Service", APIVersion:"odo.openshift.io/v1alpha1"}, ObjectMeta:v1.ObjectMeta{Name:"jenkins-persistent", GenerateName:"", Namespace:"", SelfLink:"", UID:"", ResourceVersion:"", Generation:0, CreationTimestamp:v1.Time{Time:time.Time{wall:0x0, ext:0, loc:(*time.Location)(nil)}}, DeletionTimestamp:(*v1.Time)(nil), Del
etionGracePeriodSeconds:(*int64)(nil), Labels:map[string]string(nil), Annotations:map[string]string(nil), OwnerReferences:[]v1.OwnerReference(nil), Initializers:(*v1.Initializers)(nil), Finalizers:[]string(nil), ClusterName:""}, Spec:service.ServiceSpec{Type:"jenkins-persistent", Plan:"default"}, Status:service.ServiceStatus{Status:"Provisioning"}}},got: []servic
e.Service{service.Service{TypeMeta:v1.TypeMeta{Kind:"Service", APIVersion:"odo.openshift.io/v1alpha1"}, ObjectMeta:v1.ObjectMeta{Name:"mysql-persistent", GenerateName:"", Namespace:"", SelfLink:"", UID:"", ResourceVersion:"", Generation:0, CreationTimestamp:v1.Time{Time:time.Time{wall:0x0, ext:0, loc:(*time.Location)(nil)}}, DeletionTimestamp:(*v1.Time)(nil), Del
etionGracePeriodSeconds:(*int64)(nil), Labels:map[string]string(nil), Annotations:map[string]string(nil), OwnerReferences:[]v1.OwnerReference(nil), Initializers:(*v1.Initializers)(nil), Finalizers:[]string(nil), ClusterName:""}, Spec:service.ServiceSpec{Type:"mysql-persistent", Plan:"default"}, Status:service.ServiceStatus{Status:"ProvisionedAndLinked"}}, service
.Service{TypeMeta:v1.TypeMeta{Kind:"Service", APIVersion:"odo.openshift.io/v1alpha1"}, ObjectMeta:v1.ObjectMeta{Name:"postgresql-ephemeral", GenerateName:"", Namespace:"", SelfLink:"", UID:"", ResourceVersion:"", Generation:0, CreationTimestamp:v1.Time{Time:time.Time{wall:0x0, ext:0, loc:(*time.Location)(nil)}}, DeletionTimestamp:(*v1.Time)(nil), DeletionGracePer
iodSeconds:(*int64)(nil), Labels:map[string]string(nil), Annotations:map[string]string(nil), OwnerReferences:[]v1.OwnerReference(nil), Initializers:(*v1.Initializers)(nil), Finalizers:[]string(nil), ClusterName:""}, Spec:service.ServiceSpec{Type:"postgresql-ephemeral", Plan:"default"}, Status:service.ServiceStatus{Status:"ProvisionedAndBound"}}, service.Service{T
ypeMeta:v1.TypeMeta{Kind:"Service", APIVersion:"odo.openshift.io/v1alpha1"}, ObjectMeta:v1.ObjectMeta{Name:"mongodb", GenerateName:"", Namespace:"", SelfLink:"", UID:"", ResourceVersion:"", Generation:0, CreationTimestamp:v1.Time{Time:time.Time{wall:0x0, ext:0, loc:(*time.Location)(nil)}}, DeletionTimestamp:(*v1.Time)(nil), DeletionGracePeriodSeconds:(*int64)(nil
), Labels:map[string]string(nil), Annotations:map[string]string(nil), OwnerReferences:[]v1.OwnerReference(nil), Initializers:(*v1.Initializers)(nil), Finalizers:[]string(nil), ClusterName:""}, Spec:service.ServiceSpec{Type:"mongodb", Plan:"default"}, Status:service.ServiceStatus{Status:"ProvisionedSuccessfully"}}, service.Service{TypeMeta:v1.TypeMeta{Kind:"Servic
e", APIVersion:"odo.openshift.io/v1alpha1"}, ObjectMeta:v1.ObjectMeta{Name:"jenkins-persistent", GenerateName:"", Namespace:"", SelfLink:"", UID:"", ResourceVersion:"", Generation:0, CreationTimestamp:v1.Time{Time:time.Time{wall:0x0, ext:0, loc:(*time.Location)(nil)}}, DeletionTimestamp:(*v1.Time)(nil), DeletionGracePeriodSeconds:(*int64)(nil), Labels:map[string]
string(nil), Annotations:map[string]string(nil), OwnerReferences:[]v1.OwnerReference(nil), Initializers:(*v1.Initializers)(nil), Finalizers:[]string(nil), ClusterName:""}, Spec:service.ServiceSpec{Type:"jenkins-persistent", Plan:"default"}, Status:service.ServiceStatus{Status:"Provisioning"}}}
```

Closes: redhat-developer#2120
  • Loading branch information
cdrage committed Sep 12, 2019
1 parent 8bc6851 commit c0254a9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
7 changes: 4 additions & 3 deletions pkg/occlient/occlient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"time"

scv1beta1 "github.com/kubernetes-incubator/service-catalog/pkg/apis/servicecatalog/v1beta1"
"github.com/kylelemons/godebug/pretty"
appsv1 "github.com/openshift/api/apps/v1"
buildv1 "github.com/openshift/api/build/v1"
dockerapi "github.com/openshift/api/image/docker10"
Expand Down Expand Up @@ -987,7 +988,7 @@ func TestUpdateBuildConfig(t *testing.T) {
}

if !reflect.DeepEqual(updatedDc.Spec, tt.updatedBuildConfig.Spec) {
t.Errorf("deployment Config Spec not matching with expected values, expected: %v, got %v", tt.updatedBuildConfig.Spec, updatedDc.Spec)
t.Errorf("deployment Config Spec not matching with expected values: %v", pretty.Compare(tt.updatedBuildConfig.Spec, updatedDc.Spec))
}
} else if err == nil && tt.wantErr {
t.Error("error was expected, but no error was returned")
Expand Down Expand Up @@ -2683,7 +2684,7 @@ func TestGetClusterServiceClass(t *testing.T) {
}

if !reflect.DeepEqual(gotServiceClass.Spec, tt.wantedServiceClass.Spec) {
t.Errorf("different service class spec value expected got: %v , expected: %v", gotServiceClass.Spec, tt.wantedServiceClass.Spec)
t.Errorf("different service class spec value expected: %v", pretty.Compare(gotServiceClass.Spec, tt.wantedServiceClass.Spec))
}
if !reflect.DeepEqual(gotServiceClass.Name, tt.wantedServiceClass.Name) {
t.Errorf("different service class name value expected got: %v , expected: %v", gotServiceClass.Name, tt.wantedServiceClass.Name)
Expand Down Expand Up @@ -2840,7 +2841,7 @@ func TestGetClusterPlansFromServiceName(t *testing.T) {
}

if !reflect.DeepEqual(wantedServicePlan.Spec, gotServicePlan.Spec) {
t.Errorf("different plan spec value expected got: %v , expected: %v", wantedServicePlan.Spec, gotServicePlan.Spec)
t.Errorf("different plan spec value expected: %v", pretty.Compare(wantedServicePlan.Spec, gotServicePlan.Spec))
}
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package service
import (
"encoding/json"
"fmt"
"github.com/kylelemons/godebug/pretty"
"github.com/onsi/gomega/matchers"
"github.com/openshift/odo/pkg/testingutil"

Expand Down Expand Up @@ -434,7 +435,7 @@ func TestListWithDetailedStatus(t *testing.T) {
svcInstanceList, _ := ListWithDetailedStatus(client, "app")

if !reflect.DeepEqual(tt.output, svcInstanceList) {
t.Errorf("expected output: %#v,got: %#v", tt.serviceList, svcInstanceList)
t.Error(fmt.Sprintf("Expected output: %v", pretty.Compare(tt.serviceList, svcInstanceList)))
}
}
}
Expand Down

0 comments on commit c0254a9

Please sign in to comment.