mirror of
https://github.com/redhat-developer/odo.git
synced 2025-10-19 03:06:19 +03:00
* Add integration test case Co-authored-by: Anand Kumar Singh <anandrkskd@gmail.com> Co-authored-by: Philippe Martin <phmartin@redhat.com> * Add ApplyOpenShift method to handler * Test openhift component with odo dev * Rename GetKubernetesComponentsToPush to GetK8sAndOcComponentsToPush and modify if to obtain both k8s and oc components Signed-off-by: Parthvi Vala <pvala@redhat.com> * Fix unit test failures with delete_test Signed-off-by: Parthvi Vala <pvala@redhat.com> * update ListClusterResourcesToDeleteFromDevfile to fetch openshift component,Add ListOpenShiftComponents Signed-off-by: anandrkskd <anandrkskd@gmail.com> * fix testcase 'should have deleted the old resource and created the new resource' and add helper function ReplaceStrings Signed-off-by: anandrkskd <anandrkskd@gmail.com> * fix debug test to check openshift component Signed-off-by: anandrkskd <anandrkskd@gmail.com> * Update GetBindingsFromDevfile to include openshift components * Update offline tests * Add openshift component to devfiles * Update tests * Fix binding tests * Fix RemoveBinding unit tests * Handle OpenShift components when removing binding * odo describe component displaysOpenShift components * Remove unused function --------- Signed-off-by: Parthvi Vala <pvala@redhat.com> Signed-off-by: anandrkskd <anandrkskd@gmail.com> Co-authored-by: Anand Kumar Singh <anandrkskd@gmail.com> Co-authored-by: Philippe Martin <phmartin@redhat.com> Co-authored-by: Parthvi Vala <pvala@redhat.com>
131 lines
4.2 KiB
Go
131 lines
4.2 KiB
Go
package binding
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/devfile/library/v2/pkg/devfile/parser"
|
|
devfileCtx "github.com/devfile/library/v2/pkg/devfile/parser/context"
|
|
"github.com/google/go-cmp/cmp"
|
|
|
|
odoTestingUtil "github.com/redhat-developer/odo/pkg/testingutil"
|
|
)
|
|
|
|
func TestBindingClient_ValidateRemoveBinding(t *testing.T) {
|
|
type args struct {
|
|
flags map[string]string
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "--name flag is passed",
|
|
args: args{flags: map[string]string{"name": "redis-my-node-app"}},
|
|
wantErr: false,
|
|
},
|
|
{
|
|
name: "--name flag is not passed",
|
|
args: args{flags: map[string]string{}},
|
|
wantErr: true,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
o := &BindingClient{}
|
|
if err := o.ValidateRemoveBinding(tt.args.flags); (err != nil) != tt.wantErr {
|
|
t.Errorf("ValidateRemoveBinding() error = %v, wantErr %v", err, tt.wantErr)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestBindingClient_RemoveBinding(t *testing.T) {
|
|
type args struct {
|
|
servicebindingName string
|
|
obj parser.DevfileObj
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want parser.DevfileObj
|
|
wantErr bool
|
|
}{
|
|
// TODO: Add test cases.
|
|
{
|
|
name: "removed the k8s binding successfully when bound as files",
|
|
args: args{
|
|
servicebindingName: "my-nodejs-app-cluster-sample-k8s", // name is hard coded from the devfile-with-service-binding-files.yaml
|
|
obj: odoTestingUtil.GetTestDevfileObjFromFile("devfile-with-service-binding-files.yaml"),
|
|
},
|
|
want: func() parser.DevfileObj {
|
|
obj := odoTestingUtil.GetTestDevfileObjFromFile("devfile-with-service-binding-files.yaml")
|
|
_ = obj.Data.DeleteComponent("my-nodejs-app-cluster-sample-k8s")
|
|
return obj
|
|
}(),
|
|
wantErr: false,
|
|
},
|
|
{
|
|
name: "removed the ocp binding successfully when bound as files",
|
|
args: args{
|
|
servicebindingName: "my-nodejs-app-cluster-sample-ocp", // name is hard coded from the devfile-with-service-binding-files.yaml
|
|
obj: odoTestingUtil.GetTestDevfileObjFromFile("devfile-with-service-binding-files.yaml"),
|
|
},
|
|
want: func() parser.DevfileObj {
|
|
obj := odoTestingUtil.GetTestDevfileObjFromFile("devfile-with-service-binding-files.yaml")
|
|
_ = obj.Data.DeleteComponent("my-nodejs-app-cluster-sample-ocp")
|
|
return obj
|
|
}(),
|
|
wantErr: false,
|
|
},
|
|
{
|
|
name: "removed the k8s binding successfully when not bound as files",
|
|
args: args{
|
|
servicebindingName: "my-nodejs-app-cluster-sample-k8s",
|
|
obj: odoTestingUtil.GetTestDevfileObjFromFile("devfile-with-service-binding-envvars.yaml"),
|
|
},
|
|
want: func() parser.DevfileObj {
|
|
obj := odoTestingUtil.GetTestDevfileObjFromFile("devfile-with-service-binding-envvars.yaml")
|
|
_ = obj.Data.DeleteComponent("my-nodejs-app-cluster-sample-k8s")
|
|
return obj
|
|
}(),
|
|
wantErr: false,
|
|
},
|
|
{
|
|
name: "removed the ocp binding successfully when not bound as files",
|
|
args: args{
|
|
servicebindingName: "my-nodejs-app-cluster-sample-ocp",
|
|
obj: odoTestingUtil.GetTestDevfileObjFromFile("devfile-with-service-binding-envvars.yaml"),
|
|
},
|
|
want: func() parser.DevfileObj {
|
|
obj := odoTestingUtil.GetTestDevfileObjFromFile("devfile-with-service-binding-envvars.yaml")
|
|
_ = obj.Data.DeleteComponent("my-nodejs-app-cluster-sample-ocp")
|
|
return obj
|
|
}(),
|
|
wantErr: false,
|
|
},
|
|
{
|
|
name: "failed to remove non-existent binding",
|
|
args: args{
|
|
servicebindingName: "something",
|
|
obj: odoTestingUtil.GetTestDevfileObjFromFile("devfile-with-service-binding-files.yaml"),
|
|
},
|
|
want: odoTestingUtil.GetTestDevfileObjFromFile("devfile-with-service-binding-files.yaml"),
|
|
wantErr: true,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
o := &BindingClient{}
|
|
got, err := o.RemoveBinding(tt.args.servicebindingName, tt.args.obj)
|
|
if (err != nil) != tt.wantErr {
|
|
t.Errorf("RemoveBinding() error = %v, wantErr %v", err, tt.wantErr)
|
|
return
|
|
}
|
|
if diff := cmp.Diff(tt.want, got, cmp.AllowUnexported(devfileCtx.DevfileCtx{})); diff != "" {
|
|
t.Errorf("BindingClient.RemoveBinding() mismatch (-want +got):\n%s", diff)
|
|
}
|
|
})
|
|
}
|
|
}
|