Skip to content

Commit

Permalink
[FAB-3924] Improved test coverage lib/tls package
Browse files Browse the repository at this point in the history
This change-set improves the test coverage
of the lib/tls package to over 85%

Change-Id: I6e880a9f3c3c5850d0f5b1b5b1545c2e00f3e923
Signed-off-by: Angelo De Caro <adc@zurich.ibm.com>
  • Loading branch information
adecaro committed May 16, 2017
1 parent bdefc3a commit cb7a109
Showing 1 changed file with 71 additions and 1 deletion.
72 changes: 71 additions & 1 deletion lib/tls/tls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ limitations under the License.

package tls

import "testing"
import (
"testing"

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

const (
configDir = "../../testdata"
Expand Down Expand Up @@ -47,3 +51,69 @@ func TestGetClientTLSConfig(t *testing.T) {
}

}

func TestGetClientTLSConfigInvalidArgs(t *testing.T) {
// 1.
cfg := &ClientTLSConfig{
CertFiles: []string{"root.pem"},
Client: KeyCertFiles{
KeyFile: "no_tls_client-key.pem",
CertFile: "no_tls_client-cert.pem",
},
}
_, err := GetClientTLSConfig(cfg)
assert.Error(t, err)
assert.Contains(t, err.Error(), "open no_tls_client-cert.pem: no such file or directory")

// 2.
cfg = &ClientTLSConfig{
CertFiles: nil,
Client: KeyCertFiles{
KeyFile: "tls_client-key.pem",
CertFile: "tls_client-cert.pem",
},
}
AbsTLSClient(cfg, configDir)
_, err = GetClientTLSConfig(cfg)
assert.Error(t, err)
assert.Contains(t, err.Error(), "No CA certificate files provided")

// 3.
cfg = &ClientTLSConfig{
CertFiles: nil,
Client: KeyCertFiles{
KeyFile: "no-tls_client-key.pem",
CertFile: "tls_client-cert.pem",
},
}
AbsTLSClient(cfg, configDir)
_, err = GetClientTLSConfig(cfg)
assert.Error(t, err)
assert.Contains(t, err.Error(), "no-tls_client-key.pem: no such file or directory")

// 4.
cfg = &ClientTLSConfig{
CertFiles: nil,
Client: KeyCertFiles{
KeyFile: "",
CertFile: "",
},
}
_, err = GetClientTLSConfig(cfg)
assert.Error(t, err)
assert.Contains(t, err.Error(), "No CA certificate files provided")

// 5.
cfg = &ClientTLSConfig{
CertFiles: []string{"no-root.pem"},
Client: KeyCertFiles{
KeyFile: "tls_client-key.pem",
CertFile: "tls_client-cert.pem",
},
}
AbsTLSClient(cfg, configDir)
_, err = GetClientTLSConfig(cfg)
assert.Error(t, err)
assert.Contains(t, err.Error(), "no-root.pem: no such file or directory")

}

0 comments on commit cb7a109

Please sign in to comment.