示例#1
0
func (test configTest) check(c *gc.C, home *testing.FakeHome) {
	cfg, err := config.New(test.attrs)
	if test.err != "" {
		c.Check(cfg, gc.IsNil)
		c.Assert(err, gc.ErrorMatches, test.err)
		return
	}
	c.Assert(err, gc.IsNil)

	typ, _ := test.attrs["type"].(string)
	name, _ := test.attrs["name"].(string)
	c.Assert(cfg.Type(), gc.Equals, typ)
	c.Assert(cfg.Name(), gc.Equals, name)
	agentVersion, ok := cfg.AgentVersion()
	if s := test.attrs["agent-version"]; s != nil {
		c.Assert(ok, jc.IsTrue)
		c.Assert(agentVersion, gc.Equals, version.MustParse(s.(string)))
	} else {
		c.Assert(ok, jc.IsFalse)
		c.Assert(agentVersion, gc.Equals, version.Zero)
	}

	if statePort, _ := test.attrs["state-port"].(int); statePort != 0 {
		c.Assert(cfg.StatePort(), gc.Equals, statePort)
	}
	if apiPort, _ := test.attrs["api-port"].(int); apiPort != 0 {
		c.Assert(cfg.APIPort(), gc.Equals, apiPort)
	}

	dev, _ := test.attrs["development"].(bool)
	c.Assert(cfg.Development(), gc.Equals, dev)

	if series, _ := test.attrs["default-series"].(string); series != "" {
		c.Assert(cfg.DefaultSeries(), gc.Equals, series)
	} else {
		c.Assert(cfg.DefaultSeries(), gc.Equals, config.DefaultSeries)
	}

	if m, _ := test.attrs["firewall-mode"].(string); m != "" {
		c.Assert(cfg.FirewallMode(), gc.Equals, config.FirewallMode(m))
	}

	if secret, _ := test.attrs["admin-secret"].(string); secret != "" {
		c.Assert(cfg.AdminSecret(), gc.Equals, secret)
	}

	if path, _ := test.attrs["authorized-keys-path"].(string); path != "" {
		c.Assert(cfg.AuthorizedKeys(), gc.Equals, home.FileContents(c, path))
		c.Assert(cfg.AllAttrs()["authorized-keys-path"], gc.IsNil)
	} else if keys, _ := test.attrs["authorized-keys"].(string); keys != "" {
		c.Assert(cfg.AuthorizedKeys(), gc.Equals, keys)
	} else {
		// Content of all the files that are read by default.
		want := "dsa\nrsa\nidentity\n"
		c.Assert(cfg.AuthorizedKeys(), gc.Equals, want)
	}

	cert, certPresent := cfg.CACert()
	if path, _ := test.attrs["ca-cert-path"].(string); path != "" {
		c.Assert(certPresent, jc.IsTrue)
		c.Assert(string(cert), gc.Equals, home.FileContents(c, path))
	} else if v, ok := test.attrs["ca-cert"].(string); v != "" {
		c.Assert(certPresent, jc.IsTrue)
		c.Assert(string(cert), gc.Equals, v)
	} else if ok {
		c.Check(cert, gc.HasLen, 0)
		c.Assert(certPresent, jc.IsFalse)
	} else if home.FileExists(".juju/my-name-cert.pem") {
		c.Assert(certPresent, jc.IsTrue)
		c.Assert(string(cert), gc.Equals, home.FileContents(c, "my-name-cert.pem"))
	} else {
		c.Check(cert, gc.HasLen, 0)
		c.Assert(certPresent, jc.IsFalse)
	}

	key, keyPresent := cfg.CAPrivateKey()
	if path, _ := test.attrs["ca-private-key-path"].(string); path != "" {
		c.Assert(keyPresent, jc.IsTrue)
		c.Assert(string(key), gc.Equals, home.FileContents(c, path))
	} else if v, ok := test.attrs["ca-private-key"].(string); v != "" {
		c.Assert(keyPresent, jc.IsTrue)
		c.Assert(string(key), gc.Equals, v)
	} else if ok {
		c.Check(key, gc.HasLen, 0)
		c.Assert(keyPresent, jc.IsFalse)
	} else if home.FileExists(".juju/my-name-private-key.pem") {
		c.Assert(keyPresent, jc.IsTrue)
		c.Assert(string(key), gc.Equals, home.FileContents(c, "my-name-private-key.pem"))
	} else {
		c.Check(key, gc.HasLen, 0)
		c.Assert(keyPresent, jc.IsFalse)
	}

	if v, ok := test.attrs["ssl-hostname-verification"]; ok {
		c.Assert(cfg.SSLHostnameVerification(), gc.Equals, v)
	}
}
示例#2
0
func (test configTest) check(c *C, h fakeHome) {
	cfg, err := config.New(test.attrs)
	if test.err != "" {
		c.Check(cfg, IsNil)
		c.Assert(err, ErrorMatches, test.err)
		return
	}
	c.Assert(err, IsNil)

	typ, _ := test.attrs["type"].(string)
	name, _ := test.attrs["name"].(string)
	c.Assert(cfg.Type(), Equals, typ)
	c.Assert(cfg.Name(), Equals, name)
	if s := test.attrs["agent-version"]; s != nil {
		vers, err := version.Parse(s.(string))
		c.Assert(err, IsNil)
		c.Assert(cfg.AgentVersion(), Equals, vers)
	} else {
		c.Assert(cfg.AgentVersion(), Equals, version.Number{})
	}

	dev, _ := test.attrs["development"].(bool)
	c.Assert(cfg.Development(), Equals, dev)

	if series, _ := test.attrs["default-series"].(string); series != "" {
		c.Assert(cfg.DefaultSeries(), Equals, series)
	} else {
		c.Assert(cfg.DefaultSeries(), Equals, version.Current.Series)
	}

	if m, _ := test.attrs["firewall-mode"].(string); m != "" {
		c.Assert(cfg.FirewallMode(), Equals, config.FirewallMode(m))
	}

	if secret, _ := test.attrs["admin-secret"].(string); secret != "" {
		c.Assert(cfg.AdminSecret(), Equals, secret)
	}

	if path, _ := test.attrs["authorized-keys-path"].(string); path != "" {
		c.Assert(cfg.AuthorizedKeys(), Equals, h.fileContents(c, path))
		c.Assert(cfg.AllAttrs()["authorized-keys-path"], Equals, nil)
	} else if keys, _ := test.attrs["authorized-keys"].(string); keys != "" {
		c.Assert(cfg.AuthorizedKeys(), Equals, keys)
	} else {
		// Content of all the files that are read by default.
		want := "dsa\nrsa\nidentity\n"
		c.Assert(cfg.AuthorizedKeys(), Equals, want)
	}

	cert, certPresent := cfg.CACert()
	if path, _ := test.attrs["ca-cert-path"].(string); path != "" {
		c.Assert(certPresent, Equals, true)
		c.Assert(string(cert), Equals, h.fileContents(c, path))
	} else if v, ok := test.attrs["ca-cert"].(string); v != "" {
		c.Assert(certPresent, Equals, true)
		c.Assert(string(cert), Equals, v)
	} else if ok {
		c.Check(cert, HasLen, 0)
		c.Assert(certPresent, Equals, false)
	} else if h.fileExists(".juju/my-name-cert.pem") {
		c.Assert(certPresent, Equals, true)
		c.Assert(string(cert), Equals, h.fileContents(c, "my-name-cert.pem"))
	} else {
		c.Check(cert, HasLen, 0)
		c.Assert(certPresent, Equals, false)
	}

	key, keyPresent := cfg.CAPrivateKey()
	if path, _ := test.attrs["ca-private-key-path"].(string); path != "" {
		c.Assert(keyPresent, Equals, true)
		c.Assert(string(key), Equals, h.fileContents(c, path))
	} else if v, ok := test.attrs["ca-private-key"].(string); v != "" {
		c.Assert(keyPresent, Equals, true)
		c.Assert(string(key), Equals, v)
	} else if ok {
		c.Check(key, HasLen, 0)
		c.Assert(keyPresent, Equals, false)
	} else if h.fileExists(".juju/my-name-private-key.pem") {
		c.Assert(keyPresent, Equals, true)
		c.Assert(string(key), Equals, h.fileContents(c, "my-name-private-key.pem"))
	} else {
		c.Check(key, HasLen, 0)
		c.Assert(keyPresent, Equals, false)
	}

	if v, ok := test.attrs["ssl-hostname-verification"]; ok {
		c.Assert(cfg.SSLHostnameVerification(), Equals, v)
	}
}