Skip to content

Commit

Permalink
Issue #179 Split handleJenkinsUIRequest() into smaller methods
Browse files Browse the repository at this point in the history
	- Splitted handleJenkinsUIRequest() to smaller methods
	- Added error package, removed naked returns, decreased returned parameters
	- Added tests
  • Loading branch information
kishansagathiya committed Apr 9, 2018
1 parent 365d3cb commit 9b2d795
Show file tree
Hide file tree
Showing 6 changed files with 708 additions and 295 deletions.
27 changes: 27 additions & 0 deletions internal/proxy/mock_idler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package proxy

type mockIdler struct {
idlerAPI string
isIdle bool
}

// IsIdle returns mockIdler.isIdle
func (i *mockIdler) IsIdle(tenant string, openShiftAPIURL string) (bool, error) {
return i.isIdle, nil
}

// UnIdle always unidles (mock)
func (i *mockIdler) UnIdle(tenant string, openShiftAPIURL string) error {
return nil
}

// Clusters returns a map which maps the OpenShift API URL to the application DNS for this cluster. An empty map together with
// an error is returned if an error occurs.
func (i *mockIdler) Clusters() (map[string]string, error) {
clusters := map[string]string{
"https://api.free-stg.openshift.com/": "1b7d.free-stg.openshiftapps.com",
"https://api.starter-us-east-2a.openshift.com/": "b542.starter-us-east-2a.openshiftapps.com",
}

return clusters, nil
}
47 changes: 47 additions & 0 deletions internal/proxy/mock_login.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package proxy

import (
"net/http"

"errors"

log "github.com/sirupsen/logrus"
)

type mockLogin struct {
isLoggedIn bool
isTokenValid bool
giveOSOToken bool
}

// loginJenkins always logs in
func (l *mockLogin) loginJenkins(pci CacheItem, osoToken string, requestLogEntry *log.Entry) (int, []*http.Cookie, error) {
c := &http.Cookie{
Name: "JSESSIONID",
Value: "Some Session ID",
}
return 200, []*http.Cookie{c}, nil
}

func (l *mockLogin) processToken(tokenData []byte, requestLogEntry *log.Entry, p *Proxy) (pci *CacheItem, osioToken string, err error) {

if !l.isTokenValid {
return nil, "", errors.New("Could not Process Token Properly")
}
pci = &CacheItem{
ClusterURL: "https://api.free-stg.openshift.com/",
NS: "someNameSpace",
Route: "1b7d.free-stg.openshiftapps.com",
Scheme: "",
}

return pci, "OSIO_TOKEN", nil
}

func (l *mockLogin) GetOSOToken(authURL string, clusterURL string, token string) (osoToken string, err error) {
if l.giveOSOToken {
return "valid OSO Token", nil
}

return "", errors.New("Could not get valid OSO Token")
}
Loading

0 comments on commit 9b2d795

Please sign in to comment.