Skip to content

Commit b73d2b5

Browse files
chore(lwupdater): Make test that makes an API call more robust (#1095)
This does two things to make the test less likely to fail: - Moves it to integration tests so it isn't run locally where users might hit rate limits by running it repeatedly. - Uses the `GITHUB_TOKEN` environment variable if present (which it is in CI) to authenticate the request and get higher rate limits.
1 parent 8beaf31 commit b73d2b5

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
// limitations under the License.
1717
//
1818

19-
package lwupdater_test
19+
package integration_test
2020

2121
import (
2222
"io/ioutil"

lwupdater/updater.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ func LoadCache(path string) (*Version, error) {
107107
// getGitRelease uses the git API to fetch the release information of a project.
108108
// This function could hit request rate limits wich are roughly 60 every 30m, to
109109
// check your current rate limits run: curl https://api.github.com/rate_limit
110+
// If the GITHUB_TOKEN environment variable is set, then this function will use
111+
// it to authenticate the API request, which grants higher rate limits.
110112
func getGitRelease(project, version string) (*gitReleaseResponse, error) {
111113
if project == "" {
112114
return nil, errors.New("specify a valid project")
@@ -140,6 +142,11 @@ func getGitRelease(project, version string) (*gitReleaseResponse, error) {
140142
// https://developer.github.com/v3/#user-agent-required
141143
req.Header.Set("User-Agent", "lacework-updater")
142144

145+
token := os.Getenv("GITHUB_TOKEN")
146+
if len(token) > 0 {
147+
req.Header.Set("Authorization", "Bearer "+token)
148+
}
149+
143150
resp, err := c.Do(req)
144151
if err != nil {
145152
return nil, err

0 commit comments

Comments
 (0)