예제 #1
0
func (s *SnapOpSuite) TestWaitRecovers(c *check.C) {
	restore := snap.MockMaxGoneTime(time.Millisecond)
	defer restore()

	nah := true
	s.RedirectClientToTestServer(func(w http.ResponseWriter, r *http.Request) {
		if nah {
			nah = false
			return
		}
		fmt.Fprintln(w, `{"type": "sync", "result": {"ready": true, "status": "Done"}}`)
	})

	d := c.MkDir()
	oldStdout := os.Stdout
	stdout, err := ioutil.TempFile(d, "stdout")
	c.Assert(err, check.IsNil)
	defer func() {
		os.Stdout = oldStdout
		stdout.Close()
		os.Remove(stdout.Name())
	}()
	os.Stdout = stdout

	cli := snap.Client()
	chg, err := snap.Wait(cli, "x")
	// we got the change
	c.Assert(chg, check.NotNil)
	c.Assert(err, check.IsNil)
	buf, err := ioutil.ReadFile(stdout.Name())
	c.Assert(err, check.IsNil)

	// but only after recovering
	c.Check(string(buf), check.Matches, "(?ms).*Waiting for server to restart.*")
}
예제 #2
0
func (s *SnapOpSuite) TestWait(c *check.C) {
	restore := snap.MockMaxGoneTime(time.Millisecond)
	defer restore()

	// lazy way of getting a URL that won't work nor break stuff
	server := httptest.NewServer(nil)
	snap.ClientConfig.BaseURL = server.URL
	server.Close()

	d := c.MkDir()
	oldStdout := os.Stdout
	stdout, err := ioutil.TempFile(d, "stdout")
	c.Assert(err, check.IsNil)
	defer func() {
		os.Stdout = oldStdout
		stdout.Close()
		os.Remove(stdout.Name())
	}()
	os.Stdout = stdout

	cli := snap.Client()
	chg, err := snap.Wait(cli, "x")
	c.Assert(chg, check.IsNil)
	c.Assert(err, check.NotNil)
	buf, err := ioutil.ReadFile(stdout.Name())
	c.Assert(err, check.IsNil)
	c.Check(string(buf), check.Matches, "(?ms).*Waiting for server to restart.*")
}