зеркало из https://github.com/microsoft/docker.git
Updating test for compatible platforms to test unmarshal body
Signed-off-by: Nishant Totla <nishanttotla@gmail.com>
This commit is contained in:
Родитель
587d07cca8
Коммит
7d4b8fb3b5
|
@ -4,6 +4,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -59,14 +60,24 @@ func TestServiceCreate(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestServiceCreateCompatiblePlatforms(t *testing.T) {
|
func TestServiceCreateCompatiblePlatforms(t *testing.T) {
|
||||||
var platforms []v1.Platform
|
var (
|
||||||
|
platforms []v1.Platform
|
||||||
|
distributionInspectBody io.ReadCloser
|
||||||
|
distributionInspect registrytypes.DistributionInspect
|
||||||
|
)
|
||||||
|
|
||||||
client := &Client{
|
client := &Client{
|
||||||
client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
||||||
if strings.HasPrefix(req.URL.Path, "/services/create") {
|
if strings.HasPrefix(req.URL.Path, "/services/create") {
|
||||||
// platforms should have been resolved by now
|
// check if the /distribution endpoint returned correct output
|
||||||
if len(platforms) != 1 || platforms[0].Architecture != "amd64" || platforms[0].OS != "linux" {
|
err := json.NewDecoder(distributionInspectBody).Decode(&distributionInspect)
|
||||||
return nil, fmt.Errorf("incorrect platform information")
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if len(distributionInspect.Platforms) == 0 || distributionInspect.Platforms[0].Architecture != platforms[0].Architecture || distributionInspect.Platforms[0].OS != platforms[0].OS {
|
||||||
|
return nil, fmt.Errorf("received incorrect platform information from registry")
|
||||||
|
}
|
||||||
|
|
||||||
b, err := json.Marshal(types.ServiceCreateResponse{
|
b, err := json.Marshal(types.ServiceCreateResponse{
|
||||||
ID: "service_" + platforms[0].Architecture,
|
ID: "service_" + platforms[0].Architecture,
|
||||||
})
|
})
|
||||||
|
@ -91,6 +102,7 @@ func TestServiceCreateCompatiblePlatforms(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
distributionInspectBody = ioutil.NopCloser(bytes.NewReader(b))
|
||||||
return &http.Response{
|
return &http.Response{
|
||||||
StatusCode: http.StatusOK,
|
StatusCode: http.StatusOK,
|
||||||
Body: ioutil.NopCloser(bytes.NewReader(b)),
|
Body: ioutil.NopCloser(bytes.NewReader(b)),
|
||||||
|
|
Загрузка…
Ссылка в новой задаче