Updating test for compatible platforms to test unmarshal body

Signed-off-by: Nishant Totla <nishanttotla@gmail.com>
This commit is contained in:
Nishant Totla 2017-05-17 16:58:54 -07:00
Родитель 587d07cca8
Коммит 7d4b8fb3b5
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 7EA5781C9B3D0C19
1 изменённых файлов: 16 добавлений и 4 удалений

Просмотреть файл

@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"strings"
@ -59,14 +60,24 @@ func TestServiceCreate(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: newMockClient(func(req *http.Request) (*http.Response, error) {
if strings.HasPrefix(req.URL.Path, "/services/create") {
// platforms should have been resolved by now
if len(platforms) != 1 || platforms[0].Architecture != "amd64" || platforms[0].OS != "linux" {
return nil, fmt.Errorf("incorrect platform information")
// check if the /distribution endpoint returned correct output
err := json.NewDecoder(distributionInspectBody).Decode(&distributionInspect)
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{
ID: "service_" + platforms[0].Architecture,
})
@ -91,6 +102,7 @@ func TestServiceCreateCompatiblePlatforms(t *testing.T) {
if err != nil {
return nil, err
}
distributionInspectBody = ioutil.NopCloser(bytes.NewReader(b))
return &http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(bytes.NewReader(b)),