Skip to content

Commit

Permalink
Merge pull request #468 from Comcast/null-errorMessage
Browse files Browse the repository at this point in the history
Null error message
  • Loading branch information
joshulyne committed May 7, 2020
2 parents 76a8516 + 16ce130 commit cb4c4da
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
6 changes: 6 additions & 0 deletions cmd/kuberhealthy/kuberhealthy.go
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,12 @@ func (k *Kuberhealthy) externalCheckReportHandler(w http.ResponseWriter, r *http
}
log.Debugf("Check report after unmarshal: +%v\n", state)

// if nill error is passed turn it into a slice of string
if state.Errors == nil {
log.Debugln("Saw nil error slice come through and turned into slice")
state.Errors = []string{}
}

// ensure that if ok is set to false, then an error is provided
if !state.OK {
if len(state.Errors) == 0 {
Expand Down
2 changes: 1 addition & 1 deletion cmd/kuberhealthy/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func newExternalTestCheck(c *kubernetes.Clientset) (*external.Checker, error) {
// spec file for pods
func newTestCheckFromSpec(c *kubernetes.Clientset, spec *khcheckcrd.KuberhealthyCheck) *external.Checker {
// create a new checker and insert this pod spec
checker := external.New(c, spec) // external checker does not ever return an error so we drop it
checker := external.New(c, spec, khCheckClient, khStateClient, externalCheckReportingURL) // external checker does not ever return an error so we drop it
checker.Debug = true
return checker
}
Expand Down
10 changes: 8 additions & 2 deletions cmd/kuberhealthy/webserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ package main

import (
"bytes"
"context"
"encoding/json"
"io/ioutil"
"net/http"
Expand Down Expand Up @@ -46,6 +47,9 @@ func makeTestKuberhealthy(t *testing.T) *Kuberhealthy {

// TestWebServer tests the web server status page functionality
func TestWebServer(t *testing.T) {

ctx, _ := context.WithCancel(context.Background())

if testing.Short() {
t.Skip()
}
Expand All @@ -60,7 +64,7 @@ func TestWebServer(t *testing.T) {
kh.AddCheck(fc)

t.Log("Starting Kuberhealthy checks")
go kh.Start()
go kh.Start(ctx)
// give the checker time to make CRDs
t.Log("Waiting for checks to run")
time.Sleep(time.Second * 2)
Expand Down Expand Up @@ -99,6 +103,8 @@ func TestWebServer(t *testing.T) {
// TestWebServerNotOK tests the web server status when things are not OK
func TestWebServerNotOK(t *testing.T) {

ctx, _ := context.WithCancel(context.Background())

// create a new kuberhealthy
kh := makeTestKuberhealthy(t)

Expand All @@ -110,7 +116,7 @@ func TestWebServerNotOK(t *testing.T) {
kh.AddCheck(fc)

// run the checker for enough time to make and update CRD entries, then stop it
go kh.Start()
go kh.Start(ctx)
time.Sleep(time.Second * 5)
kh.StopChecks()

Expand Down

0 comments on commit cb4c4da

Please sign in to comment.