Skip to content
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

make go linter 1.60.3 happy #485

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci-golang-sbom.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.56.2
version: v1.60.3
skip-pkg-cache: true
skip-build-cache: true
args: --config=./.golangci.yml --verbose
Expand Down
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ linters:
- gofmt
- revive
- misspell
- gosec
presets: # groups of linters. See https://golangci-lint.run/usage/linters/
- bugs
- unused
Expand Down
1 change: 1 addition & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
ignore: |
/vendor
.git

rules:
braces: enable
Expand Down
8 changes: 4 additions & 4 deletions pkg/auth/tokenparser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,17 +362,17 @@ func (s *TestTokenParserSuite) TestTokenParser() {
}

for k, tc := range tests {
s.T().Run(k, func(t *testing.T) {
s.Run(k, func() {
// generate non-serialized token
jwt0 := tokengenerator.GenerateToken(*identity0, kid0, authsupport.WithEmailClaim(email0), authsupport.WithAudClaim(tc.aud))

// serialize
jwt0string, err := tokengenerator.SignToken(jwt0, kid0)
require.NoError(t, err)
require.NoError(s.T(), err)
// validate token
parsed, err := tokenParser.FromString(jwt0string)
require.NoError(t, err)
require.Equal(t, jwt.ClaimStrings(tc.aud), parsed.Audience)
require.NoError(s.T(), err)
require.Equal(s.T(), jwt.ClaimStrings(tc.aud), parsed.Audience)
})
}
})
Expand Down
6 changes: 3 additions & 3 deletions pkg/proxy/proxy_community_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,16 +392,16 @@ func (s *TestProxySuite) checkProxyCommunityOK(proxy *Proxy, port string) {
// given
testServer.Config.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
v := testServerInvoked.Swap(true)
require.False(s.T(), v, "expected handler to be invoked just one time")
assert.False(s.T(), v, "expected handler to be invoked just one time")

w.Header().Set("Content-Type", "application/json")
// Set the Access-Control-Allow-Origin header to make sure it's overridden by the proxy response modifier
w.Header().Set("Access-Control-Allow-Origin", "dummy")
w.WriteHeader(http.StatusOK)
_, err := w.Write([]byte(httpTestServerResponse))
require.NoError(s.T(), err)
assert.NoError(s.T(), err)
for hk, hv := range tc.ExpectedAPIServerRequestHeaders {
require.Len(s.T(), r.Header.Values(hk), len(hv))
assert.Len(s.T(), r.Header.Values(hk), len(hv))
for i := range hv {
assert.Equal(s.T(), hv[i], r.Header.Values(hk)[i], "header %s", hk)
}
Expand Down
56 changes: 28 additions & 28 deletions pkg/proxy/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,13 +425,13 @@ func (s *TestProxySuite) checkWebLogin() {
switch p := r.URL.Path; p {
case "/auth/realms/sandbox-dev/.well-known/openid-configuration":
_, err := w.Write([]byte("mock SSO configuration"))
require.NoError(s.T(), err)
assert.NoError(s.T(), err)
case "/auth/anything":
_, err := w.Write([]byte("mock auth"))
require.NoError(s.T(), err)
assert.NoError(s.T(), err)
default:
_, err := w.Write([]byte("unknown"))
require.NoError(s.T(), err)
assert.NoError(s.T(), err)
}
}))
defer testServer.Close()
Expand Down Expand Up @@ -506,7 +506,7 @@ func (s *TestProxySuite) checkProxyOK(proxy *Proxy) {
w.Header().Set("Access-Control-Allow-Origin", "dummy")
w.WriteHeader(http.StatusOK)
_, err := w.Write([]byte("my response"))
require.NoError(s.T(), err)
assert.NoError(s.T(), err)
}))
defer testServer.Close()

Expand Down Expand Up @@ -798,9 +798,9 @@ func (s *TestProxySuite) checkProxyOK(proxy *Proxy) {
w.Header().Set("Access-Control-Allow-Origin", "dummy")
w.WriteHeader(http.StatusOK)
_, err := w.Write([]byte("my response"))
require.NoError(s.T(), err)
assert.NoError(s.T(), err)
for hk, hv := range tc.ExpectedAPIServerRequestHeaders {
require.Len(s.T(), r.Header.Values(hk), len(hv))
assert.Len(s.T(), r.Header.Values(hk), len(hv))
for i := range hv {
assert.Equal(s.T(), hv[i], r.Header.Values(hk)[i])
}
Expand Down Expand Up @@ -885,7 +885,7 @@ func (s *TestProxySuite) checkProxyOK(proxy *Proxy) {
s.assertResponseBody(resp, "my response")
}
for hk, hv := range tc.ExpectedProxyResponseHeaders {
require.Len(s.T(), resp.Header.Values(hk), len(hv), fmt.Sprintf("Actual Header %s: %v", hk, resp.Header.Values(hk)))
require.Lenf(s.T(), resp.Header.Values(hk), len(hv), "Actual Header %s: %v", hk, resp.Header.Values(hk))
for i := range hv {
assert.Equal(s.T(), hv[i], resp.Header.Values(hk)[i])
}
Expand Down Expand Up @@ -1091,21 +1091,21 @@ func (s *TestProxySuite) TestGetWorkspaceContext() {
}

for k, tc := range tests {
s.T().Run(k, func(t *testing.T) {
s.Run(k, func() {
req := &http.Request{
URL: &url.URL{
Path: tc.path,
},
}
proxy, workspace, err := getWorkspaceContext(req)
if tc.expectedErr == "" {
require.NoError(t, err, fmt.Sprintf("failed for tc %s", k))
require.NoErrorf(s.T(), err, "failed for tc %s", k)
} else {
require.EqualError(t, err, tc.expectedErr, fmt.Sprintf("failed for tc %s", k))
require.EqualErrorf(s.T(), err, tc.expectedErr, "failed for tc %s", k)
}
assert.Equal(t, tc.expectedWorkspace, workspace, fmt.Sprintf("failed for tc %s", k))
assert.Equal(t, tc.expectedPath, req.URL.Path, fmt.Sprintf("failed for tc %s", k))
assert.Equal(t, tc.expectedPlugin, proxy, fmt.Sprintf("failed for tc %s", k))
assert.Equalf(s.T(), tc.expectedWorkspace, workspace, "failed for tc %s", k)
assert.Equalf(s.T(), tc.expectedPath, req.URL.Path, "failed for tc %s", k)
assert.Equalf(s.T(), tc.expectedPlugin, proxy, "failed for tc %s", k)
})
}
}
Expand Down Expand Up @@ -1173,22 +1173,22 @@ func (s *TestProxySuite) TestValidateWorkspaceRequest() {
}

for k, tc := range tests {
s.T().Run(k, func(t *testing.T) {
s.Run(k, func() {
err := validateWorkspaceRequest(tc.requestedWorkspace, tc.workspaces...)
if tc.expectedErr == "" {
require.NoError(t, err)
require.NoError(s.T(), err)
} else {
require.EqualError(t, err, tc.expectedErr)
require.EqualError(s.T(), err, tc.expectedErr)
}
})
}
}

func (s *TestProxySuite) TestGetTransport() {

s.T().Run("when not prod", func(_ *testing.T) {
s.Run("when not prod", func() {
for _, envName := range []testconfig.EnvName{testconfig.E2E, testconfig.Dev} {
s.T().Run("env "+string(envName), func(t *testing.T) {
s.Run("env "+string(envName), func() {
// given
env := s.DefaultConfig().Environment()
defer s.SetConfig(testconfig.RegistrationService().
Expand All @@ -1204,20 +1204,20 @@ func (s *TestProxySuite) TestGetTransport() {
expectedTransport.TLSClientConfig = &tls.Config{
InsecureSkipVerify: true, // nolint:gosec
}
assertTransport(t, expectedTransport, transport)
assertTransport(s.T(), expectedTransport, transport)
})
}
})

s.T().Run("for prod", func(_ *testing.T) {
s.Run("for prod", func() {
// given
env := s.DefaultConfig().Environment()
defer s.SetConfig(testconfig.RegistrationService().
Environment(env))
s.SetConfig(testconfig.RegistrationService().
Environment(string(testconfig.Prod)))

s.T().Run("upgrade header is set to 'SPDY/3.1'", func(t *testing.T) {
s.Run("upgrade header is set to 'SPDY/3.1'", func() {
// when
transport := getTransport(map[string][]string{
"Connection": {"Upgrade"},
Expand All @@ -1229,38 +1229,38 @@ func (s *TestProxySuite) TestGetTransport() {
expectedTransport.TLSClientConfig.NextProtos = []string{"http/1.1"}
expectedTransport.ForceAttemptHTTP2 = false

assertTransport(t, expectedTransport, transport)
assertTransport(s.T(), expectedTransport, transport)
})

s.T().Run("upgrade header is set to 'websocket'", func(t *testing.T) {
s.Run("upgrade header is set to 'websocket'", func() {
// when
transport := getTransport(map[string][]string{
"Connection": {"Upgrade"},
"Upgrade": {"websocket"},
})

// then
assertTransport(t, noTimeoutDefaultTransport(), transport)
assertTransport(s.T(), noTimeoutDefaultTransport(), transport)
})

s.T().Run("no upgrade header is set", func(t *testing.T) {
s.Run("no upgrade header is set", func() {
// when
transport := getTransport(map[string][]string{})

// then
assertTransport(t, noTimeoutDefaultTransport(), transport)
assertTransport(s.T(), noTimeoutDefaultTransport(), transport)
})
})

s.T().Run("default transport should be same except for DailContext", func(t *testing.T) {
s.Run("default transport should be same except for DailContext", func() {
// when
transport := http.DefaultTransport.(interface {
Clone() *http.Transport
}).Clone()
transport.DialContext = noTimeoutDialerProxy

// then
assertTransport(t, noTimeoutDefaultTransport(), transport)
assertTransport(s.T(), noTimeoutDefaultTransport(), transport)
})
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ func (s *TestServerSuite) TestServer() {
},
}

s.T().Run("CORS", func(t *testing.T) {
s.Run("CORS", func() {
go func(t *testing.T) {
err := srv.Engine().Run()
assert.NoError(t, err) // require must only be used in the goroutine running the test function (testifylint)
}(t)
}(s.T())

err := wait.PollUntilContextTimeout(context.TODO(), DefaultRetryInterval, DefaultTimeout, false, func(context.Context) (done bool, err error) {
req, err := http.NewRequest("GET", "http://localhost:8080/api/v1/health", nil)
Expand Down
90 changes: 45 additions & 45 deletions pkg/signup/service/signup_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -773,39 +773,39 @@ func (s *TestSignupServiceSuite) TestGetSignupStatusNotComplete() {
assert.Empty(s.T(), response.StartDate)
assert.Empty(s.T(), response.EndDate)

s.T().Run("with no check for UserSignup complete condition", func(t *testing.T) {
s.Run("with no check for UserSignup complete condition", func() {
// given
states.SetVerificationRequired(userSignupNotComplete, false)
mur := s.newProvisionedMUR("bill")
space := s.newSpace(mur.Name)
spacebinding := s.newSpaceBinding(mur.Name, space.Name)
toolchainStatus := s.newToolchainStatus(".apps.")

fakeClient := commontest.NewFakeClient(t, userSignupNotComplete, mur, space, spacebinding, toolchainStatus)
fakeClient := commontest.NewFakeClient(s.T(), userSignupNotComplete, mur, space, spacebinding, toolchainStatus)
svc := service.NewSignupService(namespaced.NewClient(fakeClient, commontest.HostOperatorNs))

// when
// we set checkUserSignupCompleted to false
response, err := svc.GetSignup(c, userID.String(), userSignupNotComplete.Spec.IdentityClaims.PreferredUsername, false)

// then
require.NoError(t, err)
require.NotNil(t, response)

require.Equal(t, userID.String(), response.Name)
require.Equal(t, "bill", response.Username)
require.Equal(t, "bill", response.CompliantUsername)
require.True(t, response.Status.Ready)
require.Equal(t, "mur_ready_reason", response.Status.Reason)
require.Equal(t, "mur_ready_message", response.Status.Message)
require.False(t, response.Status.VerificationRequired)
require.Equal(t, "https://console.apps.member-123.com", response.ConsoleURL)
require.Equal(t, "http://che-toolchain-che.member-123.com", response.CheDashboardURL)
require.Equal(t, "http://api.devcluster.openshift.com", response.APIEndpoint)
require.Equal(t, "member-123", response.ClusterName)
require.Equal(t, "https://proxy-url.com", response.ProxyURL)
assert.Equal(t, "bill-dev", response.DefaultUserNamespace)
assert.Equal(t, "https://rhods-dashboard-redhat-ods-applications.apps.member-123.com", response.RHODSMemberURL)
require.NoError(s.T(), err)
require.NotNil(s.T(), response)

require.Equal(s.T(), userID.String(), response.Name)
require.Equal(s.T(), "bill", response.Username)
require.Equal(s.T(), "bill", response.CompliantUsername)
require.True(s.T(), response.Status.Ready)
require.Equal(s.T(), "mur_ready_reason", response.Status.Reason)
require.Equal(s.T(), "mur_ready_message", response.Status.Message)
require.False(s.T(), response.Status.VerificationRequired)
require.Equal(s.T(), "https://console.apps.member-123.com", response.ConsoleURL)
require.Equal(s.T(), "http://che-toolchain-che.member-123.com", response.CheDashboardURL)
require.Equal(s.T(), "http://api.devcluster.openshift.com", response.APIEndpoint)
require.Equal(s.T(), "member-123", response.ClusterName)
require.Equal(s.T(), "https://proxy-url.com", response.ProxyURL)
assert.Equal(s.T(), "bill-dev", response.DefaultUserNamespace)
assert.Equal(s.T(), "https://rhods-dashboard-redhat-ods-applications.apps.member-123.com", response.RHODSMemberURL)
})
}

Expand Down Expand Up @@ -909,7 +909,7 @@ func (s *TestSignupServiceSuite) TestGetSignupStatusOK() {
// given
for _, appsSubDomain := range []string{".apps.", ".apps-"} {
s.SetupTest()
s.T().Run("for apps subdomain: "+appsSubDomain, func(t *testing.T) {
s.Run("for apps subdomain: "+appsSubDomain, func() {
s.ServiceConfiguration(true, "", 5)

us := s.newUserSignupComplete()
Expand All @@ -926,26 +926,26 @@ func (s *TestSignupServiceSuite) TestGetSignupStatusOK() {
response, err := application.SignupService().GetSignup(c, us.Name, "", true)

// then
require.NoError(t, err)
require.NotNil(t, response)

require.Equal(t, us.Name, response.Name)
require.Equal(t, "jsmith", response.Username)
require.Equal(t, "ted", response.CompliantUsername)

require.Equal(t, mur.Status.ProvisionedTime.UTC().Format(time.RFC3339), response.StartDate)
require.Equal(t, us.Status.ScheduledDeactivationTimestamp.UTC().Format(time.RFC3339), response.EndDate)
assert.True(t, response.Status.Ready)
assert.Equal(t, "mur_ready_reason", response.Status.Reason)
assert.Equal(t, "mur_ready_message", response.Status.Message)
assert.False(t, response.Status.VerificationRequired)
assert.Equal(t, fmt.Sprintf("https://console%smember-123.com", appsSubDomain), response.ConsoleURL)
assert.Equal(t, "http://che-toolchain-che.member-123.com", response.CheDashboardURL)
assert.Equal(t, "http://api.devcluster.openshift.com", response.APIEndpoint)
assert.Equal(t, "member-123", response.ClusterName)
assert.Equal(t, "https://proxy-url.com", response.ProxyURL)
assert.Equal(t, "ted-dev", response.DefaultUserNamespace)
assert.Equal(t, fmt.Sprintf("https://rhods-dashboard-redhat-ods-applications%smember-123.com", appsSubDomain), response.RHODSMemberURL)
require.NoError(s.T(), err)
require.NotNil(s.T(), response)

require.Equal(s.T(), us.Name, response.Name)
require.Equal(s.T(), "jsmith", response.Username)
require.Equal(s.T(), "ted", response.CompliantUsername)

require.Equal(s.T(), mur.Status.ProvisionedTime.UTC().Format(time.RFC3339), response.StartDate)
require.Equal(s.T(), us.Status.ScheduledDeactivationTimestamp.UTC().Format(time.RFC3339), response.EndDate)
assert.True(s.T(), response.Status.Ready)
assert.Equal(s.T(), "mur_ready_reason", response.Status.Reason)
assert.Equal(s.T(), "mur_ready_message", response.Status.Message)
assert.False(s.T(), response.Status.VerificationRequired)
assert.Equal(s.T(), fmt.Sprintf("https://console%smember-123.com", appsSubDomain), response.ConsoleURL)
assert.Equal(s.T(), "http://che-toolchain-che.member-123.com", response.CheDashboardURL)
assert.Equal(s.T(), "http://api.devcluster.openshift.com", response.APIEndpoint)
assert.Equal(s.T(), "member-123", response.ClusterName)
assert.Equal(s.T(), "https://proxy-url.com", response.ProxyURL)
assert.Equal(s.T(), "ted-dev", response.DefaultUserNamespace)
assert.Equal(s.T(), fmt.Sprintf("https://rhods-dashboard-redhat-ods-applications%smember-123.com", appsSubDomain), response.RHODSMemberURL)
})
}
}
Expand Down Expand Up @@ -1151,7 +1151,7 @@ func (s *TestSignupServiceSuite) TestGetSignupReadyConditionStatus() {
}

for tcName, tc := range tests {
s.T().Run(tcName, func(t *testing.T) {
s.Run(tcName, func() {

// given
mur.Status = toolchainv1alpha1.MasterUserRecordStatus{
Expand All @@ -1165,10 +1165,10 @@ func (s *TestSignupServiceSuite) TestGetSignupReadyConditionStatus() {
response, err := application.SignupService().GetSignup(c, us.Name, "", true)

// then
require.NoError(t, err)
require.Equal(t, tc.expectedConditionReady, response.Status.Ready)
require.Equal(t, tc.condition.Reason, response.Status.Reason)
require.Equal(t, tc.condition.Message, response.Status.Message)
require.NoError(s.T(), err)
require.Equal(s.T(), tc.expectedConditionReady, response.Status.Ready)
require.Equal(s.T(), tc.condition.Reason, response.Status.Reason)
require.Equal(s.T(), tc.condition.Message, response.Status.Message)
})
}
}
Expand Down
Loading
Loading