func (s *configFunctionalSuite) TestUsingTCPRemote(c *gc.C) { if s.client == nil { c.Skip("LXD not running locally") } // We can't just pass the testingCert as part of the Local connection, // because Validate() doesn't like Local remotes that have // Certificates. lxdclient.PatchGenerateCertificate(&s.CleanupSuite, testingCert, testingKey) cfg := lxdclient.Config{ Namespace: "my-ns", Remote: lxdclient.Local, } nonlocal, err := cfg.UsingTCPRemote() c.Assert(err, jc.ErrorIsNil) checkValidRemote(c, &nonlocal.Remote) c.Check(nonlocal, jc.DeepEquals, lxdclient.Config{ Namespace: "my-ns", Remote: lxdclient.Remote{ Name: lxdclient.Local.Name, Host: nonlocal.Remote.Host, Cert: nonlocal.Remote.Cert, Protocol: lxdclient.LXDProtocol, ServerPEMCert: nonlocal.Remote.ServerPEMCert, }, }) c.Check(nonlocal.Remote.Host, gc.Not(gc.Equals), "") c.Check(nonlocal.Remote.Cert.CertPEM, gc.Not(gc.Equals), "") c.Check(nonlocal.Remote.Cert.KeyPEM, gc.Not(gc.Equals), "") c.Check(nonlocal.Remote.ServerPEMCert, gc.Not(gc.Equals), "") // TODO(ericsnow) Check that the server has the certs. }
func (s *remoteFunctionalSuite) TestUsingTCP(c *gc.C) { if _, err := net.InterfaceByName(lxdclient.DefaultLXDBridge); err != nil { c.Skip("network bridge interface not found") } lxdclient.PatchGenerateCertificate(&s.CleanupSuite, testingCert, testingKey) remote := lxdclient.Remote{ Name: "my-remote", Host: "", Cert: nil, } nonlocal, err := remote.UsingTCP() c.Assert(err, jc.ErrorIsNil) checkValidRemote(c, &nonlocal) c.Check(nonlocal, jc.DeepEquals, lxdclient.Remote{ Name: "my-remote", Host: nonlocal.Host, Protocol: lxdclient.LXDProtocol, Cert: nonlocal.Cert, }) }
// TODO(ericsnow) Move this test to a functional suite. func (s *remoteSuite) TestWithDefaultsMissingCert(c *gc.C) { lxdclient.PatchGenerateCertificate(&s.CleanupSuite, testingCert, testingKey) remote := lxdclient.Remote{ Name: "my-remote", Host: "some-host", Protocol: lxdclient.LXDProtocol, Cert: nil, } updated, err := remote.WithDefaults() c.Assert(err, jc.ErrorIsNil) err = updated.Validate() c.Check(err, jc.ErrorIsNil) c.Assert(updated.Cert, gc.NotNil) c.Check(updated.Cert.Validate(), jc.ErrorIsNil) updated.Cert = nil // Validate ensured that the cert was okay. c.Check(updated, jc.DeepEquals, lxdclient.Remote{ Name: "my-remote", Host: "some-host", Protocol: lxdclient.LXDProtocol, Cert: nil, }) }