2015-04-29 07:56:45 -04:00
package main
import (
2016-02-04 07:47:15 -05:00
"fmt"
2015-04-29 07:56:45 -04:00
"net/http"
2015-08-31 17:45:27 -04:00
"net/http/httptest"
2016-11-02 12:43:29 -04:00
"runtime"
2015-06-17 17:57:32 -04:00
"strconv"
"strings"
2015-04-29 07:56:45 -04:00
2015-06-17 17:57:32 -04:00
"github.com/docker/docker/api"
2015-10-13 08:01:58 -04:00
"github.com/docker/docker/pkg/integration/checker"
2016-08-04 12:57:34 -04:00
icmd "github.com/docker/docker/pkg/integration/cmd"
2015-04-29 07:56:45 -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 ) TestAPIOptionsRoute ( c * check . C ) {
2015-04-29 07:56:45 -04:00
status , _ , err := sockRequest ( "OPTIONS" , "/" , nil )
2015-10-13 08:01:58 -04:00
c . Assert ( err , checker . IsNil )
c . Assert ( status , checker . Equals , http . StatusOK )
2015-04-29 07:56:45 -04: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 ) TestAPIGetEnabledCORS ( c * check . C ) {
2015-04-29 07:56:45 -04:00
res , body , err := sockRequestRaw ( "GET" , "/version" , nil , "" )
2015-10-13 08:01:58 -04:00
c . Assert ( err , checker . IsNil )
c . Assert ( res . StatusCode , checker . Equals , http . StatusOK )
2015-07-23 07:24:14 -04:00
body . Close ( )
2015-04-29 07:56:45 -04:00
// TODO: @runcom incomplete tests, why old integration tests had this headers
// and here none of the headers below are in the response?
//c.Log(res.Header)
//c.Assert(res.Header.Get("Access-Control-Allow-Origin"), check.Equals, "*")
//c.Assert(res.Header.Get("Access-Control-Allow-Headers"), check.Equals, "Origin, X-Requested-With, Content-Type, Accept, X-Registry-Auth")
}
2015-05-19 12:28:50 -04: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 ) TestAPIClientVersionOldNotSupported ( c * check . C ) {
2016-11-02 12:43:29 -04:00
if daemonPlatform != runtime . GOOS {
c . Skip ( "Daemon platform doesn't match test platform" )
}
if api . MinVersion == api . DefaultVersion {
c . Skip ( "API MinVersion==DefaultVersion" )
}
2016-04-19 10:56:54 -04:00
v := strings . Split ( api . MinVersion , "." )
2015-06-17 17:57:32 -04:00
vMinInt , err := strconv . Atoi ( v [ 1 ] )
2015-10-13 08:01:58 -04:00
c . Assert ( err , checker . IsNil )
2015-06-17 17:57:32 -04:00
vMinInt --
v [ 1 ] = strconv . Itoa ( vMinInt )
version := strings . Join ( v , "." )
status , body , err := sockRequest ( "GET" , "/v" + version + "/version" , nil )
2015-10-13 08:01:58 -04:00
c . Assert ( err , checker . IsNil )
c . Assert ( status , checker . Equals , http . StatusBadRequest )
2016-02-04 07:47:15 -05:00
expected := fmt . Sprintf ( "client version %s is too old. Minimum supported API version is %s, please upgrade your client to a newer version" , version , api . MinVersion )
2016-10-31 13:15:43 -04:00
c . Assert ( strings . TrimSpace ( string ( body ) ) , checker . Contains , expected )
2015-06-17 17:57:32 -04:00
}
2015-08-31 17:45:27 -04: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 ) TestAPIDockerAPIVersion ( c * check . C ) {
2015-08-31 17:45:27 -04:00
var svrVersion string
server := httptest . NewServer ( http . HandlerFunc (
func ( w http . ResponseWriter , r * http . Request ) {
2016-11-02 20:43:32 -04:00
w . Header ( ) . Set ( "API-Version" , api . DefaultVersion )
2015-08-31 17:45:27 -04:00
url := r . URL . Path
svrVersion = url
} ) )
defer server . Close ( )
// Test using the env var first
2016-08-04 12:57:34 -04:00
result := icmd . RunCmd ( icmd . Cmd {
2016-08-16 17:51:38 -04:00
Command : binaryWithArgs ( "-H=" + server . URL [ 7 : ] , "version" ) ,
Env : appendBaseEnv ( false , "DOCKER_API_VERSION=xxx" ) ,
2016-08-04 12:57:34 -04:00
} )
2016-08-16 17:51:38 -04:00
c . Assert ( result , icmd . Matches , icmd . Expected { Out : "API version: xxx" , ExitCode : 1 } )
c . Assert ( svrVersion , check . Equals , "/vxxx/version" , check . Commentf ( "%s" , result . Compare ( icmd . Success ) ) )
2015-08-31 17:45:27 -04:00
}
2016-05-21 07:56:04 -04: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 ) TestAPIErrorJSON ( c * check . C ) {
2016-05-21 07:56:04 -04:00
httpResp , body , err := sockRequestRaw ( "POST" , "/containers/create" , strings . NewReader ( ` { } ` ) , "application/json" )
c . Assert ( err , checker . IsNil )
c . Assert ( httpResp . StatusCode , checker . Equals , http . StatusInternalServerError )
c . Assert ( httpResp . Header . Get ( "Content-Type" ) , checker . Equals , "application/json" )
b , err := readBody ( body )
c . Assert ( err , checker . IsNil )
c . Assert ( getErrorMessage ( c , b ) , checker . Equals , "Config cannot be empty in order to create a container" )
}
[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 ) TestAPIErrorPlainText ( c * check . C ) {
2016-10-31 13:15:43 -04:00
// Windows requires API 1.25 or later. This test is validating a behaviour which was present
// in v1.23, but changed in 1.24, hence not applicable on Windows. See apiVersionSupportsJSONErrors
testRequires ( c , DaemonIsLinux )
2016-05-21 07:56:04 -04:00
httpResp , body , err := sockRequestRaw ( "POST" , "/v1.23/containers/create" , strings . NewReader ( ` { } ` ) , "application/json" )
c . Assert ( err , checker . IsNil )
c . Assert ( httpResp . StatusCode , checker . Equals , http . StatusInternalServerError )
c . Assert ( httpResp . Header . Get ( "Content-Type" ) , checker . Contains , "text/plain" )
b , err := readBody ( body )
c . Assert ( err , checker . IsNil )
c . Assert ( strings . TrimSpace ( string ( b ) ) , checker . Equals , "Config cannot be empty in order to create a container" )
}
[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 ) TestAPIErrorNotFoundJSON ( c * check . C ) {
2016-05-21 07:56:04 -04:00
// 404 is a different code path to normal errors, so test separately
httpResp , body , err := sockRequestRaw ( "GET" , "/notfound" , nil , "application/json" )
c . Assert ( err , checker . IsNil )
c . Assert ( httpResp . StatusCode , checker . Equals , http . StatusNotFound )
c . Assert ( httpResp . Header . Get ( "Content-Type" ) , checker . Equals , "application/json" )
b , err := readBody ( body )
c . Assert ( err , checker . IsNil )
c . Assert ( getErrorMessage ( c , b ) , checker . Equals , "page not found" )
}
[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 ) TestAPIErrorNotFoundPlainText ( c * check . C ) {
2016-05-21 07:56:04 -04:00
httpResp , body , err := sockRequestRaw ( "GET" , "/v1.23/notfound" , nil , "application/json" )
c . Assert ( err , checker . IsNil )
c . Assert ( httpResp . StatusCode , checker . Equals , http . StatusNotFound )
c . Assert ( httpResp . Header . Get ( "Content-Type" ) , checker . Contains , "text/plain" )
b , err := readBody ( body )
c . Assert ( err , checker . IsNil )
c . Assert ( strings . TrimSpace ( string ( b ) ) , checker . Equals , "page not found" )
}