Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Matt Whelan committed Feb 22, 2021
1 parent d243e52 commit 174031e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 6 additions & 1 deletion checks/runtimeCheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
5 changes: 5 additions & 0 deletions checks/runtimeCheck_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 174031e

Please sign in to comment.