From 5ab906d2199eab686f34497609e8c1b8131cbbf9 Mon Sep 17 00:00:00 2001 From: Bobby Brennan Date: Mon, 20 May 2019 13:47:43 +0000 Subject: [PATCH] test HTTP requests to dashboard as part of CI --- .circleci/config.yml | 14 ++++++++++++++ main.go | 8 ++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index ae1f4499a..3d6ad932e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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: @@ -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: diff --git a/main.go b/main.go index 5d5c72ca3..38b99f28f 100644 --- a/main.go +++ b/main.go @@ -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) @@ -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)