Skip to content

Commit

Permalink
test HTTP requests to dashboard as part of CI
Browse files Browse the repository at this point in the history
  • Loading branch information
rbren committed May 20, 2019
1 parent 75b235e commit 5ab906d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
14 changes: 14 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ references:
go test ./pkg/... -coverprofile=coverage.txt -covermode=count
bash <(curl -s https://codecov.io/bash)
test_dashboard: &test_dashboard
run:
name: Test Dashboard
command: |
go run main.go --dashboard --dashboard-port 3000 --audit-path ./deploy/dashboard.yaml &
sleep 5
curl -f http://localhost:3000 > /dev/null
curl -f http://localhost:3000/health > /dev/null
curl -f http://localhost:3000/favicon.ico > /dev/null
curl -f http://localhost:3000/static/css/min.css > /dev/null
curl -f http://localhost:3000/results.json > /dev/null
curl -f http://localhost:3000/details/security > /dev/null
jobs:
build:
docker:
Expand All @@ -58,6 +71,7 @@ jobs:
- run: go list ./... | grep -v vendor | xargs golint -set_exit_status
- run: go list ./... | grep -v vendor | xargs go vet
- *update_coverage
- *test_dashboard

test-deploy:
docker:
Expand Down
8 changes: 4 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,19 @@ func main() {
if *webhook {
startWebhookServer(c, *disableWebhookConfigInstaller, *webhookPort)
} else if *dashboard {
startDashboardServer(c, *dashboardPort)
startDashboardServer(c, *auditPath, *dashboardPort)
} else if *audit {
runAudit(c, *auditPath, *auditOutputFile, *auditOutputURL)
}
}

func startDashboardServer(c conf.Configuration, port int) {
func startDashboardServer(c conf.Configuration, auditPath string, port int) {
router := mux.NewRouter()
router.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("OK"))
})
router.HandleFunc("/results.json", func(w http.ResponseWriter, r *http.Request) {
k, err := kube.CreateResourceProvider("")
k, err := kube.CreateResourceProvider(auditPath)
if err != nil {
logrus.Errorf("Error fetching Kubernetes resources %v", err)
http.Error(w, "Error fetching Kubernetes resources", http.StatusInternalServerError)
Expand All @@ -124,7 +124,7 @@ func startDashboardServer(c conf.Configuration, port int) {
http.NotFound(w, r)
return
}
k, err := kube.CreateResourceProvider("")
k, err := kube.CreateResourceProvider(auditPath)
if err != nil {
logrus.Errorf("Error fetching Kubernetes resources %v", err)
http.Error(w, "Error fetching Kubernetes resources", http.StatusInternalServerError)
Expand Down

0 comments on commit 5ab906d

Please sign in to comment.