From 4b1149106751d510fc6d16f8c4b923e72a054448 Mon Sep 17 00:00:00 2001 From: Liang Chenye Date: Tue, 15 Dec 2015 21:01:22 -0800 Subject: [PATCH] add ImageFormat to worker_test and programs under contrib Signed-off-by: Liang Chenye --- contrib/analyze-local-images/main.go | 2 +- contrib/check-openvz-mirror-with-clair/main.go | 3 ++- worker/worker_test.go | 12 +++++++++--- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/contrib/analyze-local-images/main.go b/contrib/analyze-local-images/main.go index 1fa5219d..777eb89d 100644 --- a/contrib/analyze-local-images/main.go +++ b/contrib/analyze-local-images/main.go @@ -197,7 +197,7 @@ func history(imageName string) ([]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) if err != nil { return err diff --git a/contrib/check-openvz-mirror-with-clair/main.go b/contrib/check-openvz-mirror-with-clair/main.go index 31b80e25..8b26a524 100644 --- a/contrib/check-openvz-mirror-with-clair/main.go +++ b/contrib/check-openvz-mirror-with-clair/main.go @@ -51,6 +51,7 @@ type AddLayoutRequestAPI struct { ID string `json:"ID"` Path string `json:"Path"` ParantID string `json:"ParantID"` + ImageFormat string `json:"ImageFormat"` } type VulnerabilityItem struct { @@ -223,7 +224,7 @@ func (clair ClairAPI) AddLayer(openvzMirror string, templateName string) error { 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 { log.Println("Cannot convert to json request with error: ", err) return err diff --git a/worker/worker_test.go b/worker/worker_test.go index 8d59d8cd..5852b09d 100644 --- a/worker/worker_test.go +++ b/worker/worker_test.go @@ -26,9 +26,15 @@ func TestDistUpgrade(t *testing.T) { // blank.tar: MAINTAINER Quentin MACHU // 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 - assert.Nil(t, Process("blank", "", path+"blank.tar.gz", "")) - assert.Nil(t, Process("wheezy", "blank", path+"wheezy.tar.gz", "")) - assert.Nil(t, Process("jessie", "wheezy", path+"jessie.tar.gz", "")) + assert.Nil(t, Process("blank", "", path+"blank.tar.gz", "Docker")) + assert.Nil(t, Process("wheezy", "blank", path+"wheezy.tar.gz", "Docker")) + 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) if assert.Nil(t, err) {