Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

use specific error for github authorization error #493

Merged

Conversation

jcockbain
Copy link
Contributor

@jcockbain jcockbain commented Jun 10, 2020

Signed-off-by: James Cockbain [email protected]

What type of PR is this ?

  • Bug fix
  • Enhancement

What does this PR do ?

Uses a specific error key (invalid_git_credentials) for whenever the Github API returns a 401 unauthorized error, when creating a project.

Example:

cwctl --json project create 
	-u https://github.ibm.com/James-Cockbain/git-basics 
	-p ~/documents/workspace/jam 
	--personalAccessToken no-token

{"error":"invalid_git_credentials","error_description":"unexpected status code: 401 Unauthorized"}
exit status 1

Modifies main tests to check for this error code in its existing bad password and access token tests.

Which issue(s) does this PR fix ?

eclipse-archived/codewind#3100

Does this PR require a documentation change ?

No

Any special notes for your reviewer ?

Modified tests require GHE credentials to be added in https://github.com/eclipse/codewind-installer/blob/master/pkg/test/globals.go.

Copy link
Contributor

@rwalle61 rwalle61 left a comment

Choose a reason for hiding this comment

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

LGTM, I guess this test https://github.com/eclipse/codewind-installer/blob/master/pkg/project/create_test.go#L101 doesn't fail because your change is to the err op code not error.Desc. If so, it miight be good to add an assertion against the err op code

@jcockbain
Copy link
Contributor Author

@rwalle61 - that's correct. I can add that assertion 👍

@jcockbain jcockbain force-pushed the 3100-unauthorized-error-key branch from f05a0d7 to a19d4ae Compare June 10, 2020 14:00
@jcockbain jcockbain force-pushed the 3100-unauthorized-error-key branch from a19d4ae to 20bdfb5 Compare June 10, 2020 14:06
Copy link
Contributor

@rwalle61 rwalle61 left a comment

Choose a reason for hiding this comment

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

LGTM except for this last thing

@@ -98,7 +98,8 @@ func TestDownloadTemplate(t *testing.T) {
out, err := DownloadTemplate(dest, url, gitCredentials)

assert.Nil(t, out)
assert.Equal(t, "unexpected status code: 401 Unauthorized", err.Desc)
assert.Equal(t, err.Op, errOpInvalidCredentials)
Copy link
Contributor

Choose a reason for hiding this comment

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

fyi I recently realised that the 2nd arg of assert.Equal should be the expected value, not the actual value. I.e. this (and the others) should be:

Suggested change
assert.Equal(t, err.Op, errOpInvalidCredentials)
assert.Equal(t, errOpInvalidCredentials, err.Op)

which is a bit confusing given that assert.Contains(t, string(out), "invalid_git_credentials") is the correct way round

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops, yeah you are right

Copy link
Contributor

Choose a reason for hiding this comment

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

thanks for the change, yea I only just recently noticed it #489

Copy link
Contributor

@rwalle61 rwalle61 left a comment

Choose a reason for hiding this comment

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

LGTM

@codecov
Copy link

codecov bot commented Jun 10, 2020

Codecov Report

Merging #493 into master will increase coverage by 0.03%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #493      +/-   ##
==========================================
+ Coverage   19.83%   19.86%   +0.03%     
==========================================
  Files          80       80              
  Lines        7014     7017       +3     
==========================================
+ Hits         1391     1394       +3     
  Misses       5453     5453              
  Partials      170      170              
Impacted Files Coverage Δ
pkg/project/project_utils.go 0.00% <ø> (ø)
pkg/project/create.go 50.48% <100.00%> (+0.73%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c5a6baf...8146499. Read the comment docs.

@tobespc tobespc self-assigned this Jun 16, 2020
Copy link
Contributor

@tobespc tobespc left a comment

Choose a reason for hiding this comment

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

LGTM

@tobespc tobespc merged commit 400c7c6 into eclipse-archived:master Jun 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants