@@ -329,7 +329,8 @@ func TestSignMulti2(t *testing.T) {
329329 hmacAlgorithms := []jwa.SignatureAlgorithm {jwa .HS256 , jwa .HS384 , jwa .HS512 }
330330 var signed []byte
331331 t .Run ("Sign" , func (t * testing.T ) {
332- var options = []jws.SignOption {jws .WithJSON ()}
332+ options := make ([]jws.SignOption , 0 , 1 + len (hmacAlgorithms ))
333+ options = append (options , jws .WithJSON ())
333334 for _ , alg := range hmacAlgorithms {
334335 options = append (options , jws .WithKey (alg , sharedkey )) // (signer, sharedkey, nil, nil))
335336 }
@@ -768,7 +769,7 @@ func TestEncode(t *testing.T) {
768769 t .Run (tc .Name , func (t * testing.T ) {
769770 t .Parallel ()
770771 // Create payload with X.Y.Z
771- var payload []byte
772+ payload := make ( []byte , 0 , size + 1 + size + 1 + size )
772773 for range size {
773774 payload = append (payload , 'X' )
774775 }
@@ -1294,7 +1295,7 @@ func TestJKU(t *testing.T) {
12941295 Fetcher : func () jwk.Fetcher {
12951296 c := jwk .NewCache (context .TODO ())
12961297 return jwk .FetchFunc (func (ctx context.Context , u string , options ... jwk.FetchOption ) (jwk.Set , error ) {
1297- var cacheopts []jwk.RegisterOption
1298+ cacheopts := make ( []jwk.RegisterOption , 0 , len ( options ) + 2 )
12981299 for _ , option := range options {
12991300 cacheopts = append (cacheopts , option )
13001301 }
@@ -1343,15 +1344,15 @@ func TestJKU(t *testing.T) {
13431344 // 1st and 3rd signatures are valid, but signed using keys that are not
13441345 // present in the JWKS.
13451346 // Only the second signature uses a key found in the JWKS
1346- var keys []jwk.Key
1347+ keys := make ( []jwk.Key , 0 , 3 )
13471348 for i := range 3 {
13481349 key , err := jwxtest .GenerateRsaJwk ()
13491350 require .NoError (t , err , `jwxtest.GenerateRsaJwk should succeed` )
13501351 key .Set (jwk .KeyIDKey , fmt .Sprintf (`used-%d` , i ))
13511352 keys = append (keys , key )
13521353 }
13531354
1354- var unusedKeys []jwk.Key
1355+ unusedKeys := make ( []jwk.Key , 0 , 2 )
13551356 for i := range 2 {
13561357 key , err := jwxtest .GenerateRsaJwk ()
13571358 require .NoError (t , err , `jwxtest.GenerateRsaJwk should succeed` )
@@ -1375,7 +1376,8 @@ func TestJKU(t *testing.T) {
13751376 defer srv .Close ()
13761377
13771378 // Sign the payload using the three keys
1378- var signOptions = []jws.SignOption {jws .WithJSON ()}
1379+ signOptions := make ([]jws.SignOption , 0 , 1 + len (keys ))
1380+ signOptions = append (signOptions , jws .WithJSON ())
13791381 for _ , key := range keys {
13801382 hdr := jws .NewHeaders ()
13811383 hdr .Set (jws .JWKSetURLKey , srv .URL )
0 commit comments