From 174031ed3506ca146ed6c3a29bc84e92b9f1022f Mon Sep 17 00:00:00 2001 From: Matt Whelan Date: Mon, 22 Feb 2021 14:16:37 -0800 Subject: [PATCH] Fix unit tests Ideally, tests (and runtime) wouldn't depend on third-party services. Certainly, the unit tests should not fail when the third-party service is sending 429 errors --- checks/runtimeCheck.go | 7 ++++++- checks/runtimeCheck_test.go | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/checks/runtimeCheck.go b/checks/runtimeCheck.go index 0ed7b54..079c638 100644 --- a/checks/runtimeCheck.go +++ b/checks/runtimeCheck.go @@ -28,11 +28,16 @@ func latestAgentTag(r *runtimeConfig) error { return err } defer resp.Body.Close() + if resp.StatusCode >= 300 { + // The version check HTTP request failed; this doesn't tell us anything + util.Debugf("Can't query latest agent version. Request to %v returned status %v", r.agentVersionUrl, resp.StatusCode) + return nil + } body, err := ioutil.ReadAll(resp.Body) if err != nil { return err } - err = json.Unmarshal([]byte(body), &r) + err = json.Unmarshal(body, &r) if err != nil { return err } diff --git a/checks/runtimeCheck_test.go b/checks/runtimeCheck_test.go index 4ec1eca..5d2cdce 100644 --- a/checks/runtimeCheck_test.go +++ b/checks/runtimeCheck_test.go @@ -15,7 +15,12 @@ func TestRuntimeCheck(t *testing.T) { assert.NotEqual(t, dirname, "") assert.Nil(t, err) + oldPath := runtimeLookupPath; + defer func() { + runtimeLookupPath = oldPath + }() runtimeLookupPath = fmt.Sprintf("%s/%s", dirname, runtimeLookupPath) + os.MkdirAll(runtimeLookupPath+"/node", os.ModePerm) defer os.RemoveAll(dirname + "/var") r, err := checkAndReturnRuntime()