add ImageFormat to worker_test and programs under contrib

Signed-off-by: Liang Chenye <liangchenye@huawei.com>
This commit is contained in:
Liang Chenye 2015-12-15 21:01:22 -08:00
parent 41509ccd3e
commit 4b11491067
3 changed files with 12 additions and 5 deletions

View File

@ -197,7 +197,7 @@ func history(imageName string) ([]string, error) {
} }
func analyzeLayer(endpoint, path, layerID, parentLayerID string) error { func analyzeLayer(endpoint, path, layerID, parentLayerID string) error {
payload := struct{ ID, Path, ParentID string }{ID: layerID, Path: path, ParentID: parentLayerID} payload := struct{ ID, Path, ParentID, ImageFormat string }{ID: layerID, Path: path, ParentID: parentLayerID, ImageFormat: "Docker"}
jsonPayload, err := json.Marshal(payload) jsonPayload, err := json.Marshal(payload)
if err != nil { if err != nil {
return err return err

View File

@ -51,6 +51,7 @@ type AddLayoutRequestAPI struct {
ID string `json:"ID"` ID string `json:"ID"`
Path string `json:"Path"` Path string `json:"Path"`
ParantID string `json:"ParantID"` ParantID string `json:"ParantID"`
ImageFormat string `json:"ImageFormat"`
} }
type VulnerabilityItem struct { type VulnerabilityItem struct {
@ -223,7 +224,7 @@ func (clair ClairAPI) AddLayer(openvzMirror string, templateName string) error {
client = httpClient client = httpClient
} }
jsonRequest, err := json.Marshal(AddLayoutRequestAPI{ID: templateName, Path: openvzMirror + "/" + templateName + ".tar.gz"}) jsonRequest, err := json.Marshal(AddLayoutRequestAPI{ID: templateName, Path: openvzMirror + "/" + templateName + ".tar.gz", ImageFormat: "Docker"})
if err != nil { if err != nil {
log.Println("Cannot convert to json request with error: ", err) log.Println("Cannot convert to json request with error: ", err)
return err return err

View File

@ -26,9 +26,15 @@ func TestDistUpgrade(t *testing.T) {
// blank.tar: MAINTAINER Quentin MACHU <quentin.machu.fr> // blank.tar: MAINTAINER Quentin MACHU <quentin.machu.fr>
// wheezy.tar: FROM debian:wheezy // wheezy.tar: FROM debian:wheezy
// jessie.tar: RUN sed -i "s/precise/trusty/" /etc/apt/sources.list && apt-get update && apt-get -y dist-upgrade // jessie.tar: RUN sed -i "s/precise/trusty/" /etc/apt/sources.list && apt-get update && apt-get -y dist-upgrade
assert.Nil(t, Process("blank", "", path+"blank.tar.gz", "")) assert.Nil(t, Process("blank", "", path+"blank.tar.gz", "Docker"))
assert.Nil(t, Process("wheezy", "blank", path+"wheezy.tar.gz", "")) assert.Nil(t, Process("wheezy", "blank", path+"wheezy.tar.gz", "Docker"))
assert.Nil(t, Process("jessie", "wheezy", path+"jessie.tar.gz", "")) assert.Nil(t, Process("jessie", "wheezy", path+"jessie.tar.gz", "Docker"))
err := Process("blank", "", path+"blank.tar.gz", "")
assert.Error(t, err, "could not process a layer which does not have a specified format")
err = Process("blank", "", path+"blank.tar.gz", "invalid")
assert.Error(t, err, "could not process a layer which does not have a supported format")
wheezy, err := database.FindOneLayerByID("wheezy", database.FieldLayerAll) wheezy, err := database.FindOneLayerByID("wheezy", database.FieldLayerAll)
if assert.Nil(t, err) { if assert.Nil(t, err) {