示例#1
0
func (s *ProxyUpdaterSuite) TestEnvironmentVariables(c *gc.C) {
	setenv := func(proxy, value string) {
		os.Setenv(proxy, value)
		os.Setenv(strings.ToUpper(proxy), value)
	}
	setenv("http_proxy", "foo")
	setenv("https_proxy", "foo")
	setenv("ftp_proxy", "foo")
	setenv("no_proxy", "foo")

	proxySettings, _ := s.updateConfig(c)
	updater, err := proxyupdater.NewWorker(s.config)
	c.Assert(err, jc.ErrorIsNil)
	defer worker.Stop(updater)
	s.waitProxySettings(c, proxySettings)

	assertEnv := func(proxy, value string) {
		c.Assert(os.Getenv(proxy), gc.Equals, value)
		c.Assert(os.Getenv(strings.ToUpper(proxy)), gc.Equals, value)
	}
	assertEnv("http_proxy", proxySettings.Http)
	assertEnv("https_proxy", proxySettings.Https)
	assertEnv("ftp_proxy", proxySettings.Ftp)
	assertEnv("no_proxy", proxySettings.NoProxy)
}
示例#2
0
func (s *ProxyUpdaterSuite) TestDontWriteSystemFiles(c *gc.C) {
	proxySettings, _ := s.updateConfig(c)

	updater, err := proxyupdater.NewWorker(s.proxyUpdaterAPI, false)
	c.Assert(err, jc.ErrorIsNil)
	defer worker.Stop(updater)
	s.waitForPostSetup(c)

	s.waitProxySettings(c, proxySettings)
	c.Assert(pacconfig.AptProxyConfigFile, jc.DoesNotExist)
	c.Assert(s.proxyFile, jc.DoesNotExist)
}
示例#3
0
func (s *ProxyUpdaterSuite) TestWriteSystemFiles(c *gc.C) {
	proxySettings, aptProxySettings := s.updateConfig(c)

	updater, err := proxyupdater.NewWorker(s.config)
	c.Assert(err, jc.ErrorIsNil)
	defer worker.Stop(updater)

	s.waitProxySettings(c, proxySettings)
	s.waitForFile(c, s.proxyFile, proxySettings.AsScriptEnvironment()+"\n")

	paccmder, err := commands.NewPackageCommander(series.HostSeries())
	c.Assert(err, jc.ErrorIsNil)
	s.waitForFile(c, pacconfig.AptProxyConfigFile, paccmder.ProxyConfigContents(aptProxySettings)+"\n")
}
示例#4
0
func (s *ProxyUpdaterSuite) TestExternalFuncCalled(c *gc.C) {
	proxySettings, _ := s.updateConfig(c)

	var externalSettings proxy.Settings
	updated := make(chan struct{})
	s.config.ExternalUpdate = func(values proxy.Settings) error {
		externalSettings = values
		close(updated)
		return nil
	}
	updater, err := proxyupdater.NewWorker(s.config)
	c.Assert(err, jc.ErrorIsNil)
	defer worker.Stop(updater)

	select {
	case <-time.After(time.Second):
		c.Fatal("function not called")
	case <-updated:
	}

	c.Assert(externalSettings, jc.DeepEquals, proxySettings)
}
示例#5
0
func (s *ProxyUpdaterSuite) TestRunStop(c *gc.C) {
	updater, err := proxyupdater.NewWorker(s.config)
	c.Assert(err, jc.ErrorIsNil)
	workertest.CleanKill(c, updater)
}
示例#6
0
func (s *ProxyUpdaterSuite) TestRunStop(c *gc.C) {
	updater, err := proxyupdater.NewWorker(s.proxyUpdaterAPI)
	c.Assert(err, jc.ErrorIsNil)
	err = worker.Stop(updater)
	c.Assert(err, jc.ErrorIsNil)
}