Skip to content

Commit 694bbca

Browse files
sykesmBrett Logan
authored andcommitted
Move everything from testify/assert to require
Signed-off-by: Matthew Sykes <[email protected]>
1 parent 5e0624d commit 694bbca

File tree

389 files changed

+9142
-9179
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

389 files changed

+9142
-9179
lines changed

bccsp/bccsp_test.go

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"strings"
2222
"testing"
2323

24-
"github.com/stretchr/testify/assert"
24+
"github.com/stretchr/testify/require"
2525
)
2626

2727
func TestAESOpts(t *testing.T) {
@@ -32,18 +32,18 @@ func TestAESOpts(t *testing.T) {
3232
&AES256KeyGenOpts{ephemeral},
3333
} {
3434
expectedAlgorithm := reflect.TypeOf(opts).String()[7:13]
35-
assert.Equal(t, expectedAlgorithm, opts.Algorithm())
36-
assert.Equal(t, ephemeral, opts.Ephemeral())
35+
require.Equal(t, expectedAlgorithm, opts.Algorithm())
36+
require.Equal(t, ephemeral, opts.Ephemeral())
3737
}
3838
}
3939
test(true)
4040
test(false)
4141

4242
opts := &AESKeyGenOpts{true}
43-
assert.Equal(t, "AES", opts.Algorithm())
44-
assert.True(t, opts.Ephemeral())
43+
require.Equal(t, "AES", opts.Algorithm())
44+
require.True(t, opts.Ephemeral())
4545
opts.Temporary = false
46-
assert.False(t, opts.Ephemeral())
46+
require.False(t, opts.Ephemeral())
4747
}
4848

4949
func TestECDSAOpts(t *testing.T) {
@@ -53,8 +53,8 @@ func TestECDSAOpts(t *testing.T) {
5353
&ECDSAP384KeyGenOpts{ephemeral},
5454
} {
5555
expectedAlgorithm := reflect.TypeOf(opts).String()[7:16]
56-
assert.Equal(t, expectedAlgorithm, opts.Algorithm())
57-
assert.Equal(t, ephemeral, opts.Ephemeral())
56+
require.Equal(t, expectedAlgorithm, opts.Algorithm())
57+
require.Equal(t, ephemeral, opts.Ephemeral())
5858
}
5959
}
6060
test(true)
@@ -67,51 +67,51 @@ func TestECDSAOpts(t *testing.T) {
6767
&ECDSAPrivateKeyImportOpts{ephemeral},
6868
&ECDSAGoPublicKeyImportOpts{ephemeral},
6969
} {
70-
assert.Equal(t, "ECDSA", opts.Algorithm())
71-
assert.Equal(t, ephemeral, opts.Ephemeral())
70+
require.Equal(t, "ECDSA", opts.Algorithm())
71+
require.Equal(t, ephemeral, opts.Ephemeral())
7272
}
7373
}
7474
test(true)
7575
test(false)
7676

7777
opts := &ECDSAReRandKeyOpts{Temporary: true}
78-
assert.True(t, opts.Ephemeral())
78+
require.True(t, opts.Ephemeral())
7979
opts.Temporary = false
80-
assert.False(t, opts.Ephemeral())
81-
assert.Equal(t, "ECDSA_RERAND", opts.Algorithm())
82-
assert.Empty(t, opts.ExpansionValue())
80+
require.False(t, opts.Ephemeral())
81+
require.Equal(t, "ECDSA_RERAND", opts.Algorithm())
82+
require.Empty(t, opts.ExpansionValue())
8383
}
8484

8585
func TestHashOpts(t *testing.T) {
8686
for _, ho := range []HashOpts{&SHA256Opts{}, &SHA384Opts{}, &SHA3_256Opts{}, &SHA3_384Opts{}} {
8787
s := strings.Replace(reflect.TypeOf(ho).String(), "*bccsp.", "", -1)
8888
algorithm := strings.Replace(s, "Opts", "", -1)
89-
assert.Equal(t, algorithm, ho.Algorithm())
89+
require.Equal(t, algorithm, ho.Algorithm())
9090
ho2, err := GetHashOpt(algorithm)
91-
assert.NoError(t, err)
92-
assert.Equal(t, ho.Algorithm(), ho2.Algorithm())
91+
require.NoError(t, err)
92+
require.Equal(t, ho.Algorithm(), ho2.Algorithm())
9393
}
9494
_, err := GetHashOpt("foo")
95-
assert.Error(t, err)
96-
assert.Contains(t, err.Error(), "hash function not recognized")
95+
require.Error(t, err)
96+
require.Contains(t, err.Error(), "hash function not recognized")
9797

98-
assert.Equal(t, "SHA", (&SHAOpts{}).Algorithm())
98+
require.Equal(t, "SHA", (&SHAOpts{}).Algorithm())
9999
}
100100

101101
func TestHMAC(t *testing.T) {
102102
opts := &HMACTruncated256AESDeriveKeyOpts{Arg: []byte("arg")}
103-
assert.False(t, opts.Ephemeral())
103+
require.False(t, opts.Ephemeral())
104104
opts.Temporary = true
105-
assert.True(t, opts.Ephemeral())
106-
assert.Equal(t, "HMAC_TRUNCATED_256", opts.Algorithm())
107-
assert.Equal(t, []byte("arg"), opts.Argument())
105+
require.True(t, opts.Ephemeral())
106+
require.Equal(t, "HMAC_TRUNCATED_256", opts.Algorithm())
107+
require.Equal(t, []byte("arg"), opts.Argument())
108108

109109
opts2 := &HMACDeriveKeyOpts{Arg: []byte("arg")}
110-
assert.False(t, opts2.Ephemeral())
110+
require.False(t, opts2.Ephemeral())
111111
opts2.Temporary = true
112-
assert.True(t, opts2.Ephemeral())
113-
assert.Equal(t, "HMAC", opts2.Algorithm())
114-
assert.Equal(t, []byte("arg"), opts2.Argument())
112+
require.True(t, opts2.Ephemeral())
113+
require.Equal(t, "HMAC", opts2.Algorithm())
114+
require.Equal(t, []byte("arg"), opts2.Argument())
115115
}
116116

117117
func TestKeyGenOpts(t *testing.T) {
@@ -127,8 +127,8 @@ func TestKeyGenOpts(t *testing.T) {
127127
&AES256ImportKeyOpts{ephemeral},
128128
} {
129129
expectedAlgorithm := expectedAlgorithms[reflect.TypeOf(opts)]
130-
assert.Equal(t, expectedAlgorithm, opts.Algorithm())
131-
assert.Equal(t, ephemeral, opts.Ephemeral())
130+
require.Equal(t, expectedAlgorithm, opts.Algorithm())
131+
require.Equal(t, ephemeral, opts.Ephemeral())
132132
}
133133
}
134134
test(true)

bccsp/factory/nopkcs11_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@ package factory
1111
import (
1212
"testing"
1313

14-
"github.com/stretchr/testify/assert"
14+
"github.com/stretchr/testify/require"
1515
)
1616

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

2424
err = initFactories(&FactoryOpts{
2525
ProviderName: "PKCS11",
2626
})
27-
assert.EqualError(t, err, "Could not find default `PKCS11` BCCSP")
27+
require.EqualError(t, err, "Could not find default `PKCS11` BCCSP")
2828
}

bccsp/factory/opts_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ package factory
1818
import (
1919
"testing"
2020

21-
"github.com/stretchr/testify/assert"
21+
"github.com/stretchr/testify/require"
2222
)
2323

2424
func TestFactoryOptsFactoryName(t *testing.T) {
25-
assert.Equal(t, GetDefaultOpts().FactoryName(), "SW")
25+
require.Equal(t, GetDefaultOpts().FactoryName(), "SW")
2626
}

bccsp/factory/pkcs11_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,45 +13,45 @@ import (
1313
"testing"
1414

1515
"github.com/hyperledger/fabric/bccsp/pkcs11"
16-
"github.com/stretchr/testify/assert"
16+
"github.com/stretchr/testify/require"
1717
)
1818

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

2323
err := InitFactories(nil)
24-
assert.NoError(t, err)
24+
require.NoError(t, err)
2525
}
2626

2727
func TestInitFactories(t *testing.T) {
2828
err := initFactories(nil)
29-
assert.NoError(t, err)
29+
require.NoError(t, err)
3030

3131
err = initFactories(&FactoryOpts{})
32-
assert.NoError(t, err)
32+
require.NoError(t, err)
3333
}
3434

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

4242
err = initFactories(&FactoryOpts{
4343
ProviderName: "PKCS11",
4444
Pkcs11Opts: &pkcs11.PKCS11Opts{},
4545
})
46-
assert.EqualError(t, err, "Failed initializing PKCS11.BCCSP: Could not initialize BCCSP PKCS11 [Failed initializing configuration: Hash Family not supported []]")
46+
require.EqualError(t, err, "Failed initializing PKCS11.BCCSP: Could not initialize BCCSP PKCS11 [Failed initializing configuration: Hash Family not supported []]")
4747
}
4848

4949
func TestGetBCCSPFromOpts(t *testing.T) {
5050
opts := GetDefaultOpts()
5151
opts.SwOpts.FileKeystore = &FileKeystoreOpts{KeyStorePath: os.TempDir()}
5252
csp, err := GetBCCSPFromOpts(opts)
53-
assert.NoError(t, err)
54-
assert.NotNil(t, csp)
53+
require.NoError(t, err)
54+
require.NotNil(t, csp)
5555

5656
lib, pin, label := pkcs11.FindPKCS11Lib()
5757
csp, err = GetBCCSPFromOpts(&FactoryOpts{
@@ -64,12 +64,12 @@ func TestGetBCCSPFromOpts(t *testing.T) {
6464
Label: label,
6565
},
6666
})
67-
assert.NoError(t, err)
68-
assert.NotNil(t, csp)
67+
require.NoError(t, err)
68+
require.NotNil(t, csp)
6969

7070
csp, err = GetBCCSPFromOpts(&FactoryOpts{
7171
ProviderName: "BadName",
7272
})
73-
assert.EqualError(t, err, "Could not find BCCSP, no 'BadName' provider")
74-
assert.Nil(t, csp)
73+
require.EqualError(t, err, "Could not find BCCSP, no 'BadName' provider")
74+
require.Nil(t, csp)
7575
}

bccsp/factory/pkcs11factory_test.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,28 @@ import (
1212
"testing"
1313

1414
"github.com/hyperledger/fabric/bccsp/pkcs11"
15-
"github.com/stretchr/testify/assert"
15+
"github.com/stretchr/testify/require"
1616
)
1717

1818
func TestPKCS11FactoryName(t *testing.T) {
1919
f := &PKCS11Factory{}
20-
assert.Equal(t, f.Name(), PKCS11BasedFactoryName)
20+
require.Equal(t, f.Name(), PKCS11BasedFactoryName)
2121
}
2222

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

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

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

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

3939
func TestPKCS11FactoryGet(t *testing.T) {
@@ -50,8 +50,8 @@ func TestPKCS11FactoryGet(t *testing.T) {
5050
},
5151
}
5252
csp, err := f.Get(opts)
53-
assert.NoError(t, err)
54-
assert.NotNil(t, csp)
53+
require.NoError(t, err)
54+
require.NotNil(t, csp)
5555

5656
opts = &FactoryOpts{
5757
Pkcs11Opts: &pkcs11.PKCS11Opts{
@@ -63,8 +63,8 @@ func TestPKCS11FactoryGet(t *testing.T) {
6363
},
6464
}
6565
csp, err = f.Get(opts)
66-
assert.NoError(t, err)
67-
assert.NotNil(t, csp)
66+
require.NoError(t, err)
67+
require.NotNil(t, csp)
6868

6969
opts = &FactoryOpts{
7070
Pkcs11Opts: &pkcs11.PKCS11Opts{
@@ -76,8 +76,8 @@ func TestPKCS11FactoryGet(t *testing.T) {
7676
},
7777
}
7878
csp, err = f.Get(opts)
79-
assert.NoError(t, err)
80-
assert.NotNil(t, csp)
79+
require.NoError(t, err)
80+
require.NotNil(t, csp)
8181
}
8282

8383
func TestPKCS11FactoryGetEmptyKeyStorePath(t *testing.T) {
@@ -94,8 +94,8 @@ func TestPKCS11FactoryGetEmptyKeyStorePath(t *testing.T) {
9494
},
9595
}
9696
csp, err := f.Get(opts)
97-
assert.NoError(t, err)
98-
assert.NotNil(t, csp)
97+
require.NoError(t, err)
98+
require.NotNil(t, csp)
9999

100100
opts = &FactoryOpts{
101101
Pkcs11Opts: &pkcs11.PKCS11Opts{
@@ -107,6 +107,6 @@ func TestPKCS11FactoryGetEmptyKeyStorePath(t *testing.T) {
107107
},
108108
}
109109
csp, err = f.Get(opts)
110-
assert.NoError(t, err)
111-
assert.NotNil(t, csp)
110+
require.NoError(t, err)
111+
require.NotNil(t, csp)
112112
}

bccsp/factory/swfactory_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,28 @@ import (
1919
"os"
2020
"testing"
2121

22-
"github.com/stretchr/testify/assert"
22+
"github.com/stretchr/testify/require"
2323
)
2424

2525
func TestSWFactoryName(t *testing.T) {
2626
f := &SWFactory{}
27-
assert.Equal(t, f.Name(), SoftwareBasedFactoryName)
27+
require.Equal(t, f.Name(), SoftwareBasedFactoryName)
2828
}
2929

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

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

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

3939
opts := &FactoryOpts{
4040
SwOpts: &SwOpts{},
4141
}
4242
_, err = f.Get(opts)
43-
assert.Error(t, err, "CSP:500 - Failed initializing configuration at [0,]")
43+
require.Error(t, err, "CSP:500 - Failed initializing configuration at [0,]")
4444
}
4545

4646
func TestSWFactoryGet(t *testing.T) {
@@ -53,8 +53,8 @@ func TestSWFactoryGet(t *testing.T) {
5353
},
5454
}
5555
csp, err := f.Get(opts)
56-
assert.NoError(t, err)
57-
assert.NotNil(t, csp)
56+
require.NoError(t, err)
57+
require.NotNil(t, csp)
5858

5959
opts = &FactoryOpts{
6060
SwOpts: &SwOpts{
@@ -64,7 +64,7 @@ func TestSWFactoryGet(t *testing.T) {
6464
},
6565
}
6666
csp, err = f.Get(opts)
67-
assert.NoError(t, err)
68-
assert.NotNil(t, csp)
67+
require.NoError(t, err)
68+
require.NotNil(t, csp)
6969

7070
}

0 commit comments

Comments
 (0)