Skip to content

Commit

Permalink
Fix test (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
Md. Nure Alam Nahid authored and tamalsaha committed Jun 21, 2018
1 parent e047ee3 commit b45ab67
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 11 deletions.
6 changes: 3 additions & 3 deletions auth/providers/azure/graph/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (u *UserInfo) login() error {
var authResp = &AuthResponse{}
err = json.NewDecoder(resp.Body).Decode(authResp)
if err != nil {
return errors.Wrapf(err, "failed to decode response for request %s", &req.URL.Path)
return errors.Wrapf(err, "failed to decode response for request %s", req.URL.Path)
}

// Set the authorization headers for future requests
Expand Down Expand Up @@ -127,7 +127,7 @@ func (u *UserInfo) getGroupIDs(userPrincipal string) ([]string, error) {
var objects = ObjectList{}
err = json.NewDecoder(resp.Body).Decode(&objects)
if err != nil {
return nil, errors.Wrapf(err, "failed to decode response for request %s", &req.URL.Path)
return nil, errors.Wrapf(err, "failed to decode response for request %s", req.URL.Path)
}
return objects.Value, nil
}
Expand Down Expand Up @@ -175,7 +175,7 @@ func (u *UserInfo) getExpandedGroups(ids []string) (*GroupList, error) {
var groups = &GroupList{}
err = json.NewDecoder(resp.Body).Decode(groups)
if err != nil {
return nil, errors.Wrapf(err, "failed to decode response for request %s", &req.URL.Path)
return nil, errors.Wrapf(err, "failed to decode response for request %s", req.URL.Path)
}
return groups, nil
}
Expand Down
19 changes: 11 additions & 8 deletions auth/providers/gitlab/gitlab_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func gitlabGetGroupResp(groupSize int) gitlabGroupRespFunc {
func gitlabServerSetup(userResp string, userStatusCode int, gengroupResp gitlabGroupRespFunc) *httptest.Server {
m := pat.New()

m.Get("/user", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
m.Get("/api/v4/user", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
err := gitlabVerifyAuthorization(r)
if err != nil {
w.WriteHeader(http.StatusUnauthorized)
Expand All @@ -164,7 +164,7 @@ func gitlabServerSetup(userResp string, userStatusCode int, gengroupResp gitlabG
w.Write([]byte(userResp))
}))

m.Get("/groups", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
m.Get("/api/v4/groups", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
err := gitlabVerifyAuthorization(r)
if err != nil {
w.WriteHeader(http.StatusUnauthorized)
Expand Down Expand Up @@ -236,8 +236,9 @@ func TestGitlab(t *testing.T) {
client := gitlabClientSetup(srv.URL)

resp, err := client.Check(test.token)
assert.NotNil(t, err)
assert.Nil(t, resp)
if assert.NotNil(t, err) {
assert.Nil(t, resp)
}
})
}
}
Expand All @@ -252,10 +253,12 @@ func TestForDIfferentGroupSizes(t *testing.T) {
defer srv.Close()

client := gitlabClientSetup(srv.URL)

resp, err := client.Check(gitlabGoodToken)
assert.Nil(t, err)
assertUserInfo(t, resp, groupSize)
if assert.NotNil(t, client) {
resp, err := client.Check(gitlabGoodToken)
if assert.Nil(t, err) {
assertUserInfo(t, resp, groupSize)
}
}
})
}
}
Expand Down
21 changes: 21 additions & 0 deletions test/e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,27 @@ var _ = BeforeSuite(func() {
err = root.CreateNamespace()
Expect(err).NotTo(HaveOccurred())
By("Using test namespace " + root.Namespace())

// clean up before test starts
_, err = root.GetService("guard", root.Namespace())
if err == nil {
Expect(root.DeleteService("guard", root.Namespace())).NotTo(HaveOccurred())
}

_, err = root.GetDeployment("guard", root.Namespace())
if err == nil {
Expect(root.DeleteDeployment("guard", root.Namespace())).NotTo(HaveOccurred())
}

_, err = root.GetClusterRole("guard")
if err == nil {
Expect(root.DeleteClusterRole("guard")).NotTo(HaveOccurred())
}

_, err = root.GetClusterRoleBinding("guard")
if err == nil {
Expect(root.DeleteClusterRoleBinding("guard")).NotTo(HaveOccurred())
}
})

var _ = AfterSuite(func() {
Expand Down
13 changes: 13 additions & 0 deletions test/e2e/framework/clusterrole.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
package framework

import (
rbac "k8s.io/api/rbac/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func (f *Framework) DeleteClusterRole(name string) error {
return f.KubeClient.RbacV1().ClusterRoles().Delete(name, deleteInBackground())
}

func (f *Framework) GetClusterRole(name string) (*rbac.ClusterRole, error) {
return f.KubeClient.RbacV1().ClusterRoles().Get(name, metav1.GetOptions{})
}

func (f *Framework) DeleteClusterRoleBinding(name string) error {
return f.KubeClient.RbacV1().ClusterRoleBindings().Delete(name, deleteInBackground())
}

func (f *Framework) GetClusterRoleBinding(name string) (*rbac.ClusterRoleBinding, error) {
return f.KubeClient.RbacV1().ClusterRoleBindings().Get(name, metav1.GetOptions{})
}
9 changes: 9 additions & 0 deletions test/e2e/framework/deployment.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
package framework

import (
apps "k8s.io/api/apps/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func (f *Framework) DeleteDeployment(name, namespace string) error {
return f.KubeClient.AppsV1beta1().Deployments(namespace).Delete(name, deleteInBackground())
}

func (f *Framework) GetDeployment(name, namespace string) (*apps.Deployment, error) {
return f.KubeClient.AppsV1beta1().Deployments(namespace).Get(name, metav1.GetOptions{})
}
9 changes: 9 additions & 0 deletions test/e2e/framework/service.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
package framework

import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func (f *Framework) DeleteService(name, namespace string) error {
return f.KubeClient.CoreV1().Services(namespace).Delete(name, deleteInForeground())
}

func (f *Framework) GetService(name, namespace string) (*corev1.Service, error) {
return f.KubeClient.CoreV1().Services(namespace).Get(name, metav1.GetOptions{})
}
13 changes: 13 additions & 0 deletions test/e2e/junit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuite name="e2e Suite" tests="10" failures="0" time="571.677005453">
<testcase name="Installer test Set up guard for individual auth provider Setting up guard for appscode Set up guard for appscode should be successful" classname="e2e Suite" time="51.343773507"></testcase>
<testcase name="Installer test Set up guard for individual auth provider Setting up guard for github Set up guard for github should be successful" classname="e2e Suite" time="51.807932203"></testcase>
<testcase name="Installer test Set up guard for individual auth provider Setting up guard for github Set up guard for github should be successful, provided base url" classname="e2e Suite" time="51.303250814"></testcase>
<testcase name="Installer test Set up guard for individual auth provider Setting up guard for gitlab Set up guard for gitlab should be successful" classname="e2e Suite" time="50.925705798"></testcase>
<testcase name="Installer test Set up guard for individual auth provider Setting up guard for gitlab Set up guard for gitlab should be successful, provided base url" classname="e2e Suite" time="60.89855021"></testcase>
<testcase name="Installer test Set up guard for individual auth provider Setting up guard for azure Set up guard for azure should be successful" classname="e2e Suite" time="60.916727168"></testcase>
<testcase name="Installer test Set up guard for individual auth provider Setting up guard for LDAP Set up guard for LDAP should be successful" classname="e2e Suite" time="50.907171918"></testcase>
<testcase name="Installer test Set up guard for individual auth provider Setting up guard for token auth Set up guard for token auth should be successful" classname="e2e Suite" time="51.260738828"></testcase>
<testcase name="Installer test Set up guard for individual auth provider Setting up guard for google Set up guard for google should be successful" classname="e2e Suite" time="90.893004798"></testcase>
<testcase name="Installer test Setting up guard for all providers Set up guard for all providers should be successful" classname="e2e Suite" time="51.075806162"></testcase>
</testsuite>

0 comments on commit b45ab67

Please sign in to comment.