Skip to content

Commit

Permalink
Move everything from testify/assert to require
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew Sykes <sykesmat@us.ibm.com>
  • Loading branch information
sykesm authored and Brett Logan committed Jul 10, 2020
1 parent 5e0624d commit 694bbca
Show file tree
Hide file tree
Showing 389 changed files with 9,142 additions and 9,179 deletions.
60 changes: 30 additions & 30 deletions bccsp/bccsp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"strings"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestAESOpts(t *testing.T) {
Expand All @@ -32,18 +32,18 @@ func TestAESOpts(t *testing.T) {
&AES256KeyGenOpts{ephemeral},
} {
expectedAlgorithm := reflect.TypeOf(opts).String()[7:13]
assert.Equal(t, expectedAlgorithm, opts.Algorithm())
assert.Equal(t, ephemeral, opts.Ephemeral())
require.Equal(t, expectedAlgorithm, opts.Algorithm())
require.Equal(t, ephemeral, opts.Ephemeral())
}
}
test(true)
test(false)

opts := &AESKeyGenOpts{true}
assert.Equal(t, "AES", opts.Algorithm())
assert.True(t, opts.Ephemeral())
require.Equal(t, "AES", opts.Algorithm())
require.True(t, opts.Ephemeral())
opts.Temporary = false
assert.False(t, opts.Ephemeral())
require.False(t, opts.Ephemeral())
}

func TestECDSAOpts(t *testing.T) {
Expand All @@ -53,8 +53,8 @@ func TestECDSAOpts(t *testing.T) {
&ECDSAP384KeyGenOpts{ephemeral},
} {
expectedAlgorithm := reflect.TypeOf(opts).String()[7:16]
assert.Equal(t, expectedAlgorithm, opts.Algorithm())
assert.Equal(t, ephemeral, opts.Ephemeral())
require.Equal(t, expectedAlgorithm, opts.Algorithm())
require.Equal(t, ephemeral, opts.Ephemeral())
}
}
test(true)
Expand All @@ -67,51 +67,51 @@ func TestECDSAOpts(t *testing.T) {
&ECDSAPrivateKeyImportOpts{ephemeral},
&ECDSAGoPublicKeyImportOpts{ephemeral},
} {
assert.Equal(t, "ECDSA", opts.Algorithm())
assert.Equal(t, ephemeral, opts.Ephemeral())
require.Equal(t, "ECDSA", opts.Algorithm())
require.Equal(t, ephemeral, opts.Ephemeral())
}
}
test(true)
test(false)

opts := &ECDSAReRandKeyOpts{Temporary: true}
assert.True(t, opts.Ephemeral())
require.True(t, opts.Ephemeral())
opts.Temporary = false
assert.False(t, opts.Ephemeral())
assert.Equal(t, "ECDSA_RERAND", opts.Algorithm())
assert.Empty(t, opts.ExpansionValue())
require.False(t, opts.Ephemeral())
require.Equal(t, "ECDSA_RERAND", opts.Algorithm())
require.Empty(t, opts.ExpansionValue())
}

func TestHashOpts(t *testing.T) {
for _, ho := range []HashOpts{&SHA256Opts{}, &SHA384Opts{}, &SHA3_256Opts{}, &SHA3_384Opts{}} {
s := strings.Replace(reflect.TypeOf(ho).String(), "*bccsp.", "", -1)
algorithm := strings.Replace(s, "Opts", "", -1)
assert.Equal(t, algorithm, ho.Algorithm())
require.Equal(t, algorithm, ho.Algorithm())
ho2, err := GetHashOpt(algorithm)
assert.NoError(t, err)
assert.Equal(t, ho.Algorithm(), ho2.Algorithm())
require.NoError(t, err)
require.Equal(t, ho.Algorithm(), ho2.Algorithm())
}
_, err := GetHashOpt("foo")
assert.Error(t, err)
assert.Contains(t, err.Error(), "hash function not recognized")
require.Error(t, err)
require.Contains(t, err.Error(), "hash function not recognized")

assert.Equal(t, "SHA", (&SHAOpts{}).Algorithm())
require.Equal(t, "SHA", (&SHAOpts{}).Algorithm())
}

func TestHMAC(t *testing.T) {
opts := &HMACTruncated256AESDeriveKeyOpts{Arg: []byte("arg")}
assert.False(t, opts.Ephemeral())
require.False(t, opts.Ephemeral())
opts.Temporary = true
assert.True(t, opts.Ephemeral())
assert.Equal(t, "HMAC_TRUNCATED_256", opts.Algorithm())
assert.Equal(t, []byte("arg"), opts.Argument())
require.True(t, opts.Ephemeral())
require.Equal(t, "HMAC_TRUNCATED_256", opts.Algorithm())
require.Equal(t, []byte("arg"), opts.Argument())

opts2 := &HMACDeriveKeyOpts{Arg: []byte("arg")}
assert.False(t, opts2.Ephemeral())
require.False(t, opts2.Ephemeral())
opts2.Temporary = true
assert.True(t, opts2.Ephemeral())
assert.Equal(t, "HMAC", opts2.Algorithm())
assert.Equal(t, []byte("arg"), opts2.Argument())
require.True(t, opts2.Ephemeral())
require.Equal(t, "HMAC", opts2.Algorithm())
require.Equal(t, []byte("arg"), opts2.Argument())
}

func TestKeyGenOpts(t *testing.T) {
Expand All @@ -127,8 +127,8 @@ func TestKeyGenOpts(t *testing.T) {
&AES256ImportKeyOpts{ephemeral},
} {
expectedAlgorithm := expectedAlgorithms[reflect.TypeOf(opts)]
assert.Equal(t, expectedAlgorithm, opts.Algorithm())
assert.Equal(t, ephemeral, opts.Ephemeral())
require.Equal(t, expectedAlgorithm, opts.Algorithm())
require.Equal(t, ephemeral, opts.Ephemeral())
}
}
test(true)
Expand Down
6 changes: 3 additions & 3 deletions bccsp/factory/nopkcs11_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ package factory
import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestInitFactories(t *testing.T) {
err := initFactories(&FactoryOpts{
ProviderName: "SW",
SwOpts: &SwOpts{},
})
assert.EqualError(t, err, "Failed initializing BCCSP: Could not initialize BCCSP SW [Failed initializing configuration at [0,]: Hash Family not supported []]")
require.EqualError(t, err, "Failed initializing BCCSP: Could not initialize BCCSP SW [Failed initializing configuration at [0,]: Hash Family not supported []]")

err = initFactories(&FactoryOpts{
ProviderName: "PKCS11",
})
assert.EqualError(t, err, "Could not find default `PKCS11` BCCSP")
require.EqualError(t, err, "Could not find default `PKCS11` BCCSP")
}
4 changes: 2 additions & 2 deletions bccsp/factory/opts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ package factory
import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestFactoryOptsFactoryName(t *testing.T) {
assert.Equal(t, GetDefaultOpts().FactoryName(), "SW")
require.Equal(t, GetDefaultOpts().FactoryName(), "SW")
}
24 changes: 12 additions & 12 deletions bccsp/factory/pkcs11_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,45 +13,45 @@ import (
"testing"

"github.com/hyperledger/fabric/bccsp/pkcs11"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestExportedInitFactories(t *testing.T) {
// Reset errors from previous negative test runs
factoriesInitError = initFactories(nil)

err := InitFactories(nil)
assert.NoError(t, err)
require.NoError(t, err)
}

func TestInitFactories(t *testing.T) {
err := initFactories(nil)
assert.NoError(t, err)
require.NoError(t, err)

err = initFactories(&FactoryOpts{})
assert.NoError(t, err)
require.NoError(t, err)
}

func TestInitFactoriesInvalidArgs(t *testing.T) {
err := initFactories(&FactoryOpts{
ProviderName: "SW",
SwOpts: &SwOpts{},
})
assert.EqualError(t, err, "Failed initializing SW.BCCSP: Could not initialize BCCSP SW [Failed initializing configuration at [0,]: Hash Family not supported []]")
require.EqualError(t, err, "Failed initializing SW.BCCSP: Could not initialize BCCSP SW [Failed initializing configuration at [0,]: Hash Family not supported []]")

err = initFactories(&FactoryOpts{
ProviderName: "PKCS11",
Pkcs11Opts: &pkcs11.PKCS11Opts{},
})
assert.EqualError(t, err, "Failed initializing PKCS11.BCCSP: Could not initialize BCCSP PKCS11 [Failed initializing configuration: Hash Family not supported []]")
require.EqualError(t, err, "Failed initializing PKCS11.BCCSP: Could not initialize BCCSP PKCS11 [Failed initializing configuration: Hash Family not supported []]")
}

func TestGetBCCSPFromOpts(t *testing.T) {
opts := GetDefaultOpts()
opts.SwOpts.FileKeystore = &FileKeystoreOpts{KeyStorePath: os.TempDir()}
csp, err := GetBCCSPFromOpts(opts)
assert.NoError(t, err)
assert.NotNil(t, csp)
require.NoError(t, err)
require.NotNil(t, csp)

lib, pin, label := pkcs11.FindPKCS11Lib()
csp, err = GetBCCSPFromOpts(&FactoryOpts{
Expand All @@ -64,12 +64,12 @@ func TestGetBCCSPFromOpts(t *testing.T) {
Label: label,
},
})
assert.NoError(t, err)
assert.NotNil(t, csp)
require.NoError(t, err)
require.NotNil(t, csp)

csp, err = GetBCCSPFromOpts(&FactoryOpts{
ProviderName: "BadName",
})
assert.EqualError(t, err, "Could not find BCCSP, no 'BadName' provider")
assert.Nil(t, csp)
require.EqualError(t, err, "Could not find BCCSP, no 'BadName' provider")
require.Nil(t, csp)
}
30 changes: 15 additions & 15 deletions bccsp/factory/pkcs11factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,28 @@ import (
"testing"

"github.com/hyperledger/fabric/bccsp/pkcs11"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestPKCS11FactoryName(t *testing.T) {
f := &PKCS11Factory{}
assert.Equal(t, f.Name(), PKCS11BasedFactoryName)
require.Equal(t, f.Name(), PKCS11BasedFactoryName)
}

func TestPKCS11FactoryGetInvalidArgs(t *testing.T) {
f := &PKCS11Factory{}

_, err := f.Get(nil)
assert.Error(t, err, "Invalid config. It must not be nil.")
require.Error(t, err, "Invalid config. It must not be nil.")

_, err = f.Get(&FactoryOpts{})
assert.Error(t, err, "Invalid config. It must not be nil.")
require.Error(t, err, "Invalid config. It must not be nil.")

opts := &FactoryOpts{
Pkcs11Opts: &pkcs11.PKCS11Opts{},
}
_, err = f.Get(opts)
assert.Error(t, err, "CSP:500 - Failed initializing configuration at [0,]")
require.Error(t, err, "CSP:500 - Failed initializing configuration at [0,]")
}

func TestPKCS11FactoryGet(t *testing.T) {
Expand All @@ -50,8 +50,8 @@ func TestPKCS11FactoryGet(t *testing.T) {
},
}
csp, err := f.Get(opts)
assert.NoError(t, err)
assert.NotNil(t, csp)
require.NoError(t, err)
require.NotNil(t, csp)

opts = &FactoryOpts{
Pkcs11Opts: &pkcs11.PKCS11Opts{
Expand All @@ -63,8 +63,8 @@ func TestPKCS11FactoryGet(t *testing.T) {
},
}
csp, err = f.Get(opts)
assert.NoError(t, err)
assert.NotNil(t, csp)
require.NoError(t, err)
require.NotNil(t, csp)

opts = &FactoryOpts{
Pkcs11Opts: &pkcs11.PKCS11Opts{
Expand All @@ -76,8 +76,8 @@ func TestPKCS11FactoryGet(t *testing.T) {
},
}
csp, err = f.Get(opts)
assert.NoError(t, err)
assert.NotNil(t, csp)
require.NoError(t, err)
require.NotNil(t, csp)
}

func TestPKCS11FactoryGetEmptyKeyStorePath(t *testing.T) {
Expand All @@ -94,8 +94,8 @@ func TestPKCS11FactoryGetEmptyKeyStorePath(t *testing.T) {
},
}
csp, err := f.Get(opts)
assert.NoError(t, err)
assert.NotNil(t, csp)
require.NoError(t, err)
require.NotNil(t, csp)

opts = &FactoryOpts{
Pkcs11Opts: &pkcs11.PKCS11Opts{
Expand All @@ -107,6 +107,6 @@ func TestPKCS11FactoryGetEmptyKeyStorePath(t *testing.T) {
},
}
csp, err = f.Get(opts)
assert.NoError(t, err)
assert.NotNil(t, csp)
require.NoError(t, err)
require.NotNil(t, csp)
}
18 changes: 9 additions & 9 deletions bccsp/factory/swfactory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,28 @@ import (
"os"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestSWFactoryName(t *testing.T) {
f := &SWFactory{}
assert.Equal(t, f.Name(), SoftwareBasedFactoryName)
require.Equal(t, f.Name(), SoftwareBasedFactoryName)
}

func TestSWFactoryGetInvalidArgs(t *testing.T) {
f := &SWFactory{}

_, err := f.Get(nil)
assert.Error(t, err, "Invalid config. It must not be nil.")
require.Error(t, err, "Invalid config. It must not be nil.")

_, err = f.Get(&FactoryOpts{})
assert.Error(t, err, "Invalid config. It must not be nil.")
require.Error(t, err, "Invalid config. It must not be nil.")

opts := &FactoryOpts{
SwOpts: &SwOpts{},
}
_, err = f.Get(opts)
assert.Error(t, err, "CSP:500 - Failed initializing configuration at [0,]")
require.Error(t, err, "CSP:500 - Failed initializing configuration at [0,]")
}

func TestSWFactoryGet(t *testing.T) {
Expand All @@ -53,8 +53,8 @@ func TestSWFactoryGet(t *testing.T) {
},
}
csp, err := f.Get(opts)
assert.NoError(t, err)
assert.NotNil(t, csp)
require.NoError(t, err)
require.NotNil(t, csp)

opts = &FactoryOpts{
SwOpts: &SwOpts{
Expand All @@ -64,7 +64,7 @@ func TestSWFactoryGet(t *testing.T) {
},
}
csp, err = f.Get(opts)
assert.NoError(t, err)
assert.NotNil(t, csp)
require.NoError(t, err)
require.NotNil(t, csp)

}
Loading

0 comments on commit 694bbca

Please sign in to comment.