Skip to content

Commit

Permalink
Added unit test for the makeURLSegments function of dynamichelper (Az…
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoyu74 authored and ellis-johnson committed Jun 3, 2022
1 parent 857b252 commit 76bf4a3
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions pkg/util/dynamichelper/dynamichelper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
kruntime "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"

"github.com/Azure/ARO-RP/pkg/util/cmp"
)
Expand Down Expand Up @@ -288,3 +289,76 @@ func TestMerge(t *testing.T) {
})
}
}

func TestMakeURLSegments(t *testing.T) {
for _, tt := range []struct {
gvr *schema.GroupVersionResource
namespace string
uname, name string
url []string
want []string
}{
{
uname: "Group is empty",
gvr: &schema.GroupVersionResource{
Group: "",
Version: "4.10",
Resource: "test-resource",
},
namespace: "openshift",
name: "test-name-1",
want: []string{"api", "4.10", "namespaces", "openshift", "test-resource", "test-name-1"},
},
{
uname: "Group is not empty",
gvr: &schema.GroupVersionResource{
Group: "test-group",
Version: "4.10",
Resource: "test-resource",
},
namespace: "openshift-apiserver",
name: "test-name-2",
want: []string{"apis", "test-group", "4.10", "namespaces", "openshift-apiserver", "test-resource", "test-name-2"},
},
{
uname: "Namespace is empty",
gvr: &schema.GroupVersionResource{
Group: "test-group",
Version: "4.10",
Resource: "test-resource",
},
namespace: "",
name: "test-name-3",
want: []string{"apis", "test-group", "4.10", "test-resource", "test-name-3"},
},
{
uname: "Namespace is not empty",
gvr: &schema.GroupVersionResource{
Group: "test-group",
Version: "4.10",
Resource: "test-resource",
},
namespace: "openshift-sdn",
name: "test-name-3",
want: []string{"apis", "test-group", "4.10", "namespaces", "openshift-sdn", "test-resource", "test-name-3"},
},
{
uname: "Name is empty",
gvr: &schema.GroupVersionResource{
Group: "test-group",
Version: "4.10",
Resource: "test-resource",
},
namespace: "openshift-ns",
name: "",
want: []string{"apis", "test-group", "4.10", "namespaces", "openshift-ns", "test-resource"},
},
} {
t.Run(tt.uname, func(t *testing.T) {
got := makeURLSegments(tt.gvr, tt.namespace, tt.name)
if !reflect.DeepEqual(got, tt.want) {
t.Error(cmp.Diff(got, tt.want))
}
})
}
}

0 comments on commit 76bf4a3

Please sign in to comment.