-
Notifications
You must be signed in to change notification settings - Fork 763
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug Fix: GitHub Usernames are Case Insensitive #241
Changes from 15 commits
e4a5d4e
a9ba1cd
0b784bb
08b732c
a5b71f6
e4375c3
b56a29c
ff7d46d
19b5f88
a68fc4c
793befc
b76fe4f
7e8fa40
2b1b424
37fed31
34e594c
d995f54
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,29 +2,52 @@ package github | |
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"testing" | ||
"unicode" | ||
|
||
"github.com/google/go-github/v25/github" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
"github.com/hashicorp/terraform/terraform" | ||
) | ||
|
||
func TestAccGithubMembership_basic(t *testing.T) { | ||
if testCollaborator == "" { | ||
t.Skip("Skipping because length of `GITHUB_TEST_COLLABORATOR` is not set") | ||
} | ||
|
||
var membership github.Membership | ||
var otherMembership github.Membership | ||
|
||
oc := []rune(testCollaborator) | ||
if unicode.IsUpper(oc[0]) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure if its possible, but could |
||
oc[0] = unicode.ToLower(oc[0]) | ||
} else { | ||
oc[0] = unicode.ToUpper(oc[0]) | ||
} | ||
|
||
otherCase := string(oc) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckGithubMembershipDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccGithubMembershipConfig, | ||
Config: testAccGithubMembershipConfig(testCollaborator), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckGithubMembershipExists("github_membership.test_org_membership", &membership), | ||
testAccCheckGithubMembershipRoleState("github_membership.test_org_membership", &membership), | ||
), | ||
}, | ||
{ | ||
Config: testAccGithubMembershipConfig(otherCase), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckGithubMembershipExists("github_membership.test_org_membership", &otherMembership), | ||
testAccGithubMembershipTheSame(&membership, &otherMembership), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
@@ -36,7 +59,7 @@ func TestAccGithubMembership_importBasic(t *testing.T) { | |
CheckDestroy: testAccCheckGithubMembershipDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccGithubMembershipConfig, | ||
Config: testAccGithubMembershipConfig(testCollaborator), | ||
}, | ||
{ | ||
ResourceName: "github_membership.test_org_membership", | ||
|
@@ -134,9 +157,21 @@ func testAccCheckGithubMembershipRoleState(n string, membership *github.Membersh | |
} | ||
} | ||
|
||
var testAccGithubMembershipConfig string = fmt.Sprintf(` | ||
func testAccGithubMembershipConfig(username string) string { | ||
return fmt.Sprintf(` | ||
resource "github_membership" "test_org_membership" { | ||
username = "%s" | ||
role = "member" | ||
} | ||
`, testCollaborator) | ||
`, username) | ||
} | ||
|
||
func testAccGithubMembershipTheSame(orig, other *github.Membership) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
if *orig.URL != *other.URL { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should this also test to make sure at least one isn't null/empty? or should two empties be equal? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think, for the intent of the test, two empties would be equal. I can't think of a time when this would be empty here, but if they were to both be empty, I think it means the case change didn't have an effect. |
||
return errors.New("users are different") | ||
} | ||
|
||
return nil | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
think this is a copy/paste typo for the message