Skip to content

Commit

Permalink
[FAB-18322] Check panic message in TestInitializeServerConfig (#2140)
Browse files Browse the repository at this point in the history
Signed-off-by: Tiffany Harris <tiffany.harris@ibm.com>
  • Loading branch information
stephyee committed Nov 17, 2020
1 parent 504caaf commit bc33cbb
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion orderer/common/server/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,34 +196,39 @@ func TestInitializeServerConfig(t *testing.T) {
clusterKey string
clusterCA string
isCluster bool
expectedPanic string
}{
{
name: "BadCertificate",
certificate: badFile,
privateKey: goodFile,
rootCA: goodFile,
clientRootCert: goodFile,
expectedPanic: "Failed to load server Certificate file 'does_not_exist' (open does_not_exist: no such file or directory)",
},
{
name: "BadPrivateKey",
certificate: goodFile,
privateKey: badFile,
rootCA: goodFile,
clientRootCert: goodFile,
expectedPanic: "Failed to load PrivateKey file 'does_not_exist' (open does_not_exist: no such file or directory)",
},
{
name: "BadRootCA",
certificate: goodFile,
privateKey: goodFile,
rootCA: badFile,
clientRootCert: goodFile,
expectedPanic: "Failed to load ServerRootCAs file 'open does_not_exist: no such file or directory' (does_not_exist)",
},
{
name: "BadClientRootCertificate",
certificate: goodFile,
privateKey: goodFile,
rootCA: goodFile,
clientRootCert: badFile,
expectedPanic: "Failed to load ClientRootCAs file 'open does_not_exist: no such file or directory' (does_not_exist)",
},
{
name: "BadCertificate - cluster reuses server config",
Expand All @@ -235,6 +240,7 @@ func TestInitializeServerConfig(t *testing.T) {
clusterKey: "",
clusterCA: "",
isCluster: true,
expectedPanic: "Failed to load client TLS certificate file 'does_not_exist' (open does_not_exist: no such file or directory)",
},
{
name: "BadPrivateKey - cluster reuses server config",
Expand All @@ -246,6 +252,7 @@ func TestInitializeServerConfig(t *testing.T) {
clusterKey: "",
clusterCA: "",
isCluster: true,
expectedPanic: "Failed to load client TLS key file 'does_not_exist' (open does_not_exist: no such file or directory)",
},
{
name: "BadRootCA - cluster reuses server config",
Expand All @@ -257,6 +264,7 @@ func TestInitializeServerConfig(t *testing.T) {
clusterKey: "",
clusterCA: "",
isCluster: true,
expectedPanic: "Failed to load ServerRootCAs file '' (open : no such file or directory)",
},
{
name: "ClusterBadCertificate",
Expand All @@ -268,6 +276,7 @@ func TestInitializeServerConfig(t *testing.T) {
clusterKey: goodFile,
clusterCA: goodFile,
isCluster: true,
expectedPanic: "Failed to load client TLS certificate file 'does_not_exist' (open does_not_exist: no such file or directory)",
},
{
name: "ClusterBadPrivateKey",
Expand All @@ -279,6 +288,7 @@ func TestInitializeServerConfig(t *testing.T) {
clusterKey: badFile,
clusterCA: goodFile,
isCluster: true,
expectedPanic: "Failed to load client TLS key file 'does_not_exist' (open does_not_exist: no such file or directory)",
},
{
name: "ClusterBadRootCA",
Expand All @@ -290,6 +300,7 @@ func TestInitializeServerConfig(t *testing.T) {
clusterKey: goodFile,
clusterCA: badFile,
isCluster: true,
expectedPanic: "Failed to load ServerRootCAs file 'does_not_exist' (open does_not_exist: no such file or directory)",
},
}
for _, tc := range testCases {
Expand All @@ -311,7 +322,7 @@ func TestInitializeServerConfig(t *testing.T) {
},
},
}
require.Panics(t, func() {
require.PanicsWithValue(t, tc.expectedPanic, func() {
if !tc.isCluster {
initializeServerConfig(conf, nil)
} else {
Expand Down

0 comments on commit bc33cbb

Please sign in to comment.