Skip to content

Commit

Permalink
Added backend tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kenan435 committed Sep 21, 2017
1 parent 680abb0 commit 28898bf
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/app/backend/userlinks/userlinks.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ package userlinks
import (
"encoding/json"
"log"
"net/url"
"strconv"
"strings"
"net/url"

"github.com/kubernetes/dashboard/src/app/backend/api"
metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down
31 changes: 31 additions & 0 deletions src/app/backend/userlinks/userlinks_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2017 The Kubernetes Dashboard Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package userlinks

import (
Expand All @@ -6,6 +20,8 @@ import (

"strconv"

"sort"

"github.com/kubernetes/dashboard/src/app/backend/api"
metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes/fake"
Expand Down Expand Up @@ -67,6 +83,13 @@ func TestGetUserLinksForService(t *testing.T) {

actual, _ := GetUserLinks(fakeClient, c.namespace, c.name, c.resource, c.host)

sort.Slice(actual, func(i, j int) bool {
return actual[i].Description < actual[j].Description
})
sort.Slice(c.expected, func(i, j int) bool {
return c.expected[i].Description < c.expected[j].Description
})

if !reflect.DeepEqual(actual, c.expected) {
t.Errorf("GetUserLinksForService(client,%#v, %#v) == \ngot: %#v, \nexpected %#v",
c.namespace, c.name, actual, c.expected)
Expand Down Expand Up @@ -111,6 +134,14 @@ func TestGetUserLinksForPod(t *testing.T) {
fakeClient := fake.NewSimpleClientset(c.pod)
actual, _ := GetUserLinks(fakeClient, c.namespace, c.name, c.resource, c.host)

// since order of the "actual" slice cannot be predicted we sort both slice so that the correct indices are compared
sort.Slice(actual, func(i, j int) bool {
return actual[i].Description < actual[j].Description
})
sort.Slice(c.expected, func(i, j int) bool {
return c.expected[i].Description < c.expected[j].Description
})

if !reflect.DeepEqual(actual, c.expected) {
t.Errorf("GetUserLinksForPod(client,%#v, %#v) == \ngot: %#v, \nexpected %#v",
c.namespace, c.name, actual, c.expected)
Expand Down

0 comments on commit 28898bf

Please sign in to comment.