Exemple #1
0
func (s *FacadeSuite) TestAddress(c *gc.C) {
	var stub jujutesting.Stub
	apiCaller := apitesting.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
		stub.AddCall(objType+"."+request, arg)
		c.Check(id, gc.Equals, "")
		*result.(*params.SSHAddressResults) = params.SSHAddressResults{
			Results: []params.SSHAddressResult{{Address: "1.1.1.1"}},
		}
		return nil
	})
	facade := sshclient.NewFacade(apiCaller)
	expectedArg := []interface{}{params.Entities{[]params.Entity{{
		names.NewUnitTag("foo/0").String(),
	}}}}

	public, err := facade.PublicAddress("foo/0")
	c.Assert(err, jc.ErrorIsNil)
	c.Check(public, gc.Equals, "1.1.1.1")
	stub.CheckCalls(c, []jujutesting.StubCall{{"SSHClient.PublicAddress", expectedArg}})
	stub.ResetCalls()

	private, err := facade.PrivateAddress("foo/0")
	c.Assert(err, jc.ErrorIsNil)
	c.Check(private, gc.Equals, "1.1.1.1")
	stub.CheckCalls(c, []jujutesting.StubCall{{"SSHClient.PrivateAddress", expectedArg}})
}
Exemple #2
0
func (s *FacadeSuite) TestProxyError(c *gc.C) {
	apiCaller := apitesting.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
		return errors.New("boom")
	})
	facade := sshclient.NewFacade(apiCaller)
	_, err := facade.Proxy()
	c.Check(err, gc.ErrorMatches, "boom")
}
Exemple #3
0
// initAPIClient initialises the API connection.
func (c *SSHCommon) initAPIClient() error {
	conn, err := c.NewAPIRoot()
	if err != nil {
		return errors.Trace(err)
	}
	c.apiClient = sshclient.NewFacade(conn)
	c.apiAddr = conn.Addr()
	return nil
}
Exemple #4
0
func (s *FacadeSuite) TestPublicKeysMissingResults(c *gc.C) {
	apiCaller := apitesting.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
		return nil
	})
	facade := sshclient.NewFacade(apiCaller)
	keys, err := facade.PublicKeys("foo/0")
	c.Check(keys, gc.IsNil)
	c.Check(err, gc.ErrorMatches, "expected 1 result, got 0")
}
Exemple #5
0
func (s *FacadeSuite) TestPublicKeysError(c *gc.C) {
	apiCaller := apitesting.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
		return errors.New("boom")
	})
	facade := sshclient.NewFacade(apiCaller)
	keys, err := facade.PublicKeys("foo/0")
	c.Check(keys, gc.IsNil)
	c.Check(err, gc.ErrorMatches, "boom")
}
Exemple #6
0
func (s *FacadeSuite) TestAddressError(c *gc.C) {
	apiCaller := apitesting.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
		return errors.New("boom")
	})
	facade := sshclient.NewFacade(apiCaller)

	public, err := facade.PublicAddress("foo/0")
	c.Check(public, gc.Equals, "")
	c.Check(err, gc.ErrorMatches, "boom")

	private, err := facade.PrivateAddress("foo/0")
	c.Check(private, gc.Equals, "")
	c.Check(err, gc.ErrorMatches, "boom")
}
Exemple #7
0
func (s *FacadeSuite) TestAddressMissingResults(c *gc.C) {
	apiCaller := apitesting.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
		return nil
	})
	facade := sshclient.NewFacade(apiCaller)
	expectedErr := "expected 1 result, got 0"

	public, err := facade.PublicAddress("foo/0")
	c.Check(public, gc.Equals, "")
	c.Check(err, gc.ErrorMatches, expectedErr)

	private, err := facade.PrivateAddress("foo/0")
	c.Check(private, gc.Equals, "")
	c.Check(err, gc.ErrorMatches, expectedErr)
}
Exemple #8
0
func checkProxy(c *gc.C, useProxy bool) {
	var stub jujutesting.Stub
	apiCaller := apitesting.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
		stub.AddCall(objType+"."+request, arg)
		*result.(*params.SSHProxyResult) = params.SSHProxyResult{
			UseProxy: useProxy,
		}
		return nil
	})
	facade := sshclient.NewFacade(apiCaller)
	result, err := facade.Proxy()
	c.Check(err, jc.ErrorIsNil)
	c.Check(result, gc.Equals, useProxy)
	stub.CheckCalls(c, []jujutesting.StubCall{{"SSHClient.Proxy", []interface{}{nil}}})
}
Exemple #9
0
func (s *FacadeSuite) TestPublicKeysExtraResults(c *gc.C) {
	apiCaller := apitesting.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
		*result.(*params.SSHPublicKeysResults) = params.SSHPublicKeysResults{
			Results: []params.SSHPublicKeysResult{
				{PublicKeys: []string{"rsa"}},
				{PublicKeys: []string{"rsa"}},
			},
		}
		return nil
	})
	facade := sshclient.NewFacade(apiCaller)
	keys, err := facade.PublicKeys("foo/0")
	c.Check(keys, gc.IsNil)
	c.Check(err, gc.ErrorMatches, "expected 1 result, got 2")
}
Exemple #10
0
func (s *FacadeSuite) TestPublicKeysTargetError(c *gc.C) {
	var stub jujutesting.Stub
	apiCaller := apitesting.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
		stub.AddCall(objType+"."+request, arg)
		c.Check(id, gc.Equals, "")
		*result.(*params.SSHPublicKeysResults) = params.SSHPublicKeysResults{
			Results: []params.SSHPublicKeysResult{{Error: common.ServerError(errors.New("boom"))}},
		}
		return nil
	})
	facade := sshclient.NewFacade(apiCaller)
	keys, err := facade.PublicKeys("foo/0")
	c.Check(keys, gc.IsNil)
	c.Check(err, gc.ErrorMatches, "boom")
}
Exemple #11
0
func (s *FacadeSuite) TestAddressTargetError(c *gc.C) {
	apiCaller := apitesting.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
		*result.(*params.SSHAddressResults) = params.SSHAddressResults{
			Results: []params.SSHAddressResult{{Error: common.ServerError(errors.New("boom"))}},
		}
		return nil
	})
	facade := sshclient.NewFacade(apiCaller)

	public, err := facade.PublicAddress("foo/0")
	c.Check(public, gc.Equals, "")
	c.Check(err, gc.ErrorMatches, "boom")

	private, err := facade.PrivateAddress("foo/0")
	c.Check(private, gc.Equals, "")
	c.Check(err, gc.ErrorMatches, "boom")
}
Exemple #12
0
func (s *FacadeSuite) TestPublicKeys(c *gc.C) {
	var stub jujutesting.Stub
	apiCaller := apitesting.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
		stub.AddCall(objType+"."+request, arg)
		c.Check(id, gc.Equals, "")
		*result.(*params.SSHPublicKeysResults) = params.SSHPublicKeysResults{
			Results: []params.SSHPublicKeysResult{{PublicKeys: []string{"rsa", "dsa"}}},
		}
		return nil
	})
	facade := sshclient.NewFacade(apiCaller)
	keys, err := facade.PublicKeys("foo/0")
	c.Assert(err, jc.ErrorIsNil)
	c.Check(keys, gc.DeepEquals, []string{"rsa", "dsa"})
	stub.CheckCalls(c, []jujutesting.StubCall{{
		"SSHClient.PublicKeys",
		[]interface{}{params.Entities{[]params.Entity{{
			Tag: names.NewUnitTag("foo/0").String(),
		}}}},
	}})
}
Exemple #13
0
func (s *FacadeSuite) TestAddressExtraResults(c *gc.C) {
	apiCaller := apitesting.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
		*result.(*params.SSHAddressResults) = params.SSHAddressResults{
			Results: []params.SSHAddressResult{
				{Address: "1.1.1.1"},
				{Address: "2.2.2.2"},
			},
		}
		return nil
	})
	facade := sshclient.NewFacade(apiCaller)
	expectedErr := "expected 1 result, got 2"

	public, err := facade.PublicAddress("foo/0")
	c.Check(public, gc.Equals, "")
	c.Check(err, gc.ErrorMatches, expectedErr)

	private, err := facade.PrivateAddress("foo/0")
	c.Check(private, gc.Equals, "")
	c.Check(err, gc.ErrorMatches, expectedErr)
}