github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/provider/lxd/upgrades_test.go (about) 1 // Copyright 2017 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package lxd_test 5 6 import ( 7 "os" 8 9 "github.com/juju/errors" 10 "github.com/juju/testing" 11 jc "github.com/juju/testing/checkers" 12 gc "gopkg.in/check.v1" 13 14 "github.com/juju/juju/cloud" 15 "github.com/juju/juju/provider/lxd" 16 ) 17 18 type upgradesSuite struct { 19 testing.IsolationSuite 20 } 21 22 var _ = gc.Suite(&upgradesSuite{}) 23 24 func (s *upgradesSuite) TestReadLegacyCloudCredentials(c *gc.C) { 25 var paths []string 26 readFile := func(path string) ([]byte, error) { 27 paths = append(paths, path) 28 return []byte("content: " + path), nil 29 } 30 cred, err := lxd.ReadLegacyCloudCredentials(readFile) 31 c.Assert(err, jc.ErrorIsNil) 32 c.Assert(cred, jc.DeepEquals, cloud.NewCredential(cloud.CertificateAuthType, map[string]string{ 33 "client-cert": "content: /etc/juju/lxd-client.crt", 34 "client-key": "content: /etc/juju/lxd-client.key", 35 "server-cert": "content: /etc/juju/lxd-server.crt", 36 })) 37 c.Assert(paths, jc.DeepEquals, []string{ 38 "/etc/juju/lxd-client.crt", 39 "/etc/juju/lxd-client.key", 40 "/etc/juju/lxd-server.crt", 41 }) 42 } 43 44 func (s *upgradesSuite) TestReadLegacyCloudCredentialsFileNotExist(c *gc.C) { 45 readFile := func(path string) ([]byte, error) { 46 return nil, os.ErrNotExist 47 } 48 _, err := lxd.ReadLegacyCloudCredentials(readFile) 49 c.Assert(err, jc.Satisfies, errors.IsNotFound) 50 }