-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #179 Split handleJenkinsUIRequest() into smaller methods
- Splitted handleJenkinsUIRequest() to smaller methods - Added error package, removed naked returns, decreased returned parameters - Added tests
- Loading branch information
1 parent
365d3cb
commit a652445
Showing
6 changed files
with
708 additions
and
295 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
Oops, something went wrong.