Skip to content

Commit

Permalink
Use rsa.PrivateKey equal instead of testify's Equal
Browse files Browse the repository at this point in the history
  • Loading branch information
lestrrat committed Apr 17, 2024
1 parent 4399ace commit 55f9ab4
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions internal/keyconv/keyconv_test.go
Expand Up @@ -3,13 +3,15 @@ package keyconv_test
import (
"crypto/ecdsa"
"crypto/rsa"
"fmt"
"testing"

"github.com/lestrrat-go/jwx/internal/jwxtest"
"github.com/lestrrat-go/jwx/internal/keyconv"
"github.com/lestrrat-go/jwx/jwa"
"github.com/lestrrat-go/jwx/jwk"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestKeyconv(t *testing.T) {
Expand All @@ -23,16 +25,17 @@ func TestKeyconv(t *testing.T) {
testcases := []struct {
Src interface{}
Error bool
Name string
}{
{Src: key},
{Src: *key},
{Src: jwkKey},
{Src: struct{}{}, Error: true},
{Src: key, Name: "From rsa.PrivateKey"},
{Src: *key, Name: "From pointer to rsa.PrivateKey"},
{Src: jwkKey, Name: "From JWK"},
{Src: struct{}{}, Name: "From invalid value", Error: true},
}

for _, tc := range testcases {
tc := tc
t.Run("Assign to rsa.PrivateKey", func(t *testing.T) {
t.Run(fmt.Sprintf("Assign to rsa.PrivateKey (%s)", tc.Name), func(t *testing.T) {
var dst rsa.PrivateKey
var checker func(assert.TestingT, error, ...interface{}) bool
if tc.Error {
Expand All @@ -45,9 +48,7 @@ func TestKeyconv(t *testing.T) {
return
}
if !tc.Error {
if !assert.Equal(t, key, &dst, `keyconv.RSAPrivateKey should produce same value`) {
return
}
require.True(t, key.Equal(&dst), `keyconv.RSAPrivateKey should produce same value`)
}
})
t.Run("Assign to *rsa.PrivateKey", func(t *testing.T) {
Expand All @@ -63,9 +64,7 @@ func TestKeyconv(t *testing.T) {
return
}
if !tc.Error {
if !assert.Equal(t, key, dst, `keyconv.RSAPrivateKey should produce same value`) {
return
}
require.True(t, key.Equal(dst), `keyconv.RSAPrivateKey should produce same value`)
}
})
}
Expand Down

0 comments on commit 55f9ab4

Please sign in to comment.