Skip to content

Commit 2cf2fec

Browse files
committed
refactor: extract repeated test constants to eliminate goconst violations
1 parent 0f6d608 commit 2cf2fec

9 files changed

+29
-10
lines changed

go/controller/add_security_key_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/nhost/hasura-auth/go/controller"
1414
"github.com/nhost/hasura-auth/go/controller/mock"
1515
"github.com/nhost/hasura-auth/go/sql"
16+
"github.com/nhost/hasura-auth/go/testhelpers"
1617
"go.uber.org/mock/gomock"
1718
)
1819

@@ -21,7 +22,7 @@ func TestAddSecurityKey(t *testing.T) { //nolint:maintidx
2122

2223
userID := uuid.MustParse("DB477732-48FA-4289-B694-2886A646B6EB")
2324

24-
credentialIDString := "EuKJAraRGDcmHon-EjDoqoU5Yvk" //nolint:gosec
25+
credentialIDString := testhelpers.TestCredentialID
2526

2627
var credentialID protocol.URLEncodedBase64
2728
if err := credentialID.UnmarshalJSON([]byte(credentialIDString)); err != nil {

go/controller/elevate_webauthn_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/nhost/hasura-auth/go/controller"
1414
"github.com/nhost/hasura-auth/go/controller/mock"
1515
"github.com/nhost/hasura-auth/go/sql"
16+
"github.com/nhost/hasura-auth/go/testhelpers"
1617
"go.uber.org/mock/gomock"
1718
)
1819

@@ -46,7 +47,7 @@ func TestElevateWebauthn(t *testing.T) {
4647
}
4748
}
4849

49-
credentialIDString := "EuKJAraRGDcmHon-EjDoqoU5Yvk" //nolint:gosec,goconst
50+
credentialIDString := testhelpers.TestCredentialID
5051

5152
var credentialID protocol.URLEncodedBase64
5253
if err := credentialID.UnmarshalJSON([]byte(credentialIDString)); err != nil {
@@ -79,7 +80,7 @@ func TestElevateWebauthn(t *testing.T) {
7980
"307b758d-c0b0-4ce3-894b-f8ddec753c29",
8081
),
8182
UserID: userID,
82-
CredentialID: "EuKJAraRGDcmHon-EjDoqoU5Yvk",
83+
CredentialID: testhelpers.TestCredentialID,
8384
CredentialPublicKey: []byte{
8485
165, 1, 2, 3, 38, 32, 1, 33, 88, 32, 252, 177, 134,
8586
121, 67, 213, 214, 63, 237, 6, 140, 235, 18, 28, 108,

go/controller/refresh_token_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/nhost/hasura-auth/go/controller"
1414
"github.com/nhost/hasura-auth/go/controller/mock"
1515
"github.com/nhost/hasura-auth/go/sql"
16+
"github.com/nhost/hasura-auth/go/testhelpers"
1617
"github.com/oapi-codegen/runtime/types"
1718
"go.uber.org/mock/gomock"
1819
)
@@ -55,7 +56,7 @@ func TestRefreshToken(t *testing.T) { //nolint:maintidx
5556

5657
userID := uuid.MustParse("db477732-48fa-4289-b694-2886a646b6eb")
5758
token := uuid.MustParse("1fb17604-86c7-444e-b337-09a644465f2d")
58-
hashedToken := `\x9698157153010b858587119503cbeef0cf288f11775e51cdb6bfd65e930d9310` //nolint:goconst
59+
hashedToken := testhelpers.TestHashedToken
5960
newTokenID := uuid.MustParse("1fb13604-86c7-4444-a337-09a644465f2d")
6061

6162
cases := []testRequest[api.RefreshTokenRequestObject, api.RefreshTokenResponseObject]{

go/controller/sign_in_pat_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/nhost/hasura-auth/go/controller"
1313
"github.com/nhost/hasura-auth/go/controller/mock"
1414
"github.com/nhost/hasura-auth/go/sql"
15+
"github.com/nhost/hasura-auth/go/testhelpers"
1516
"github.com/oapi-codegen/runtime/types"
1617
"go.uber.org/mock/gomock"
1718
)
@@ -23,7 +24,7 @@ func TestSignInPAT(t *testing.T) { //nolint:maintidx
2324
refreshTokenID := uuid.MustParse("c3b747ef-76a9-4c56-8091-ed3e6b8afb2c")
2425
userID := uuid.MustParse("db477732-48fa-4289-b694-2886a646b6eb")
2526
pat := uuid.MustParse("1fb17604-86c7-444e-b337-09a644465f2d")
26-
hashedPat := `\x9698157153010b858587119503cbeef0cf288f11775e51cdb6bfd65e930d9310`
27+
hashedPat := testhelpers.TestHashedToken
2728

2829
cases := []testRequest[api.SignInPATRequestObject, api.SignInPATResponseObject]{
2930
{

go/controller/sign_in_provider_callback_get_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/nhost/hasura-auth/go/controller"
1616
"github.com/nhost/hasura-auth/go/controller/mock"
1717
"github.com/nhost/hasura-auth/go/sql"
18+
"github.com/nhost/hasura-auth/go/testhelpers"
1819
"go.uber.org/mock/gomock"
1920
)
2021

@@ -1207,7 +1208,7 @@ func TestSignInProviderCallback(t *testing.T) { //nolint:maintidx
12071208
tc.expectedResponse,
12081209
cmp.FilterPath(func(p cmp.Path) bool {
12091210
if last := p.Last(); last != nil {
1210-
return last.String() == ".Location" //nolint:goconst
1211+
return last.String() == testhelpers.LocationField
12111212
}
12121213

12131214
return false

go/controller/sign_in_provider_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/nhost/hasura-auth/go/api"
88
"github.com/nhost/hasura-auth/go/controller"
99
"github.com/nhost/hasura-auth/go/controller/mock"
10+
"github.com/nhost/hasura-auth/go/testhelpers"
1011
"go.uber.org/mock/gomock"
1112
)
1213

@@ -131,7 +132,8 @@ func TestSignInProvider(t *testing.T) {
131132
tc.expectedResponse,
132133
cmp.FilterPath(func(p cmp.Path) bool {
133134
if last := p.Last(); last != nil {
134-
return last.String() == ".Location" || last.String() == ".SetCookie"
135+
return last.String() == testhelpers.LocationField ||
136+
last.String() == testhelpers.SetCookieField
135137
}
136138

137139
return false

go/controller/sign_in_webauthn_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/nhost/hasura-auth/go/controller"
1111
"github.com/nhost/hasura-auth/go/controller/mock"
1212
"github.com/nhost/hasura-auth/go/sql"
13+
"github.com/nhost/hasura-auth/go/testhelpers"
1314
"github.com/oapi-codegen/runtime/types"
1415
"go.uber.org/mock/gomock"
1516
)
@@ -19,7 +20,7 @@ func TestSignInWebauthn(t *testing.T) {
1920

2021
userID := uuid.MustParse("DB477732-48FA-4289-B694-2886A646B6EB")
2122

22-
credentialIDString := "EuKJAraRGDcmHon-EjDoqoU5Yvk" //nolint:gosec
23+
credentialIDString := testhelpers.TestCredentialID
2324

2425
var credentialID protocol.URLEncodedBase64
2526
if err := credentialID.UnmarshalJSON([]byte(credentialIDString)); err != nil {
@@ -49,7 +50,7 @@ func TestSignInWebauthn(t *testing.T) {
4950
UserID: uuid.MustParse(
5051
"53b008ee-bafb-489c-bcea-9237e0b778a7",
5152
),
52-
CredentialID: "EuKJAraRGDcmHon-EjDoqoU5Yvk",
53+
CredentialID: testhelpers.TestCredentialID,
5354
CredentialPublicKey: []byte{
5455
165,
5556
1,

go/controller/verify_ticket_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/nhost/hasura-auth/go/controller"
1313
"github.com/nhost/hasura-auth/go/controller/mock"
1414
"github.com/nhost/hasura-auth/go/sql"
15+
"github.com/nhost/hasura-auth/go/testhelpers"
1516
"go.uber.org/mock/gomock"
1617
)
1718

@@ -571,7 +572,7 @@ func TestVerifyTicket(t *testing.T) { //nolint:maintidx
571572
t.Context(), t, c.VerifyTicket, tc.request, tc.expectedResponse,
572573
cmp.FilterPath(func(p cmp.Path) bool {
573574
if last := p.Last(); last != nil {
574-
return last.String() == ".Location"
575+
return last.String() == testhelpers.LocationField
575576
}
576577

577578
return false

go/testhelpers/gocmp.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ import (
44
"github.com/google/go-cmp/cmp"
55
)
66

7+
const (
8+
// Common field names used in test comparisons.
9+
LocationField = ".Location"
10+
SetCookieField = ".SetCookie"
11+
12+
// Common test hash values used across multiple test files.
13+
TestHashedToken = `\x9698157153010b858587119503cbeef0cf288f11775e51cdb6bfd65e930d9310`
14+
TestCredentialID = "EuKJAraRGDcmHon-EjDoqoU5Yvk" //nolint:gosec
15+
)
16+
717
//nolint:ireturn
818
func FilterPathLast(last []string, opt cmp.Option) cmp.Option {
919
return cmp.FilterPath(

0 commit comments

Comments
 (0)