Skip to content

Commit

Permalink
Rate limit (#2345)
Browse files Browse the repository at this point in the history
* docs: Correct name of docs file

* tests: failed on main branch

When running the tests prior to making changes 2 issues were seen

1) With a setting to enable vulnerability alerts the tests failed,
adding them to be on in these tests doesn't impact the results and
allows others in the same position to run the tests.

2) The overwrte tests did not set attributes that were being asserted,
adding the attribures allow the test to pass. Not sure how these
previously passed.

* fix: Files should not be removed on rate limiting

---------

Co-authored-by: Keegan Campbell <[email protected]>
  • Loading branch information
grahamhar and kfcampbell authored Aug 16, 2024
1 parent 7e83094 commit 0f84a2a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
10 changes: 9 additions & 1 deletion github/resource_github_repository_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package github

import (
"context"
"errors"
"log"
"net/http"
"net/url"
"strings"

Expand Down Expand Up @@ -298,7 +300,13 @@ func resourceGithubRepositoryFileRead(d *schema.ResourceData, meta interface{})
opts.Ref = branch.(string)
}

fc, _, _, _ := client.Repositories.GetContents(ctx, owner, repo, file, opts)
fc, _, _, err := client.Repositories.GetContents(ctx, owner, repo, file, opts)
if err != nil {
var errorResponse *github.ErrorResponse
if errors.As(err, &errorResponse) && errorResponse.Response.StatusCode == http.StatusTooManyRequests {
return err
}
}
if fc == nil {
log.Printf("[INFO] Removing repository path %s/%s/%s from state because it no longer exists in GitHub",
owner, repo, file)
Expand Down
23 changes: 15 additions & 8 deletions github/resource_github_repository_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ func TestAccGithubRepositoryFile(t *testing.T) {
config := fmt.Sprintf(`
resource "github_repository" "test" {
name = "tf-acc-test-%s"
auto_init = true
name = "tf-acc-test-%s"
auto_init = true
vulnerability_alerts = true
}
resource "github_repository_file" "test" {
Expand Down Expand Up @@ -92,8 +93,9 @@ func TestAccGithubRepositoryFile(t *testing.T) {

config := fmt.Sprintf(`
resource "github_repository" "test" {
name = "tf-acc-test-%s"
auto_init = true
name = "tf-acc-test-%s"
auto_init = true
vulnerability_alerts = true
}
resource "github_repository_file" "test" {
Expand All @@ -102,6 +104,9 @@ func TestAccGithubRepositoryFile(t *testing.T) {
file = "README.md"
content = "overwritten"
overwrite_on_create = false
commit_message = "Managed by Terraform"
commit_author = "Terraform User"
commit_email = "[email protected]"
}
`, randomID)
Expand Down Expand Up @@ -167,8 +172,9 @@ func TestAccGithubRepositoryFile(t *testing.T) {
config := fmt.Sprintf(`
resource "github_repository" "test" {
name = "tf-acc-test-%s"
auto_init = true
name = "tf-acc-test-%s"
auto_init = true
vulnerability_alerts = true
}
resource "github_branch" "test" {
Expand Down Expand Up @@ -251,8 +257,9 @@ func TestAccGithubRepositoryFile(t *testing.T) {

config := fmt.Sprintf(`
resource "github_repository" "test" {
name = "tf-acc-test-%s"
auto_init = true
name = "tf-acc-test-%s"
auto_init = true
vulnerability_alerts = true
}
resource "github_repository_file" "test" {
Expand Down

0 comments on commit 0f84a2a

Please sign in to comment.