Skip to content

Commit

Permalink
Handle error when creating etcd client
Browse files Browse the repository at this point in the history
  • Loading branch information
ozdanborne committed Feb 22, 2018
1 parent a06c8bd commit 59b12d9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/backend/etcdv3/etcdv3.go
Expand Up @@ -60,7 +60,11 @@ func NewEtcdV3Client(config *apiconfig.EtcdConfig) (api.Client, error) {
CertFile: config.EtcdCertFile,
KeyFile: config.EtcdKeyFile,
}
tls, _ := tlsInfo.ClientConfig()

tls, err := tlsInfo.ClientConfig()
if err != nil {
return nil, fmt.Errorf("could not initialize etcdv3 client: %+v", err)
}

// Build the etcdv3 config.
cfg := clientv3.Config{
Expand Down
32 changes: 32 additions & 0 deletions lib/backend/etcdv3/etcdv3_test.go
@@ -0,0 +1,32 @@
package etcdv3_test

import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/projectcalico/libcalico-go/lib/apiconfig"
"github.com/projectcalico/libcalico-go/lib/backend/etcdv3"
)

var _ = Describe("RulesAPIToBackend", func() {
It("should raise an error if specified certs don't exist", func() {
_, err := etcdv3.NewEtcdV3Client(&apiconfig.EtcdConfig{
EtcdCACertFile: "/fake/path",
EtcdCertFile: "/fake/path",
EtcdKeyFile: "/fake/path",
EtcdEndpoints: "http://fake:2379",
})

Expect(err).To(HaveOccurred())
})

It("shouldn't create a client with empty certs", func() {
_, err := etcdv3.NewEtcdV3Client(&apiconfig.EtcdConfig{
EtcdCACertFile: "/dev/null",
EtcdCertFile: "/dev/null",
EtcdKeyFile: "/dev/null",
EtcdEndpoints: "http://fake:2379",
})

Expect(err).To(HaveOccurred())
})
})

0 comments on commit 59b12d9

Please sign in to comment.