Skip to content

Conversation

@bflad
Copy link
Contributor

@bflad bflad commented May 30, 2020

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for pull request followers and do not help prioritize the request

Previously:

$ make lint
awsauth_test.go:127:32: Using the variable on range scope `testCase` in function literal (scopelint)
			awsTs := awsMetadataApiMock(testCase.EC2MetadataEndpoints)
			                            ^
awsauth_test.go:130:60: Using the variable on range scope `testCase` in function literal (scopelint)
			closeIam, iamSess, err := GetMockedAwsApiSession("IAM", testCase.IAMEndpoints)
			                                                        ^
awsauth_test.go:136:60: Using the variable on range scope `testCase` in function literal (scopelint)
			closeSts, stsSess, err := GetMockedAwsApiSession("STS", testCase.STSEndpoints)
			                                                        ^
awsauth_test.go:145:76: Using the variable on range scope `testCase` in function literal (scopelint)
			accountID, partition, err := GetAccountIDAndPartition(iamConn, stsConn, testCase.AuthProviderName)
			                                                                        ^
awsauth_test.go:146:21: Using the variable on range scope `testCase` in function literal (scopelint)
			if err != nil && testCase.ErrCount == 0 {
			                 ^
awsauth_test.go:149:21: Using the variable on range scope `testCase` in function literal (scopelint)
			if err == nil && testCase.ErrCount > 0 {
			                 ^
awsauth_test.go:150:53: Using the variable on range scope `testCase` in function literal (scopelint)
				t.Fatalf("Expected %d error(s), received none", testCase.ErrCount)
				                                                ^
awsauth_test.go:152:20: Using the variable on range scope `testCase` in function literal (scopelint)
			if accountID != testCase.ExpectedAccountID {
			                ^
awsauth_test.go:153:85: Using the variable on range scope `testCase` in function literal (scopelint)
				t.Fatalf("Parsed account ID doesn't match with expected (%q != %q)", accountID, testCase.ExpectedAccountID)
				                                                                                ^
awsauth_test.go:155:20: Using the variable on range scope `testCase` in function literal (scopelint)
			if partition != testCase.ExpectedPartition {
			                ^
awsauth_test.go:156:84: Using the variable on range scope `testCase` in function literal (scopelint)
				t.Fatalf("Parsed partition doesn't match with expected (%q != %q)", partition, testCase.ExpectedPartition)
				                                                                               ^
awsauth_test.go:227:60: Using the variable on range scope `testCase` in function literal (scopelint)
			closeIam, iamSess, err := GetMockedAwsApiSession("IAM", testCase.MockEndpoints)
			                                                        ^
awsauth_test.go:236:21: Using the variable on range scope `testCase` in function literal (scopelint)
			if err != nil && testCase.ErrCount == 0 {
			                 ^
awsauth_test.go:239:21: Using the variable on range scope `testCase` in function literal (scopelint)
			if err == nil && testCase.ErrCount > 0 {
			                 ^
awsauth_test.go:240:53: Using the variable on range scope `testCase` in function literal (scopelint)
				t.Fatalf("Expected %d error(s), received none", testCase.ErrCount)
				                                                ^
awsauth_test.go:242:20: Using the variable on range scope `testCase` in function literal (scopelint)
			if accountID != testCase.ExpectedAccountID {
			                ^
awsauth_test.go:243:85: Using the variable on range scope `testCase` in function literal (scopelint)
				t.Fatalf("Parsed account ID doesn't match with expected (%q != %q)", accountID, testCase.ExpectedAccountID)
				                                                                                ^
awsauth_test.go:245:20: Using the variable on range scope `testCase` in function literal (scopelint)
			if partition != testCase.ExpectedPartition {
			                ^
awsauth_test.go:246:84: Using the variable on range scope `testCase` in function literal (scopelint)
				t.Fatalf("Parsed partition doesn't match with expected (%q != %q)", partition, testCase.ExpectedPartition)
				                                                                               ^
awsauth_test.go:285:60: Using the variable on range scope `testCase` in function literal (scopelint)
			closeIam, iamSess, err := GetMockedAwsApiSession("IAM", testCase.MockEndpoints)
			                                                        ^
awsauth_test.go:294:21: Using the variable on range scope `testCase` in function literal (scopelint)
			if err != nil && testCase.ErrCount == 0 {
			                 ^
awsauth_test.go:297:21: Using the variable on range scope `testCase` in function literal (scopelint)
			if err == nil && testCase.ErrCount > 0 {
			                 ^
awsauth_test.go:298:53: Using the variable on range scope `testCase` in function literal (scopelint)
				t.Fatalf("Expected %d error(s), received none", testCase.ErrCount)
				                                                ^
awsauth_test.go:300:20: Using the variable on range scope `testCase` in function literal (scopelint)
			if accountID != testCase.ExpectedAccountID {
			                ^
awsauth_test.go:301:85: Using the variable on range scope `testCase` in function literal (scopelint)
				t.Fatalf("Parsed account ID doesn't match with expected (%q != %q)", accountID, testCase.ExpectedAccountID)
				                                                                                ^
awsauth_test.go:303:20: Using the variable on range scope `testCase` in function literal (scopelint)
			if partition != testCase.ExpectedPartition {
			                ^
awsauth_test.go:304:84: Using the variable on range scope `testCase` in function literal (scopelint)
				t.Fatalf("Parsed partition doesn't match with expected (%q != %q)", partition, testCase.ExpectedPartition)
				                                                                               ^
awsauth_test.go:343:60: Using the variable on range scope `testCase` in function literal (scopelint)
			closeSts, stsSess, err := GetMockedAwsApiSession("STS", testCase.MockEndpoints)
			                                                        ^
awsauth_test.go:352:21: Using the variable on range scope `testCase` in function literal (scopelint)
			if err != nil && testCase.ErrCount == 0 {
			                 ^
awsauth_test.go:355:21: Using the variable on range scope `testCase` in function literal (scopelint)
			if err == nil && testCase.ErrCount > 0 {
			                 ^
awsauth_test.go:356:53: Using the variable on range scope `testCase` in function literal (scopelint)
				t.Fatalf("Expected %d error(s), received none", testCase.ErrCount)
				                                                ^
awsauth_test.go:358:20: Using the variable on range scope `testCase` in function literal (scopelint)
			if accountID != testCase.ExpectedAccountID {
			                ^
awsauth_test.go:359:85: Using the variable on range scope `testCase` in function literal (scopelint)
				t.Fatalf("Parsed account ID doesn't match with expected (%q != %q)", accountID, testCase.ExpectedAccountID)
				                                                                                ^
awsauth_test.go:361:20: Using the variable on range scope `testCase` in function literal (scopelint)
			if partition != testCase.ExpectedPartition {
			                ^
awsauth_test.go:362:84: Using the variable on range scope `testCase` in function literal (scopelint)
				t.Fatalf("Parsed partition doesn't match with expected (%q != %q)", partition, testCase.ExpectedPartition)
				                                                                               ^
awsauth_test.go:403:67: Using the variable on range scope `testCase` in function literal (scopelint)
			accountID, partition, err := parseAccountIDAndPartitionFromARN(testCase.InputARN)
			                                                               ^
awsauth_test.go:404:21: Using the variable on range scope `testCase` in function literal (scopelint)
			if err != nil && testCase.ErrCount == 0 {
			                 ^
awsauth_test.go:407:21: Using the variable on range scope `testCase` in function literal (scopelint)
			if err == nil && testCase.ErrCount > 0 {
			                 ^
awsauth_test.go:408:70: Using the variable on range scope `testCase` in function literal (scopelint)
				t.Fatalf("Expected %d error(s) when parsing ARN, received none", testCase.ErrCount)
				                                                                 ^
awsauth_test.go:410:20: Using the variable on range scope `testCase` in function literal (scopelint)
			if accountID != testCase.ExpectedAccountID {
			                ^
awsauth_test.go:411:85: Using the variable on range scope `testCase` in function literal (scopelint)
				t.Fatalf("Parsed account ID doesn't match with expected (%q != %q)", accountID, testCase.ExpectedAccountID)
				                                                                                ^
awsauth_test.go:413:20: Using the variable on range scope `testCase` in function literal (scopelint)
			if partition != testCase.ExpectedPartition {
			                ^
awsauth_test.go:414:84: Using the variable on range scope `testCase` in function literal (scopelint)
				t.Fatalf("Parsed partition doesn't match with expected (%q != %q)", partition, testCase.ExpectedPartition)
				                                                                               ^
awserr_test.go:107:20: Using the variable on range scope `testCase` in function literal (scopelint)
			got := IsAWSErr(testCase.Err, testCase.Code, testCase.Message)
			                ^
awserr_test.go:109:14: Using the variable on range scope `testCase` in function literal (scopelint)
			if got != testCase.Expected {
			          ^
awserr_test.go:110:42: Using the variable on range scope `testCase` in function literal (scopelint)
				t.Errorf("got %t, expected %t", got, testCase.Expected)
				                                     ^
awserr_test.go:333:28: Using the variable on range scope `testCase` in function literal (scopelint)
			got := IsAWSErrExtended(testCase.Err, testCase.Code, testCase.Message, testCase.ExtendedMessage)
			                        ^
awserr_test.go:335:14: Using the variable on range scope `testCase` in function literal (scopelint)
			if got != testCase.Expected {
			          ^
awserr_test.go:336:42: Using the variable on range scope `testCase` in function literal (scopelint)
				t.Errorf("got %t, expected %t", got, testCase.Expected)
				                                     ^
session_test.go:34:35: Using the variable on range scope `tc` in function literal (scopelint)
			opts, err := GetSessionOptions(tc.config)
			                               ^
awsauth_test.go:735:20: `invalidAwsEnv` - `t` is unused (unparam)
func invalidAwsEnv(t *testing.T) func() {
                   ^
mock.go:22:18: mnd: Magic number: 500, in <argument> detected (gomnd)
			w.WriteHeader(500)
			              ^
mock.go:46:17: mnd: Magic number: 400, in <argument> detected (gomnd)
		w.WriteHeader(400)
		              ^
mock.go:83:17: mnd: Magic number: 400, in <argument> detected (gomnd)
		w.WriteHeader(400)
		              ^
session.go:87:21: mnd: Magic number: 9, in <condition> detected (gomnd)
		if r.RetryCount < 9 {
		                  ^
awsauth.go:241:19: mnd: Magic number: 100, in <operation> detected (gomnd)
	client.Timeout = 100 * time.Millisecond
	                 ^
make: *** [lint] Error 1

Previously:

```
$ make lint
awsauth_test.go:127:32: Using the variable on range scope `testCase` in function literal (scopelint)
			awsTs := awsMetadataApiMock(testCase.EC2MetadataEndpoints)
			                            ^
awsauth_test.go:130:60: Using the variable on range scope `testCase` in function literal (scopelint)
			closeIam, iamSess, err := GetMockedAwsApiSession("IAM", testCase.IAMEndpoints)
			                                                        ^
awsauth_test.go:136:60: Using the variable on range scope `testCase` in function literal (scopelint)
			closeSts, stsSess, err := GetMockedAwsApiSession("STS", testCase.STSEndpoints)
			                                                        ^
awsauth_test.go:145:76: Using the variable on range scope `testCase` in function literal (scopelint)
			accountID, partition, err := GetAccountIDAndPartition(iamConn, stsConn, testCase.AuthProviderName)
			                                                                        ^
awsauth_test.go:146:21: Using the variable on range scope `testCase` in function literal (scopelint)
			if err != nil && testCase.ErrCount == 0 {
			                 ^
awsauth_test.go:149:21: Using the variable on range scope `testCase` in function literal (scopelint)
			if err == nil && testCase.ErrCount > 0 {
			                 ^
awsauth_test.go:150:53: Using the variable on range scope `testCase` in function literal (scopelint)
				t.Fatalf("Expected %d error(s), received none", testCase.ErrCount)
				                                                ^
awsauth_test.go:152:20: Using the variable on range scope `testCase` in function literal (scopelint)
			if accountID != testCase.ExpectedAccountID {
			                ^
awsauth_test.go:153:85: Using the variable on range scope `testCase` in function literal (scopelint)
				t.Fatalf("Parsed account ID doesn't match with expected (%q != %q)", accountID, testCase.ExpectedAccountID)
				                                                                                ^
awsauth_test.go:155:20: Using the variable on range scope `testCase` in function literal (scopelint)
			if partition != testCase.ExpectedPartition {
			                ^
awsauth_test.go:156:84: Using the variable on range scope `testCase` in function literal (scopelint)
				t.Fatalf("Parsed partition doesn't match with expected (%q != %q)", partition, testCase.ExpectedPartition)
				                                                                               ^
awsauth_test.go:227:60: Using the variable on range scope `testCase` in function literal (scopelint)
			closeIam, iamSess, err := GetMockedAwsApiSession("IAM", testCase.MockEndpoints)
			                                                        ^
awsauth_test.go:236:21: Using the variable on range scope `testCase` in function literal (scopelint)
			if err != nil && testCase.ErrCount == 0 {
			                 ^
awsauth_test.go:239:21: Using the variable on range scope `testCase` in function literal (scopelint)
			if err == nil && testCase.ErrCount > 0 {
			                 ^
awsauth_test.go:240:53: Using the variable on range scope `testCase` in function literal (scopelint)
				t.Fatalf("Expected %d error(s), received none", testCase.ErrCount)
				                                                ^
awsauth_test.go:242:20: Using the variable on range scope `testCase` in function literal (scopelint)
			if accountID != testCase.ExpectedAccountID {
			                ^
awsauth_test.go:243:85: Using the variable on range scope `testCase` in function literal (scopelint)
				t.Fatalf("Parsed account ID doesn't match with expected (%q != %q)", accountID, testCase.ExpectedAccountID)
				                                                                                ^
awsauth_test.go:245:20: Using the variable on range scope `testCase` in function literal (scopelint)
			if partition != testCase.ExpectedPartition {
			                ^
awsauth_test.go:246:84: Using the variable on range scope `testCase` in function literal (scopelint)
				t.Fatalf("Parsed partition doesn't match with expected (%q != %q)", partition, testCase.ExpectedPartition)
				                                                                               ^
awsauth_test.go:285:60: Using the variable on range scope `testCase` in function literal (scopelint)
			closeIam, iamSess, err := GetMockedAwsApiSession("IAM", testCase.MockEndpoints)
			                                                        ^
awsauth_test.go:294:21: Using the variable on range scope `testCase` in function literal (scopelint)
			if err != nil && testCase.ErrCount == 0 {
			                 ^
awsauth_test.go:297:21: Using the variable on range scope `testCase` in function literal (scopelint)
			if err == nil && testCase.ErrCount > 0 {
			                 ^
awsauth_test.go:298:53: Using the variable on range scope `testCase` in function literal (scopelint)
				t.Fatalf("Expected %d error(s), received none", testCase.ErrCount)
				                                                ^
awsauth_test.go:300:20: Using the variable on range scope `testCase` in function literal (scopelint)
			if accountID != testCase.ExpectedAccountID {
			                ^
awsauth_test.go:301:85: Using the variable on range scope `testCase` in function literal (scopelint)
				t.Fatalf("Parsed account ID doesn't match with expected (%q != %q)", accountID, testCase.ExpectedAccountID)
				                                                                                ^
awsauth_test.go:303:20: Using the variable on range scope `testCase` in function literal (scopelint)
			if partition != testCase.ExpectedPartition {
			                ^
awsauth_test.go:304:84: Using the variable on range scope `testCase` in function literal (scopelint)
				t.Fatalf("Parsed partition doesn't match with expected (%q != %q)", partition, testCase.ExpectedPartition)
				                                                                               ^
awsauth_test.go:343:60: Using the variable on range scope `testCase` in function literal (scopelint)
			closeSts, stsSess, err := GetMockedAwsApiSession("STS", testCase.MockEndpoints)
			                                                        ^
awsauth_test.go:352:21: Using the variable on range scope `testCase` in function literal (scopelint)
			if err != nil && testCase.ErrCount == 0 {
			                 ^
awsauth_test.go:355:21: Using the variable on range scope `testCase` in function literal (scopelint)
			if err == nil && testCase.ErrCount > 0 {
			                 ^
awsauth_test.go:356:53: Using the variable on range scope `testCase` in function literal (scopelint)
				t.Fatalf("Expected %d error(s), received none", testCase.ErrCount)
				                                                ^
awsauth_test.go:358:20: Using the variable on range scope `testCase` in function literal (scopelint)
			if accountID != testCase.ExpectedAccountID {
			                ^
awsauth_test.go:359:85: Using the variable on range scope `testCase` in function literal (scopelint)
				t.Fatalf("Parsed account ID doesn't match with expected (%q != %q)", accountID, testCase.ExpectedAccountID)
				                                                                                ^
awsauth_test.go:361:20: Using the variable on range scope `testCase` in function literal (scopelint)
			if partition != testCase.ExpectedPartition {
			                ^
awsauth_test.go:362:84: Using the variable on range scope `testCase` in function literal (scopelint)
				t.Fatalf("Parsed partition doesn't match with expected (%q != %q)", partition, testCase.ExpectedPartition)
				                                                                               ^
awsauth_test.go:403:67: Using the variable on range scope `testCase` in function literal (scopelint)
			accountID, partition, err := parseAccountIDAndPartitionFromARN(testCase.InputARN)
			                                                               ^
awsauth_test.go:404:21: Using the variable on range scope `testCase` in function literal (scopelint)
			if err != nil && testCase.ErrCount == 0 {
			                 ^
awsauth_test.go:407:21: Using the variable on range scope `testCase` in function literal (scopelint)
			if err == nil && testCase.ErrCount > 0 {
			                 ^
awsauth_test.go:408:70: Using the variable on range scope `testCase` in function literal (scopelint)
				t.Fatalf("Expected %d error(s) when parsing ARN, received none", testCase.ErrCount)
				                                                                 ^
awsauth_test.go:410:20: Using the variable on range scope `testCase` in function literal (scopelint)
			if accountID != testCase.ExpectedAccountID {
			                ^
awsauth_test.go:411:85: Using the variable on range scope `testCase` in function literal (scopelint)
				t.Fatalf("Parsed account ID doesn't match with expected (%q != %q)", accountID, testCase.ExpectedAccountID)
				                                                                                ^
awsauth_test.go:413:20: Using the variable on range scope `testCase` in function literal (scopelint)
			if partition != testCase.ExpectedPartition {
			                ^
awsauth_test.go:414:84: Using the variable on range scope `testCase` in function literal (scopelint)
				t.Fatalf("Parsed partition doesn't match with expected (%q != %q)", partition, testCase.ExpectedPartition)
				                                                                               ^
awserr_test.go:107:20: Using the variable on range scope `testCase` in function literal (scopelint)
			got := IsAWSErr(testCase.Err, testCase.Code, testCase.Message)
			                ^
awserr_test.go:109:14: Using the variable on range scope `testCase` in function literal (scopelint)
			if got != testCase.Expected {
			          ^
awserr_test.go:110:42: Using the variable on range scope `testCase` in function literal (scopelint)
				t.Errorf("got %t, expected %t", got, testCase.Expected)
				                                     ^
awserr_test.go:333:28: Using the variable on range scope `testCase` in function literal (scopelint)
			got := IsAWSErrExtended(testCase.Err, testCase.Code, testCase.Message, testCase.ExtendedMessage)
			                        ^
awserr_test.go:335:14: Using the variable on range scope `testCase` in function literal (scopelint)
			if got != testCase.Expected {
			          ^
awserr_test.go:336:42: Using the variable on range scope `testCase` in function literal (scopelint)
				t.Errorf("got %t, expected %t", got, testCase.Expected)
				                                     ^
session_test.go:34:35: Using the variable on range scope `tc` in function literal (scopelint)
			opts, err := GetSessionOptions(tc.config)
			                               ^
awsauth_test.go:735:20: `invalidAwsEnv` - `t` is unused (unparam)
func invalidAwsEnv(t *testing.T) func() {
                   ^
mock.go:22:18: mnd: Magic number: 500, in <argument> detected (gomnd)
			w.WriteHeader(500)
			              ^
mock.go:46:17: mnd: Magic number: 400, in <argument> detected (gomnd)
		w.WriteHeader(400)
		              ^
mock.go:83:17: mnd: Magic number: 400, in <argument> detected (gomnd)
		w.WriteHeader(400)
		              ^
session.go:87:21: mnd: Magic number: 9, in <condition> detected (gomnd)
		if r.RetryCount < 9 {
		                  ^
awsauth.go:241:19: mnd: Magic number: 100, in <operation> detected (gomnd)
	client.Timeout = 100 * time.Millisecond
	                 ^
make: *** [lint] Error 1
```
@bflad bflad added the tests label May 30, 2020
@bflad bflad requested a review from a team May 30, 2020 19:03
Copy link
Contributor

@anGie44 anGie44 left a comment

Choose a reason for hiding this comment

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

LGTM (though can't say I'm tooo familiar with the list of added linters 😅 ) and linter/tests are passing as expected 👍

func invalidAwsEnv(t *testing.T) func() {
func invalidAwsEnv() func() {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(400)
Copy link
Contributor

Choose a reason for hiding this comment

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

just a general linter q: noticed this line wasn't caught by the linter like in mock.go, is this expected? thought maybe it was b/c it's embedded within another function or in general test cases are ignored?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks like https://github.com/tommy-muehle/go-mnd ignores test files by default. 👍 I'm not sure if there's a way to enable that.

Copy link
Contributor

Choose a reason for hiding this comment

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

ahh i see makes sense, the config object is hardcoded

@bflad bflad added this to the v0.6.0 milestone Jun 1, 2020
@bflad bflad merged commit 77840c3 into master Jun 1, 2020
@bflad bflad deleted the t-additional-linters branch June 1, 2020 18:16
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.

2 participants