Use checker on integration test when possible
Signed-off-by: Hu Keping <hukeping@huawei.com>
This commit is contained in:
parent
4786ac1ffe
commit
710817a71b
|
@ -4,6 +4,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/docker/docker/pkg/integration/checker"
|
||||||
"github.com/go-check/check"
|
"github.com/go-check/check"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -42,7 +43,5 @@ func (s *DockerSuite) TestResizeApiResponseWhenContainerNotStarted(c *check.C) {
|
||||||
c.Assert(status, check.Equals, http.StatusInternalServerError)
|
c.Assert(status, check.Equals, http.StatusInternalServerError)
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, check.IsNil)
|
||||||
|
|
||||||
if !strings.Contains(string(body), "Cannot resize container") && !strings.Contains(string(body), cleanedContainerID) {
|
c.Assert(string(body), checker.Contains, "is not running", check.Commentf("resize should fail with message 'Container is not running'"))
|
||||||
c.Fatalf("resize should fail with message 'Cannot resize container' but instead received %s", string(body))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
|
"github.com/docker/docker/pkg/integration/checker"
|
||||||
"github.com/go-check/check"
|
"github.com/go-check/check"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -19,25 +20,24 @@ func (s *DockerSuite) TestApiStatsNoStreamGetCpu(c *check.C) {
|
||||||
out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "while true;do echo 'Hello'; usleep 100000; done")
|
out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "while true;do echo 'Hello'; usleep 100000; done")
|
||||||
|
|
||||||
id := strings.TrimSpace(out)
|
id := strings.TrimSpace(out)
|
||||||
c.Assert(waitRun(id), check.IsNil)
|
c.Assert(waitRun(id), checker.IsNil)
|
||||||
|
|
||||||
resp, body, err := sockRequestRaw("GET", fmt.Sprintf("/containers/%s/stats?stream=false", id), nil, "")
|
resp, body, err := sockRequestRaw("GET", fmt.Sprintf("/containers/%s/stats?stream=false", id), nil, "")
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
c.Assert(resp.ContentLength > 0, check.Equals, true, check.Commentf("should not use chunked encoding"))
|
c.Assert(resp.ContentLength, checker.GreaterThan, int64(0), check.Commentf("should not use chunked encoding"))
|
||||||
c.Assert(resp.Header.Get("Content-Type"), check.Equals, "application/json")
|
c.Assert(resp.Header.Get("Content-Type"), checker.Equals, "application/json")
|
||||||
|
|
||||||
var v *types.Stats
|
var v *types.Stats
|
||||||
err = json.NewDecoder(body).Decode(&v)
|
err = json.NewDecoder(body).Decode(&v)
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
body.Close()
|
body.Close()
|
||||||
|
|
||||||
var cpuPercent = 0.0
|
var cpuPercent = 0.0
|
||||||
cpuDelta := float64(v.CPUStats.CPUUsage.TotalUsage - v.PreCPUStats.CPUUsage.TotalUsage)
|
cpuDelta := float64(v.CPUStats.CPUUsage.TotalUsage - v.PreCPUStats.CPUUsage.TotalUsage)
|
||||||
systemDelta := float64(v.CPUStats.SystemUsage - v.PreCPUStats.SystemUsage)
|
systemDelta := float64(v.CPUStats.SystemUsage - v.PreCPUStats.SystemUsage)
|
||||||
cpuPercent = (cpuDelta / systemDelta) * float64(len(v.CPUStats.CPUUsage.PercpuUsage)) * 100.0
|
cpuPercent = (cpuDelta / systemDelta) * float64(len(v.CPUStats.CPUUsage.PercpuUsage)) * 100.0
|
||||||
if cpuPercent == 0 {
|
|
||||||
c.Fatalf("docker stats with no-stream get cpu usage failed: was %v", cpuPercent)
|
c.Assert(cpuPercent, check.Not(checker.Equals), 0.0, check.Commentf("docker stats with no-stream get cpu usage failed: was %v", cpuPercent))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerSuite) TestApiStatsStoppedContainerInGoroutines(c *check.C) {
|
func (s *DockerSuite) TestApiStatsStoppedContainerInGoroutines(c *check.C) {
|
||||||
|
@ -47,10 +47,10 @@ func (s *DockerSuite) TestApiStatsStoppedContainerInGoroutines(c *check.C) {
|
||||||
|
|
||||||
getGoRoutines := func() int {
|
getGoRoutines := func() int {
|
||||||
_, body, err := sockRequestRaw("GET", fmt.Sprintf("/info"), nil, "")
|
_, body, err := sockRequestRaw("GET", fmt.Sprintf("/info"), nil, "")
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
info := types.Info{}
|
info := types.Info{}
|
||||||
err = json.NewDecoder(body).Decode(&info)
|
err = json.NewDecoder(body).Decode(&info)
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
body.Close()
|
body.Close()
|
||||||
return info.NGoroutines
|
return info.NGoroutines
|
||||||
}
|
}
|
||||||
|
@ -58,14 +58,14 @@ func (s *DockerSuite) TestApiStatsStoppedContainerInGoroutines(c *check.C) {
|
||||||
// When the HTTP connection is closed, the number of goroutines should not increase.
|
// When the HTTP connection is closed, the number of goroutines should not increase.
|
||||||
routines := getGoRoutines()
|
routines := getGoRoutines()
|
||||||
_, body, err := sockRequestRaw("GET", fmt.Sprintf("/containers/%s/stats", id), nil, "")
|
_, body, err := sockRequestRaw("GET", fmt.Sprintf("/containers/%s/stats", id), nil, "")
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
body.Close()
|
body.Close()
|
||||||
|
|
||||||
t := time.After(30 * time.Second)
|
t := time.After(30 * time.Second)
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-t:
|
case <-t:
|
||||||
c.Assert(getGoRoutines() <= routines, check.Equals, true)
|
c.Assert(getGoRoutines(), checker.LessOrEqualThan, routines)
|
||||||
return
|
return
|
||||||
default:
|
default:
|
||||||
if n := getGoRoutines(); n <= routines {
|
if n := getGoRoutines(); n <= routines {
|
||||||
|
@ -82,7 +82,7 @@ func (s *DockerSuite) TestApiStatsNetworkStats(c *check.C) {
|
||||||
// Run container for 30 secs
|
// Run container for 30 secs
|
||||||
out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
|
out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
|
||||||
id := strings.TrimSpace(out)
|
id := strings.TrimSpace(out)
|
||||||
c.Assert(waitRun(id), check.IsNil)
|
c.Assert(waitRun(id), checker.IsNil)
|
||||||
|
|
||||||
// Retrieve the container address
|
// Retrieve the container address
|
||||||
contIP := findContainerIP(c, id)
|
contIP := findContainerIP(c, id)
|
||||||
|
@ -106,7 +106,7 @@ func (s *DockerSuite) TestApiStatsNetworkStats(c *check.C) {
|
||||||
}
|
}
|
||||||
pingout, err := exec.Command("ping", contIP, countParam, strconv.Itoa(numPings)).Output()
|
pingout, err := exec.Command("ping", contIP, countParam, strconv.Itoa(numPings)).Output()
|
||||||
pingouts := string(pingout[:])
|
pingouts := string(pingout[:])
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
nwStatsPost := getNetworkStats(c, id)
|
nwStatsPost := getNetworkStats(c, id)
|
||||||
for _, v := range nwStatsPost {
|
for _, v := range nwStatsPost {
|
||||||
postRxPackets += v.RxPackets
|
postRxPackets += v.RxPackets
|
||||||
|
@ -116,9 +116,9 @@ func (s *DockerSuite) TestApiStatsNetworkStats(c *check.C) {
|
||||||
// Verify the stats contain at least the expected number of packets (account for ARP)
|
// Verify the stats contain at least the expected number of packets (account for ARP)
|
||||||
expRxPkts := 1 + preRxPackets + uint64(numPings)
|
expRxPkts := 1 + preRxPackets + uint64(numPings)
|
||||||
expTxPkts := 1 + preTxPackets + uint64(numPings)
|
expTxPkts := 1 + preTxPackets + uint64(numPings)
|
||||||
c.Assert(postTxPackets >= expTxPkts, check.Equals, true,
|
c.Assert(postTxPackets, checker.GreaterOrEqualThan, expTxPkts,
|
||||||
check.Commentf("Reported less TxPackets than expected. Expected >= %d. Found %d. %s", expTxPkts, postTxPackets, pingouts))
|
check.Commentf("Reported less TxPackets than expected. Expected >= %d. Found %d. %s", expTxPkts, postTxPackets, pingouts))
|
||||||
c.Assert(postRxPackets >= expRxPkts, check.Equals, true,
|
c.Assert(postRxPackets, checker.GreaterOrEqualThan, expRxPkts,
|
||||||
check.Commentf("Reported less Txbytes than expected. Expected >= %d. Found %d. %s", expRxPkts, postRxPackets, pingouts))
|
check.Commentf("Reported less Txbytes than expected. Expected >= %d. Found %d. %s", expRxPkts, postRxPackets, pingouts))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,10 +126,10 @@ func getNetworkStats(c *check.C, id string) map[string]types.NetworkStats {
|
||||||
var st *types.StatsJSON
|
var st *types.StatsJSON
|
||||||
|
|
||||||
_, body, err := sockRequestRaw("GET", fmt.Sprintf("/containers/%s/stats?stream=false", id), nil, "")
|
_, body, err := sockRequestRaw("GET", fmt.Sprintf("/containers/%s/stats?stream=false", id), nil, "")
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
|
|
||||||
err = json.NewDecoder(body).Decode(&st)
|
err = json.NewDecoder(body).Decode(&st)
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
body.Close()
|
body.Close()
|
||||||
|
|
||||||
return st.Networks
|
return st.Networks
|
||||||
|
@ -139,10 +139,10 @@ func (s *DockerSuite) TestApiStatsContainerNotFound(c *check.C) {
|
||||||
testRequires(c, DaemonIsLinux)
|
testRequires(c, DaemonIsLinux)
|
||||||
|
|
||||||
status, _, err := sockRequest("GET", "/containers/nonexistent/stats", nil)
|
status, _, err := sockRequest("GET", "/containers/nonexistent/stats", nil)
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
c.Assert(status, check.Equals, http.StatusNotFound)
|
c.Assert(status, checker.Equals, http.StatusNotFound)
|
||||||
|
|
||||||
status, _, err = sockRequest("GET", "/containers/nonexistent/stats?stream=0", nil)
|
status, _, err = sockRequest("GET", "/containers/nonexistent/stats?stream=0", nil)
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
c.Assert(status, check.Equals, http.StatusNotFound)
|
c.Assert(status, checker.Equals, http.StatusNotFound)
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,19 +8,20 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/docker/docker/api"
|
"github.com/docker/docker/api"
|
||||||
|
"github.com/docker/docker/pkg/integration/checker"
|
||||||
"github.com/go-check/check"
|
"github.com/go-check/check"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *DockerSuite) TestApiOptionsRoute(c *check.C) {
|
func (s *DockerSuite) TestApiOptionsRoute(c *check.C) {
|
||||||
status, _, err := sockRequest("OPTIONS", "/", nil)
|
status, _, err := sockRequest("OPTIONS", "/", nil)
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
c.Assert(status, check.Equals, http.StatusOK)
|
c.Assert(status, checker.Equals, http.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerSuite) TestApiGetEnabledCors(c *check.C) {
|
func (s *DockerSuite) TestApiGetEnabledCors(c *check.C) {
|
||||||
res, body, err := sockRequestRaw("GET", "/version", nil, "")
|
res, body, err := sockRequestRaw("GET", "/version", nil, "")
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
c.Assert(res.StatusCode, check.Equals, http.StatusOK)
|
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
|
||||||
body.Close()
|
body.Close()
|
||||||
// TODO: @runcom incomplete tests, why old integration tests had this headers
|
// TODO: @runcom incomplete tests, why old integration tests had this headers
|
||||||
// and here none of the headers below are in the response?
|
// and here none of the headers below are in the response?
|
||||||
|
@ -31,43 +32,43 @@ func (s *DockerSuite) TestApiGetEnabledCors(c *check.C) {
|
||||||
|
|
||||||
func (s *DockerSuite) TestApiVersionStatusCode(c *check.C) {
|
func (s *DockerSuite) TestApiVersionStatusCode(c *check.C) {
|
||||||
conn, err := sockConn(time.Duration(10 * time.Second))
|
conn, err := sockConn(time.Duration(10 * time.Second))
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
|
|
||||||
client := httputil.NewClientConn(conn, nil)
|
client := httputil.NewClientConn(conn, nil)
|
||||||
defer client.Close()
|
defer client.Close()
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", "/v999.0/version", nil)
|
req, err := http.NewRequest("GET", "/v999.0/version", nil)
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
req.Header.Set("User-Agent", "Docker-Client/999.0 (os)")
|
req.Header.Set("User-Agent", "Docker-Client/999.0 (os)")
|
||||||
|
|
||||||
res, err := client.Do(req)
|
res, err := client.Do(req)
|
||||||
c.Assert(res.StatusCode, check.Equals, http.StatusBadRequest)
|
c.Assert(res.StatusCode, checker.Equals, http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerSuite) TestApiClientVersionNewerThanServer(c *check.C) {
|
func (s *DockerSuite) TestApiClientVersionNewerThanServer(c *check.C) {
|
||||||
v := strings.Split(string(api.Version), ".")
|
v := strings.Split(string(api.Version), ".")
|
||||||
vMinInt, err := strconv.Atoi(v[1])
|
vMinInt, err := strconv.Atoi(v[1])
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
vMinInt++
|
vMinInt++
|
||||||
v[1] = strconv.Itoa(vMinInt)
|
v[1] = strconv.Itoa(vMinInt)
|
||||||
version := strings.Join(v, ".")
|
version := strings.Join(v, ".")
|
||||||
|
|
||||||
status, body, err := sockRequest("GET", "/v"+version+"/version", nil)
|
status, body, err := sockRequest("GET", "/v"+version+"/version", nil)
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
c.Assert(status, check.Equals, http.StatusBadRequest)
|
c.Assert(status, checker.Equals, http.StatusBadRequest)
|
||||||
c.Assert(len(string(body)), check.Not(check.Equals), 0) // Expected not empty body
|
c.Assert(len(string(body)), check.Not(checker.Equals), 0) // Expected not empty body
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerSuite) TestApiClientVersionOldNotSupported(c *check.C) {
|
func (s *DockerSuite) TestApiClientVersionOldNotSupported(c *check.C) {
|
||||||
v := strings.Split(string(api.MinVersion), ".")
|
v := strings.Split(string(api.MinVersion), ".")
|
||||||
vMinInt, err := strconv.Atoi(v[1])
|
vMinInt, err := strconv.Atoi(v[1])
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
vMinInt--
|
vMinInt--
|
||||||
v[1] = strconv.Itoa(vMinInt)
|
v[1] = strconv.Itoa(vMinInt)
|
||||||
version := strings.Join(v, ".")
|
version := strings.Join(v, ".")
|
||||||
|
|
||||||
status, body, err := sockRequest("GET", "/v"+version+"/version", nil)
|
status, body, err := sockRequest("GET", "/v"+version+"/version", nil)
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
c.Assert(status, check.Equals, http.StatusBadRequest)
|
c.Assert(status, checker.Equals, http.StatusBadRequest)
|
||||||
c.Assert(len(string(body)), check.Not(check.Equals), 0) // Expected not empty body
|
c.Assert(len(string(body)), checker.Not(check.Equals), 0) // Expected not empty body
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"path"
|
"path"
|
||||||
|
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
|
"github.com/docker/docker/pkg/integration/checker"
|
||||||
"github.com/go-check/check"
|
"github.com/go-check/check"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -14,13 +15,13 @@ func (s *DockerSuite) TestVolumesApiList(c *check.C) {
|
||||||
dockerCmd(c, "run", "-d", "-v", "/foo", "busybox")
|
dockerCmd(c, "run", "-d", "-v", "/foo", "busybox")
|
||||||
|
|
||||||
status, b, err := sockRequest("GET", "/volumes", nil)
|
status, b, err := sockRequest("GET", "/volumes", nil)
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
c.Assert(status, check.Equals, http.StatusOK)
|
c.Assert(status, checker.Equals, http.StatusOK)
|
||||||
|
|
||||||
var volumes types.VolumesListResponse
|
var volumes types.VolumesListResponse
|
||||||
c.Assert(json.Unmarshal(b, &volumes), check.IsNil)
|
c.Assert(json.Unmarshal(b, &volumes), checker.IsNil)
|
||||||
|
|
||||||
c.Assert(len(volumes.Volumes), check.Equals, 1, check.Commentf("\n%v", volumes.Volumes))
|
c.Assert(len(volumes.Volumes), checker.Equals, 1, check.Commentf("\n%v", volumes.Volumes))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerSuite) TestVolumesApiCreate(c *check.C) {
|
func (s *DockerSuite) TestVolumesApiCreate(c *check.C) {
|
||||||
|
@ -34,9 +35,9 @@ func (s *DockerSuite) TestVolumesApiCreate(c *check.C) {
|
||||||
|
|
||||||
var vol types.Volume
|
var vol types.Volume
|
||||||
err = json.Unmarshal(b, &vol)
|
err = json.Unmarshal(b, &vol)
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
|
|
||||||
c.Assert(path.Base(path.Dir(vol.Mountpoint)), check.Equals, config.Name)
|
c.Assert(path.Base(path.Dir(vol.Mountpoint)), checker.Equals, config.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerSuite) TestVolumesApiRemove(c *check.C) {
|
func (s *DockerSuite) TestVolumesApiRemove(c *check.C) {
|
||||||
|
@ -44,22 +45,22 @@ func (s *DockerSuite) TestVolumesApiRemove(c *check.C) {
|
||||||
dockerCmd(c, "run", "-d", "-v", "/foo", "--name=test", "busybox")
|
dockerCmd(c, "run", "-d", "-v", "/foo", "--name=test", "busybox")
|
||||||
|
|
||||||
status, b, err := sockRequest("GET", "/volumes", nil)
|
status, b, err := sockRequest("GET", "/volumes", nil)
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
c.Assert(status, check.Equals, http.StatusOK)
|
c.Assert(status, checker.Equals, http.StatusOK)
|
||||||
|
|
||||||
var volumes types.VolumesListResponse
|
var volumes types.VolumesListResponse
|
||||||
c.Assert(json.Unmarshal(b, &volumes), check.IsNil)
|
c.Assert(json.Unmarshal(b, &volumes), checker.IsNil)
|
||||||
c.Assert(len(volumes.Volumes), check.Equals, 1, check.Commentf("\n%v", volumes.Volumes))
|
c.Assert(len(volumes.Volumes), checker.Equals, 1, check.Commentf("\n%v", volumes.Volumes))
|
||||||
|
|
||||||
v := volumes.Volumes[0]
|
v := volumes.Volumes[0]
|
||||||
status, _, err = sockRequest("DELETE", "/volumes/"+v.Name, nil)
|
status, _, err = sockRequest("DELETE", "/volumes/"+v.Name, nil)
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
c.Assert(status, check.Equals, http.StatusConflict, check.Commentf("Should not be able to remove a volume that is in use"))
|
c.Assert(status, checker.Equals, http.StatusConflict, check.Commentf("Should not be able to remove a volume that is in use"))
|
||||||
|
|
||||||
dockerCmd(c, "rm", "-f", "test")
|
dockerCmd(c, "rm", "-f", "test")
|
||||||
status, data, err := sockRequest("DELETE", "/volumes/"+v.Name, nil)
|
status, data, err := sockRequest("DELETE", "/volumes/"+v.Name, nil)
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
c.Assert(status, check.Equals, http.StatusNoContent, check.Commentf(string(data)))
|
c.Assert(status, checker.Equals, http.StatusNoContent, check.Commentf(string(data)))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,17 +74,17 @@ func (s *DockerSuite) TestVolumesApiInspect(c *check.C) {
|
||||||
c.Assert(status, check.Equals, http.StatusCreated, check.Commentf(string(b)))
|
c.Assert(status, check.Equals, http.StatusCreated, check.Commentf(string(b)))
|
||||||
|
|
||||||
status, b, err = sockRequest("GET", "/volumes", nil)
|
status, b, err = sockRequest("GET", "/volumes", nil)
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
c.Assert(status, check.Equals, http.StatusOK, check.Commentf(string(b)))
|
c.Assert(status, checker.Equals, http.StatusOK, check.Commentf(string(b)))
|
||||||
|
|
||||||
var volumes types.VolumesListResponse
|
var volumes types.VolumesListResponse
|
||||||
c.Assert(json.Unmarshal(b, &volumes), check.IsNil)
|
c.Assert(json.Unmarshal(b, &volumes), checker.IsNil)
|
||||||
c.Assert(len(volumes.Volumes), check.Equals, 1, check.Commentf("\n%v", volumes.Volumes))
|
c.Assert(len(volumes.Volumes), checker.Equals, 1, check.Commentf("\n%v", volumes.Volumes))
|
||||||
|
|
||||||
var vol types.Volume
|
var vol types.Volume
|
||||||
status, b, err = sockRequest("GET", "/volumes/"+config.Name, nil)
|
status, b, err = sockRequest("GET", "/volumes/"+config.Name, nil)
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
c.Assert(status, check.Equals, http.StatusOK, check.Commentf(string(b)))
|
c.Assert(status, checker.Equals, http.StatusOK, check.Commentf(string(b)))
|
||||||
c.Assert(json.Unmarshal(b, &vol), check.IsNil)
|
c.Assert(json.Unmarshal(b, &vol), checker.IsNil)
|
||||||
c.Assert(vol.Name, check.Equals, config.Name)
|
c.Assert(vol.Name, checker.Equals, config.Name)
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/docker/docker/pkg/integration/checker"
|
||||||
"github.com/go-check/check"
|
"github.com/go-check/check"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -23,32 +24,26 @@ func (s *DockerRegistrySuite) TestPushBusyboxImage(c *check.C) {
|
||||||
|
|
||||||
// pushing an image without a prefix should throw an error
|
// pushing an image without a prefix should throw an error
|
||||||
func (s *DockerSuite) TestPushUnprefixedRepo(c *check.C) {
|
func (s *DockerSuite) TestPushUnprefixedRepo(c *check.C) {
|
||||||
if out, _, err := dockerCmdWithError("push", "busybox"); err == nil {
|
out, _, err := dockerCmdWithError("push", "busybox")
|
||||||
c.Fatalf("pushing an unprefixed repo didn't result in a non-zero exit status: %s", out)
|
c.Assert(err, check.NotNil, check.Commentf("pushing an unprefixed repo didn't result in a non-zero exit status: %s", out))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerRegistrySuite) TestPushUntagged(c *check.C) {
|
func (s *DockerRegistrySuite) TestPushUntagged(c *check.C) {
|
||||||
repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
|
repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
|
||||||
|
|
||||||
expected := "Repository does not exist"
|
expected := "Repository does not exist"
|
||||||
if out, _, err := dockerCmdWithError("push", repoName); err == nil {
|
|
||||||
c.Fatalf("pushing the image to the private registry should have failed: output %q", out)
|
out, _, err := dockerCmdWithError("push", repoName)
|
||||||
} else if !strings.Contains(out, expected) {
|
c.Assert(err, check.NotNil, check.Commentf("pushing the image to the private registry should have failed: output %q", out))
|
||||||
c.Fatalf("pushing the image failed with an unexpected message: expected %q, got %q", expected, out)
|
c.Assert(out, checker.Contains, expected, check.Commentf("pushing the image failed"))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerRegistrySuite) TestPushBadTag(c *check.C) {
|
func (s *DockerRegistrySuite) TestPushBadTag(c *check.C) {
|
||||||
repoName := fmt.Sprintf("%v/dockercli/busybox:latest", privateRegistryURL)
|
repoName := fmt.Sprintf("%v/dockercli/busybox:latest", privateRegistryURL)
|
||||||
|
|
||||||
expected := "does not exist"
|
expected := "does not exist"
|
||||||
|
|
||||||
if out, _, err := dockerCmdWithError("push", repoName); err == nil {
|
out, _, err := dockerCmdWithError("push", repoName)
|
||||||
c.Fatalf("pushing the image to the private registry should have failed: output %q", out)
|
c.Assert(err, check.NotNil, check.Commentf("pushing the image to the private registry should have failed: output %q", out))
|
||||||
} else if !strings.Contains(out, expected) {
|
c.Assert(out, checker.Contains, expected, check.Commentf("pushing the image failed"))
|
||||||
c.Fatalf("pushing the image failed with an unexpected message: expected %q, got %q", expected, out)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerRegistrySuite) TestPushMultipleTags(c *check.C) {
|
func (s *DockerRegistrySuite) TestPushMultipleTags(c *check.C) {
|
||||||
|
@ -64,9 +59,7 @@ func (s *DockerRegistrySuite) TestPushMultipleTags(c *check.C) {
|
||||||
|
|
||||||
// Ensure layer list is equivalent for repoTag1 and repoTag2
|
// Ensure layer list is equivalent for repoTag1 and repoTag2
|
||||||
out1, _ := dockerCmd(c, "pull", repoTag1)
|
out1, _ := dockerCmd(c, "pull", repoTag1)
|
||||||
if strings.Contains(out1, "Tag t1 not found") {
|
|
||||||
c.Fatalf("Unable to pull pushed image: %s", out1)
|
|
||||||
}
|
|
||||||
imageAlreadyExists := ": Image already exists"
|
imageAlreadyExists := ": Image already exists"
|
||||||
var out1Lines []string
|
var out1Lines []string
|
||||||
for _, outputLine := range strings.Split(out1, "\n") {
|
for _, outputLine := range strings.Split(out1, "\n") {
|
||||||
|
@ -76,54 +69,40 @@ func (s *DockerRegistrySuite) TestPushMultipleTags(c *check.C) {
|
||||||
}
|
}
|
||||||
|
|
||||||
out2, _ := dockerCmd(c, "pull", repoTag2)
|
out2, _ := dockerCmd(c, "pull", repoTag2)
|
||||||
if strings.Contains(out2, "Tag t2 not found") {
|
|
||||||
c.Fatalf("Unable to pull pushed image: %s", out1)
|
|
||||||
}
|
|
||||||
var out2Lines []string
|
var out2Lines []string
|
||||||
for _, outputLine := range strings.Split(out2, "\n") {
|
for _, outputLine := range strings.Split(out2, "\n") {
|
||||||
if strings.Contains(outputLine, imageAlreadyExists) {
|
if strings.Contains(outputLine, imageAlreadyExists) {
|
||||||
out1Lines = append(out1Lines, outputLine)
|
out1Lines = append(out1Lines, outputLine)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
c.Assert(out2Lines, checker.HasLen, len(out1Lines))
|
||||||
if len(out1Lines) != len(out2Lines) {
|
|
||||||
c.Fatalf("Mismatched output length:\n%s\n%s", out1, out2)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := range out1Lines {
|
for i := range out1Lines {
|
||||||
if out1Lines[i] != out2Lines[i] {
|
c.Assert(out1Lines[i], checker.Equals, out2Lines[i])
|
||||||
c.Fatalf("Mismatched output line:\n%s\n%s", out1Lines[i], out2Lines[i])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerRegistrySuite) TestPushEmptyLayer(c *check.C) {
|
func (s *DockerRegistrySuite) TestPushEmptyLayer(c *check.C) {
|
||||||
repoName := fmt.Sprintf("%v/dockercli/emptylayer", privateRegistryURL)
|
repoName := fmt.Sprintf("%v/dockercli/emptylayer", privateRegistryURL)
|
||||||
emptyTarball, err := ioutil.TempFile("", "empty_tarball")
|
emptyTarball, err := ioutil.TempFile("", "empty_tarball")
|
||||||
if err != nil {
|
c.Assert(err, check.IsNil, check.Commentf("Unable to create test file"))
|
||||||
c.Fatalf("Unable to create test file: %v", err)
|
|
||||||
}
|
|
||||||
tw := tar.NewWriter(emptyTarball)
|
tw := tar.NewWriter(emptyTarball)
|
||||||
err = tw.Close()
|
err = tw.Close()
|
||||||
if err != nil {
|
c.Assert(err, check.IsNil, check.Commentf("Error creating empty tarball"))
|
||||||
c.Fatalf("Error creating empty tarball: %v", err)
|
|
||||||
}
|
|
||||||
freader, err := os.Open(emptyTarball.Name())
|
freader, err := os.Open(emptyTarball.Name())
|
||||||
if err != nil {
|
c.Assert(err, check.IsNil, check.Commentf("Could not open test tarball"))
|
||||||
c.Fatalf("Could not open test tarball: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
importCmd := exec.Command(dockerBinary, "import", "-", repoName)
|
importCmd := exec.Command(dockerBinary, "import", "-", repoName)
|
||||||
importCmd.Stdin = freader
|
importCmd.Stdin = freader
|
||||||
out, _, err := runCommandWithOutput(importCmd)
|
out, _, err := runCommandWithOutput(importCmd)
|
||||||
if err != nil {
|
c.Assert(err, check.IsNil, check.Commentf("import failed: %q", out))
|
||||||
c.Errorf("import failed with errors: %v, output: %q", err, out)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now verify we can push it
|
// Now verify we can push it
|
||||||
if out, _, err := dockerCmdWithError("push", repoName); err != nil {
|
out, _, err = dockerCmdWithError("push", repoName)
|
||||||
c.Fatalf("pushing the image to the private registry has failed: %s, %v", out, err)
|
c.Assert(err, check.IsNil, check.Commentf("pushing the image to the private registry has failed: %s", out))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerTrustSuite) TestTrustedPush(c *check.C) {
|
func (s *DockerTrustSuite) TestTrustedPush(c *check.C) {
|
||||||
|
@ -134,12 +113,8 @@ func (s *DockerTrustSuite) TestTrustedPush(c *check.C) {
|
||||||
pushCmd := exec.Command(dockerBinary, "push", repoName)
|
pushCmd := exec.Command(dockerBinary, "push", repoName)
|
||||||
s.trustedCmd(pushCmd)
|
s.trustedCmd(pushCmd)
|
||||||
out, _, err := runCommandWithOutput(pushCmd)
|
out, _, err := runCommandWithOutput(pushCmd)
|
||||||
if err != nil {
|
c.Assert(err, check.IsNil, check.Commentf("Error running trusted push: %s\n%s", err, out))
|
||||||
c.Fatalf("Error running trusted push: %s\n%s", err, out)
|
c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push"))
|
||||||
}
|
|
||||||
if !strings.Contains(string(out), "Signing and pushing trust metadata") {
|
|
||||||
c.Fatalf("Missing expected output on trusted push:\n%s", out)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerTrustSuite) TestTrustedPushWithEnvPasswords(c *check.C) {
|
func (s *DockerTrustSuite) TestTrustedPushWithEnvPasswords(c *check.C) {
|
||||||
|
@ -150,12 +125,8 @@ func (s *DockerTrustSuite) TestTrustedPushWithEnvPasswords(c *check.C) {
|
||||||
pushCmd := exec.Command(dockerBinary, "push", repoName)
|
pushCmd := exec.Command(dockerBinary, "push", repoName)
|
||||||
s.trustedCmdWithPassphrases(pushCmd, "12345678", "12345678")
|
s.trustedCmdWithPassphrases(pushCmd, "12345678", "12345678")
|
||||||
out, _, err := runCommandWithOutput(pushCmd)
|
out, _, err := runCommandWithOutput(pushCmd)
|
||||||
if err != nil {
|
c.Assert(err, check.IsNil, check.Commentf("Error running trusted push: %s\n%s", err, out))
|
||||||
c.Fatalf("Error running trusted push: %s\n%s", err, out)
|
c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push"))
|
||||||
}
|
|
||||||
if !strings.Contains(string(out), "Signing and pushing trust metadata") {
|
|
||||||
c.Fatalf("Missing expected output on trusted push:\n%s", out)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This test ensures backwards compatibility with old ENV variables. Should be
|
// This test ensures backwards compatibility with old ENV variables. Should be
|
||||||
|
@ -168,12 +139,8 @@ func (s *DockerTrustSuite) TestTrustedPushWithDeprecatedEnvPasswords(c *check.C)
|
||||||
pushCmd := exec.Command(dockerBinary, "push", repoName)
|
pushCmd := exec.Command(dockerBinary, "push", repoName)
|
||||||
s.trustedCmdWithDeprecatedEnvPassphrases(pushCmd, "12345678", "12345678")
|
s.trustedCmdWithDeprecatedEnvPassphrases(pushCmd, "12345678", "12345678")
|
||||||
out, _, err := runCommandWithOutput(pushCmd)
|
out, _, err := runCommandWithOutput(pushCmd)
|
||||||
if err != nil {
|
c.Assert(err, check.IsNil, check.Commentf("Error running trusted push: %s\n%s", err, out))
|
||||||
c.Fatalf("Error running trusted push: %s\n%s", err, out)
|
c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push"))
|
||||||
}
|
|
||||||
if !strings.Contains(string(out), "Signing and pushing trust metadata") {
|
|
||||||
c.Fatalf("Missing expected output on trusted push:\n%s", out)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerTrustSuite) TestTrustedPushWithFaillingServer(c *check.C) {
|
func (s *DockerTrustSuite) TestTrustedPushWithFaillingServer(c *check.C) {
|
||||||
|
@ -184,13 +151,8 @@ func (s *DockerTrustSuite) TestTrustedPushWithFaillingServer(c *check.C) {
|
||||||
pushCmd := exec.Command(dockerBinary, "push", repoName)
|
pushCmd := exec.Command(dockerBinary, "push", repoName)
|
||||||
s.trustedCmdWithServer(pushCmd, "https://example.com:81/")
|
s.trustedCmdWithServer(pushCmd, "https://example.com:81/")
|
||||||
out, _, err := runCommandWithOutput(pushCmd)
|
out, _, err := runCommandWithOutput(pushCmd)
|
||||||
if err == nil {
|
c.Assert(err, check.NotNil, check.Commentf("Missing error while running trusted push w/ no server"))
|
||||||
c.Fatalf("Missing error while running trusted push w/ no server")
|
c.Assert(out, checker.Contains, "error contacting notary server", check.Commentf("Missing expected output on trusted push"))
|
||||||
}
|
|
||||||
|
|
||||||
if !strings.Contains(string(out), "error contacting notary server") {
|
|
||||||
c.Fatalf("Missing expected output on trusted push:\n%s", out)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerTrustSuite) TestTrustedPushWithoutServerAndUntrusted(c *check.C) {
|
func (s *DockerTrustSuite) TestTrustedPushWithoutServerAndUntrusted(c *check.C) {
|
||||||
|
@ -201,13 +163,8 @@ func (s *DockerTrustSuite) TestTrustedPushWithoutServerAndUntrusted(c *check.C)
|
||||||
pushCmd := exec.Command(dockerBinary, "push", "--disable-content-trust", repoName)
|
pushCmd := exec.Command(dockerBinary, "push", "--disable-content-trust", repoName)
|
||||||
s.trustedCmdWithServer(pushCmd, "https://example.com/")
|
s.trustedCmdWithServer(pushCmd, "https://example.com/")
|
||||||
out, _, err := runCommandWithOutput(pushCmd)
|
out, _, err := runCommandWithOutput(pushCmd)
|
||||||
if err != nil {
|
c.Assert(err, check.IsNil, check.Commentf("trusted push with no server and --disable-content-trust failed: %s\n%s", err, out))
|
||||||
c.Fatalf("trusted push with no server and --disable-content-trust failed: %s\n%s", err, out)
|
c.Assert(out, check.Not(checker.Contains), "Error establishing connection to notary repository", check.Commentf("Missing expected output on trusted push with --disable-content-trust:"))
|
||||||
}
|
|
||||||
|
|
||||||
if strings.Contains(string(out), "Error establishing connection to notary repository") {
|
|
||||||
c.Fatalf("Missing expected output on trusted push with --disable-content-trust:\n%s", out)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerTrustSuite) TestTrustedPushWithExistingTag(c *check.C) {
|
func (s *DockerTrustSuite) TestTrustedPushWithExistingTag(c *check.C) {
|
||||||
|
@ -219,13 +176,8 @@ func (s *DockerTrustSuite) TestTrustedPushWithExistingTag(c *check.C) {
|
||||||
pushCmd := exec.Command(dockerBinary, "push", repoName)
|
pushCmd := exec.Command(dockerBinary, "push", repoName)
|
||||||
s.trustedCmd(pushCmd)
|
s.trustedCmd(pushCmd)
|
||||||
out, _, err := runCommandWithOutput(pushCmd)
|
out, _, err := runCommandWithOutput(pushCmd)
|
||||||
if err != nil {
|
c.Assert(err, check.IsNil, check.Commentf("trusted push failed: %s\n%s", err, out))
|
||||||
c.Fatalf("trusted push failed: %s\n%s", err, out)
|
c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push with existing tag"))
|
||||||
}
|
|
||||||
|
|
||||||
if !strings.Contains(string(out), "Signing and pushing trust metadata") {
|
|
||||||
c.Fatalf("Missing expected output on trusted push with existing tag:\n%s", out)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerTrustSuite) TestTrustedPushWithExistingSignedTag(c *check.C) {
|
func (s *DockerTrustSuite) TestTrustedPushWithExistingSignedTag(c *check.C) {
|
||||||
|
@ -237,25 +189,15 @@ func (s *DockerTrustSuite) TestTrustedPushWithExistingSignedTag(c *check.C) {
|
||||||
pushCmd := exec.Command(dockerBinary, "push", repoName)
|
pushCmd := exec.Command(dockerBinary, "push", repoName)
|
||||||
s.trustedCmd(pushCmd)
|
s.trustedCmd(pushCmd)
|
||||||
out, _, err := runCommandWithOutput(pushCmd)
|
out, _, err := runCommandWithOutput(pushCmd)
|
||||||
if err != nil {
|
c.Assert(err, check.IsNil, check.Commentf("trusted push failed: %s\n%s", err, out))
|
||||||
c.Fatalf("trusted push failed: %s\n%s", err, out)
|
c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push with existing tag"))
|
||||||
}
|
|
||||||
|
|
||||||
if !strings.Contains(string(out), "Signing and pushing trust metadata") {
|
|
||||||
c.Fatalf("Missing expected output on trusted push with existing tag:\n%s", out)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Do another trusted push
|
// Do another trusted push
|
||||||
pushCmd = exec.Command(dockerBinary, "push", repoName)
|
pushCmd = exec.Command(dockerBinary, "push", repoName)
|
||||||
s.trustedCmd(pushCmd)
|
s.trustedCmd(pushCmd)
|
||||||
out, _, err = runCommandWithOutput(pushCmd)
|
out, _, err = runCommandWithOutput(pushCmd)
|
||||||
if err != nil {
|
c.Assert(err, check.IsNil, check.Commentf("trusted push failed: %s\n%s", err, out))
|
||||||
c.Fatalf("trusted push failed: %s\n%s", err, out)
|
c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push with existing tag"))
|
||||||
}
|
|
||||||
|
|
||||||
if !strings.Contains(string(out), "Signing and pushing trust metadata") {
|
|
||||||
c.Fatalf("Missing expected output on trusted push with existing tag:\n%s", out)
|
|
||||||
}
|
|
||||||
|
|
||||||
dockerCmd(c, "rmi", repoName)
|
dockerCmd(c, "rmi", repoName)
|
||||||
|
|
||||||
|
@ -263,13 +205,9 @@ func (s *DockerTrustSuite) TestTrustedPushWithExistingSignedTag(c *check.C) {
|
||||||
pullCmd := exec.Command(dockerBinary, "pull", repoName)
|
pullCmd := exec.Command(dockerBinary, "pull", repoName)
|
||||||
s.trustedCmd(pullCmd)
|
s.trustedCmd(pullCmd)
|
||||||
out, _, err = runCommandWithOutput(pullCmd)
|
out, _, err = runCommandWithOutput(pullCmd)
|
||||||
if err != nil {
|
c.Assert(err, check.IsNil, check.Commentf("Error running trusted pull: %s\n%s", err, out))
|
||||||
c.Fatalf("Error running trusted pull: %s\n%s", err, out)
|
c.Assert(out, checker.Contains, "Status: Downloaded", check.Commentf("Missing expected output on trusted pull with --disable-content-trust"))
|
||||||
}
|
|
||||||
|
|
||||||
if !strings.Contains(string(out), "Status: Downloaded") {
|
|
||||||
c.Fatalf("Missing expected output on trusted pull with --disable-content-trust:\n%s", out)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerTrustSuite) TestTrustedPushWithIncorrectPassphraseForNonRoot(c *check.C) {
|
func (s *DockerTrustSuite) TestTrustedPushWithIncorrectPassphraseForNonRoot(c *check.C) {
|
||||||
|
@ -281,25 +219,15 @@ func (s *DockerTrustSuite) TestTrustedPushWithIncorrectPassphraseForNonRoot(c *c
|
||||||
pushCmd := exec.Command(dockerBinary, "push", repoName)
|
pushCmd := exec.Command(dockerBinary, "push", repoName)
|
||||||
s.trustedCmd(pushCmd)
|
s.trustedCmd(pushCmd)
|
||||||
out, _, err := runCommandWithOutput(pushCmd)
|
out, _, err := runCommandWithOutput(pushCmd)
|
||||||
if err != nil {
|
c.Assert(err, check.IsNil, check.Commentf("trusted push failed: %s\n%s", err, out))
|
||||||
c.Fatalf("trusted push failed: %s\n%s", err, out)
|
c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push:\n%s", out))
|
||||||
}
|
|
||||||
|
|
||||||
if !strings.Contains(string(out), "Signing and pushing trust metadata") {
|
|
||||||
c.Fatalf("Missing expected output on trusted push:\n%s", out)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Push with wrong passphrases
|
// Push with wrong passphrases
|
||||||
pushCmd = exec.Command(dockerBinary, "push", repoName)
|
pushCmd = exec.Command(dockerBinary, "push", repoName)
|
||||||
s.trustedCmdWithPassphrases(pushCmd, "12345678", "87654321")
|
s.trustedCmdWithPassphrases(pushCmd, "12345678", "87654321")
|
||||||
out, _, err = runCommandWithOutput(pushCmd)
|
out, _, err = runCommandWithOutput(pushCmd)
|
||||||
if err == nil {
|
c.Assert(err, check.NotNil, check.Commentf("Error missing from trusted push with short targets passphrase: \n%s", out))
|
||||||
c.Fatalf("Error missing from trusted push with short targets passphrase: \n%s", out)
|
c.Assert(out, checker.Contains, "password invalid, operation has failed", check.Commentf("Missing expected output on trusted push with short targets/snapsnot passphrase"))
|
||||||
}
|
|
||||||
|
|
||||||
if !strings.Contains(string(out), "password invalid, operation has failed") {
|
|
||||||
c.Fatalf("Missing expected output on trusted push with short targets/snapsnot passphrase:\n%s", out)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This test ensures backwards compatibility with old ENV variables. Should be
|
// This test ensures backwards compatibility with old ENV variables. Should be
|
||||||
|
@ -313,25 +241,15 @@ func (s *DockerTrustSuite) TestTrustedPushWithIncorrectDeprecatedPassphraseForNo
|
||||||
pushCmd := exec.Command(dockerBinary, "push", repoName)
|
pushCmd := exec.Command(dockerBinary, "push", repoName)
|
||||||
s.trustedCmd(pushCmd)
|
s.trustedCmd(pushCmd)
|
||||||
out, _, err := runCommandWithOutput(pushCmd)
|
out, _, err := runCommandWithOutput(pushCmd)
|
||||||
if err != nil {
|
c.Assert(err, check.IsNil, check.Commentf("trusted push failed: %s\n%s", err, out))
|
||||||
c.Fatalf("trusted push failed: %s\n%s", err, out)
|
c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push"))
|
||||||
}
|
|
||||||
|
|
||||||
if !strings.Contains(string(out), "Signing and pushing trust metadata") {
|
|
||||||
c.Fatalf("Missing expected output on trusted push:\n%s", out)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Push with wrong passphrases
|
// Push with wrong passphrases
|
||||||
pushCmd = exec.Command(dockerBinary, "push", repoName)
|
pushCmd = exec.Command(dockerBinary, "push", repoName)
|
||||||
s.trustedCmdWithDeprecatedEnvPassphrases(pushCmd, "12345678", "87654321")
|
s.trustedCmdWithDeprecatedEnvPassphrases(pushCmd, "12345678", "87654321")
|
||||||
out, _, err = runCommandWithOutput(pushCmd)
|
out, _, err = runCommandWithOutput(pushCmd)
|
||||||
if err == nil {
|
c.Assert(err, check.NotNil, check.Commentf("Error missing from trusted push with short targets passphrase: \n%s", out))
|
||||||
c.Fatalf("Error missing from trusted push with short targets passphrase: \n%s", out)
|
c.Assert(out, checker.Contains, "password invalid, operation has failed", check.Commentf("Missing expected output on trusted push with short targets/snapsnot passphrase"))
|
||||||
}
|
|
||||||
|
|
||||||
if !strings.Contains(string(out), "password invalid, operation has failed") {
|
|
||||||
c.Fatalf("Missing expected output on trusted push with short targets/snapsnot passphrase:\n%s", out)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerTrustSuite) TestTrustedPushWithExpiredSnapshot(c *check.C) {
|
func (s *DockerTrustSuite) TestTrustedPushWithExpiredSnapshot(c *check.C) {
|
||||||
|
@ -344,13 +262,8 @@ func (s *DockerTrustSuite) TestTrustedPushWithExpiredSnapshot(c *check.C) {
|
||||||
pushCmd := exec.Command(dockerBinary, "push", repoName)
|
pushCmd := exec.Command(dockerBinary, "push", repoName)
|
||||||
s.trustedCmd(pushCmd)
|
s.trustedCmd(pushCmd)
|
||||||
out, _, err := runCommandWithOutput(pushCmd)
|
out, _, err := runCommandWithOutput(pushCmd)
|
||||||
if err != nil {
|
c.Assert(err, check.IsNil, check.Commentf("trusted push failed: %s\n%s", err, out))
|
||||||
c.Fatalf("trusted push failed: %s\n%s", err, out)
|
c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push"))
|
||||||
}
|
|
||||||
|
|
||||||
if !strings.Contains(string(out), "Signing and pushing trust metadata") {
|
|
||||||
c.Fatalf("Missing expected output on trusted push:\n%s", out)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Snapshots last for three years. This should be expired
|
// Snapshots last for three years. This should be expired
|
||||||
fourYearsLater := time.Now().Add(time.Hour * 24 * 365 * 4)
|
fourYearsLater := time.Now().Add(time.Hour * 24 * 365 * 4)
|
||||||
|
@ -360,13 +273,8 @@ func (s *DockerTrustSuite) TestTrustedPushWithExpiredSnapshot(c *check.C) {
|
||||||
pushCmd = exec.Command(dockerBinary, "push", repoName)
|
pushCmd = exec.Command(dockerBinary, "push", repoName)
|
||||||
s.trustedCmd(pushCmd)
|
s.trustedCmd(pushCmd)
|
||||||
out, _, err = runCommandWithOutput(pushCmd)
|
out, _, err = runCommandWithOutput(pushCmd)
|
||||||
if err == nil {
|
c.Assert(err, check.NotNil, check.Commentf("Error missing from trusted push with expired snapshot: \n%s", out))
|
||||||
c.Fatalf("Error missing from trusted push with expired snapshot: \n%s", out)
|
c.Assert(out, checker.Contains, "repository out-of-date", check.Commentf("Missing expected output on trusted push with expired snapshot"))
|
||||||
}
|
|
||||||
|
|
||||||
if !strings.Contains(string(out), "repository out-of-date") {
|
|
||||||
c.Fatalf("Missing expected output on trusted push with expired snapshot:\n%s", out)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -380,13 +288,8 @@ func (s *DockerTrustSuite) TestTrustedPushWithExpiredTimestamp(c *check.C) {
|
||||||
pushCmd := exec.Command(dockerBinary, "push", repoName)
|
pushCmd := exec.Command(dockerBinary, "push", repoName)
|
||||||
s.trustedCmd(pushCmd)
|
s.trustedCmd(pushCmd)
|
||||||
out, _, err := runCommandWithOutput(pushCmd)
|
out, _, err := runCommandWithOutput(pushCmd)
|
||||||
if err != nil {
|
c.Assert(err, check.IsNil, check.Commentf("trusted push failed: %s\n%s", err, out))
|
||||||
c.Fatalf("trusted push failed: %s\n%s", err, out)
|
c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push"))
|
||||||
}
|
|
||||||
|
|
||||||
if !strings.Contains(string(out), "Signing and pushing trust metadata") {
|
|
||||||
c.Fatalf("Missing expected output on trusted push:\n%s", out)
|
|
||||||
}
|
|
||||||
|
|
||||||
// The timestamps expire in two weeks. Lets check three
|
// The timestamps expire in two weeks. Lets check three
|
||||||
threeWeeksLater := time.Now().Add(time.Hour * 24 * 21)
|
threeWeeksLater := time.Now().Add(time.Hour * 24 * 21)
|
||||||
|
@ -396,11 +299,7 @@ func (s *DockerTrustSuite) TestTrustedPushWithExpiredTimestamp(c *check.C) {
|
||||||
pushCmd := exec.Command(dockerBinary, "push", repoName)
|
pushCmd := exec.Command(dockerBinary, "push", repoName)
|
||||||
s.trustedCmd(pushCmd)
|
s.trustedCmd(pushCmd)
|
||||||
out, _, err := runCommandWithOutput(pushCmd)
|
out, _, err := runCommandWithOutput(pushCmd)
|
||||||
if err != nil {
|
c.Assert(err, check.IsNil, check.Commentf("Error running trusted push: %s\n%s", err, out))
|
||||||
c.Fatalf("Error running trusted push: %s\n%s", err, out)
|
c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push with expired timestamp"))
|
||||||
}
|
|
||||||
if !strings.Contains(string(out), "Signing and pushing trust metadata") {
|
|
||||||
c.Fatalf("Missing expected output on trusted push with expired timestamp:\n%s", out)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue