Skip to content

Bug Fix: GitHub Usernames are Case Insensitive - #241

Merged
megan07 merged 17 commits into
masterfrom
f-username-case
Jun 26, 2019
Merged

megan07 merged 17 commits into
masterfrom
f-username-case

Conversation

@megan07

@megan07 megan07 commented Jun 14, 2019 •

Copy link
Copy Markdown
Contributor

Addressing #196 where GitHub usernames were being treated as case-sensitive in the diff.
Before fix:

Step 1 error: After applying this step, the plan was not empty:

        DIFF:

        DESTROY/CREATE: github_team_membership.test_team_membership
          etag:     "W/\"52d84b121c000efbcf03e7e877c4fbf7\"" => "<computed>"
          id:       "3289152:Mbang-github2" => "<computed>"
          role:     "member" => "member"
          team_id:  "3289152" => "3289152"
          username: "mbang-github2" => "Mbang-github2" (forces new resource)
Step 1 error: After applying this step, the plan was not empty:

        DIFF:

        DESTROY/CREATE: github_membership.test_org_membership
          etag:     "W/\"ef0b40d063d184967e965b7d8af83466\"" => "<computed>"
          id:       "mbang-github-acc-test:mbang-github2" => "<computed>"
          role:     "member" => "member"
          username: "mbang-github2" => "Mbang-github2" (forces new resource)
    Error: Provider produced inconsistent result after apply

        When applying changes to
        github_repository_collaborator.test_repo_collaborator, provider "github"
        produced an unexpected new value for was present, but now absent.

        This is a bug in the provider, which should be reported in the provider's own
        issue tracker.

FAIL

After fix:

=== RUN   TestAccGithubTeamMembership_basic
--- PASS: TestAccGithubTeamMembership_basic (13.25s)
PASS
=== RUN   TestAccGithubMembership_basic
--- PASS: TestAccGithubMembership_basic (4.08s)
PASS
=== RUN   TestAccGithubRepositoryCollaborator_basic
--- PASS: TestAccGithubRepositoryCollaborator_basic (10.31s)
PASS

I also tested that if the user DOES update the casing in the GitHub UI, a terraform refresh will pick that up.

@ghost ghost added the size/M label Jun 14, 2019
@ghost ghost added size/L and removed size/M labels Jun 14, 2019
@megan07
megan07 requested a review from a team June 20, 2019 19:53

@nywilken nywilken left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@megan07 this looks good so far. I took a quick pass and left a couple of comments. I'll circle back later today.

`, testCollaborator)

func testAccGithubMembershipConfig_caseInsensitive() string {
otherCase := []rune(testCollaborator)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I get the intent right, you are modifying the collaborator username, by toggling the case of the first rune, to test case insensitivity functionality. Is that correct? If so what about changing the function signature to take in an input, and just pass the collaborator name with the expected case.

func testAccGithubMembershipConfig_caseInsensitive(memberName string) {
return fmt.Sprintf(`
  resource "github_membership" "test_org_membership" {
    username = "%s"
    role = "member"
  }
`, memberName)
}

This way in the acceptance test you can run two TestSteps:

Steps: []resource.TestStep{
			{
				Config: testAccGithubMembershipConfig_caseInsensitive(strings.ToUpper(testCollaborator)),
				Check: resource.ComposeTestCheckFunc(
					testAccCheckGithubMembershipExists("github_membership.test_org_membership", &membership),
				),
			},
			{
				Config: testAccGithubMembershipConfig_caseInsensitive(strings.ToLower(testCollaborator)),
				Check: resource.ComposeTestCheckFunc(
					testAccCheckGithubMembershipExists("github_membership.test_org_membership", &membership),
				),
			},
		},

@nywilken nywilken left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@megan07 I left a few comments for you, but this is otherwise good.

--- PASS: TestAccGithubMembership_basic (3.30s)
--- PASS: TestAccGithubMembership_caseInsensitive (2.84s)
--- PASS: TestAccGithubMembership_importBasic (2.79s)
--- PASS: TestAccGithubRepositoryCollaborator_basic (9.65s)
--- PASS: TestAccGithubRepositoryCollaborator_importBasic (9.17s)

@megan07
megan07 requested a review from nywilken June 24, 2019 18:52

@paultyng paultyng left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor comments, but otherwise LGTM


func TestAccGithubMembership_basic(t *testing.T) {
if testCollaborator == "" {
t.Skip("Skipping because length of `GITHUB_TEST_COLLABORATOR` is not set")

Copy link
Copy Markdown
Contributor

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


func testAccGithubMembershipTheSame(orig, other *github.Membership) resource.TestCheckFunc {
return func(s *terraform.State) error {
if *orig.URL != *other.URL {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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.

var otherMembership github.Membership

oc := []rune(testCollaborator)
if unicode.IsUpper(oc[0]) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if its possible, but could 0 ever be a number or symbol in a username?

@megan07
megan07 requested a review from paultyng June 24, 2019 21:26
@megan07
megan07 merged commit efbf3f2 into master Jun 26, 2019
@megan07
megan07 deleted the f-username-case branch June 26, 2019 15:48
kfcampbell pushed a commit to kfcampbell/terraform-provider-github that referenced this pull request Jul 26, 2022
@kjolley-zainar

Copy link
Copy Markdown

I'm still seeing this:

% tf --version
Terraform v1.6.6
on darwin_amd64

% tf plan
...
# module.github.github_repository_collaborators.myenv will be updated in-place
  ~ resource "github_repository_collaborators" "myenv" {
        id             = "myenv"
      ~ invitation_ids = {} -> (known after apply)
        # (1 unchanged attribute hidden)

      - user {
          - permission = "pull" -> null
          - username   = "foo" -> null
        }
      - user {
          - permission = "pull" -> null
          - username   = "bar" -> null
        }
      + user {
          + permission = "pull"
          + username   = "Foo"
        }
      + user {
          + permission = "pull"
          + username   = "Bar"
        }

        # (4 unchanged blocks hidden)
    }

@esacteksab

Copy link
Copy Markdown

I'm still seeing this as well. Not sure if there is a regression. An example (a bit redacted).

Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # github_team_members.drupal_fe will be updated in-place
  ~ resource "github_team_members" "drupal_fe" {
        # (2 unchanged attributes hidden)

      - members {
          - role     = "maintainer" -> null
          - username = "username" -> null
        }
      + members {
          + role     = "maintainer"
          + username = "UserName"
        }

        # (3 unchanged blocks hidden)
    }

  # github_team_members.org_admin will be updated in-place
  ~ resource "github_team_members" "org_admin" {
        # (2 unchanged attributes hidden)

      - members {
          - role     = "maintainer" -> null
          - username = "username" -> null
        }
      + members {
          + role     = "maintainer"
          + username = "UserName"
        }

        # (4 unchanged blocks hidden)
    }

  # github_team_members.org_devops will be updated in-place
  ~ resource "github_team_members" "org_devops" {
        # (2 unchanged attributes hidden)

      - members {
          - role     = "maintainer" -> null
          - username = "username" -> null
        }
      + members {
          + role     = "maintainer"
          + username = "UserName"
        }

        # (1 unchanged block hidden)
    }

  # github_team_members.org_eng will be updated in-place
  ~ resource "github_team_members" "org_eng" {
        # (2 unchanged attributes hidden)

      - members {
          - role     = "maintainer" -> null
          - username = "username" -> null
        }
      + members {
          + role     = "maintainer"
          + username = "UserName"
        }

        # (6 unchanged blocks hidden)
    }

Plan: 0 to add, 4 to change, 0 to destroy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants