2015-07-02 11:43:07 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2015-12-21 17:55:23 -05:00
|
|
|
"encoding/json"
|
|
|
|
"io"
|
2015-07-02 11:43:07 -04:00
|
|
|
"net/http"
|
2015-12-21 17:55:23 -05:00
|
|
|
"net/url"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
2015-07-02 11:43:07 -04:00
|
|
|
"time"
|
|
|
|
|
2016-12-30 12:23:00 -05:00
|
|
|
"github.com/docker/docker/integration-cli/checker"
|
2016-12-30 04:49:36 -05:00
|
|
|
"github.com/docker/docker/integration-cli/request"
|
2015-12-21 17:55:23 -05:00
|
|
|
"github.com/docker/docker/pkg/jsonmessage"
|
2015-07-02 11:43:07 -04:00
|
|
|
"github.com/go-check/check"
|
|
|
|
)
|
|
|
|
|
[nit] integration-cli: obey Go's naming convention
No substantial code change.
- Api --> API
- Cli --> CLI
- Http, Https --> HTTP, HTTPS
- Id --> ID
- Uid,Gid,Pid --> UID,PID,PID
- Ipam --> IPAM
- Tls --> TLS (TestDaemonNoTlsCliTlsVerifyWithEnv --> TestDaemonTLSVerifyIssue13964)
Didn't touch in this commit:
- Git: because it is officially "Git": https://git-scm.com/
- Tar: because it is officially "Tar": https://www.gnu.org/software/tar/
- Cpu, Nat, Mac, Ipc, Shm: for keeping a consistency with existing production code (not changable, for compatibility)
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
2016-09-27 21:50:12 -04:00
|
|
|
func (s *DockerSuite) TestEventsAPIEmptyOutput(c *check.C) {
|
2015-07-02 11:43:07 -04:00
|
|
|
type apiResp struct {
|
|
|
|
resp *http.Response
|
|
|
|
err error
|
|
|
|
}
|
|
|
|
chResp := make(chan *apiResp)
|
|
|
|
go func() {
|
2017-03-06 10:35:27 -05:00
|
|
|
resp, body, err := request.Get("/events")
|
2015-07-02 11:43:07 -04:00
|
|
|
body.Close()
|
|
|
|
chResp <- &apiResp{resp, err}
|
|
|
|
}()
|
|
|
|
|
|
|
|
select {
|
|
|
|
case r := <-chResp:
|
2015-10-15 12:40:36 -04:00
|
|
|
c.Assert(r.err, checker.IsNil)
|
|
|
|
c.Assert(r.resp.StatusCode, checker.Equals, http.StatusOK)
|
2015-07-02 11:43:07 -04:00
|
|
|
case <-time.After(3 * time.Second):
|
|
|
|
c.Fatal("timeout waiting for events api to respond, should have responded immediately")
|
|
|
|
}
|
|
|
|
}
|
2015-12-21 17:55:23 -05:00
|
|
|
|
[nit] integration-cli: obey Go's naming convention
No substantial code change.
- Api --> API
- Cli --> CLI
- Http, Https --> HTTP, HTTPS
- Id --> ID
- Uid,Gid,Pid --> UID,PID,PID
- Ipam --> IPAM
- Tls --> TLS (TestDaemonNoTlsCliTlsVerifyWithEnv --> TestDaemonTLSVerifyIssue13964)
Didn't touch in this commit:
- Git: because it is officially "Git": https://git-scm.com/
- Tar: because it is officially "Tar": https://www.gnu.org/software/tar/
- Cpu, Nat, Mac, Ipc, Shm: for keeping a consistency with existing production code (not changable, for compatibility)
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
2016-09-27 21:50:12 -04:00
|
|
|
func (s *DockerSuite) TestEventsAPIBackwardsCompatible(c *check.C) {
|
2015-12-21 17:55:23 -05:00
|
|
|
since := daemonTime(c).Unix()
|
|
|
|
ts := strconv.FormatInt(since, 10)
|
|
|
|
|
2016-02-24 13:17:25 -05:00
|
|
|
out, _ := runSleepingContainer(c, "--name=foo", "-d")
|
2015-12-21 17:55:23 -05:00
|
|
|
containerID := strings.TrimSpace(out)
|
|
|
|
c.Assert(waitRun(containerID), checker.IsNil)
|
|
|
|
|
|
|
|
q := url.Values{}
|
|
|
|
q.Set("since", ts)
|
|
|
|
|
2017-03-06 10:35:27 -05:00
|
|
|
_, body, err := request.Get("/events?" + q.Encode())
|
2015-12-21 17:55:23 -05:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
defer body.Close()
|
|
|
|
|
|
|
|
dec := json.NewDecoder(body)
|
|
|
|
var containerCreateEvent *jsonmessage.JSONMessage
|
|
|
|
for {
|
|
|
|
var event jsonmessage.JSONMessage
|
|
|
|
if err := dec.Decode(&event); err != nil {
|
|
|
|
if err == io.EOF {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
c.Fatal(err)
|
|
|
|
}
|
|
|
|
if event.Status == "create" && event.ID == containerID {
|
|
|
|
containerCreateEvent = &event
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
c.Assert(containerCreateEvent, checker.Not(checker.IsNil))
|
|
|
|
c.Assert(containerCreateEvent.Status, checker.Equals, "create")
|
|
|
|
c.Assert(containerCreateEvent.ID, checker.Equals, containerID)
|
|
|
|
c.Assert(containerCreateEvent.From, checker.Equals, "busybox")
|
|
|
|
}
|