mirror of
https://github.com/containers/podman.git
synced 2025-08-06 19:44:14 +08:00
Merge pull request #12156 from matejvasek/docker-api-zero-value-fixes
Fix libpod API conformance to swagger
This commit is contained in:
@ -42,9 +42,9 @@ type ContainersPruneReport struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type LibpodContainersPruneReport struct {
|
type LibpodContainersPruneReport struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"Id"`
|
||||||
SpaceReclaimed int64 `json:"space"`
|
SpaceReclaimed int64 `json:"Size"`
|
||||||
PruneError string `json:"error"`
|
PruneError string `json:"Err,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Info struct {
|
type Info struct {
|
||||||
|
@ -145,12 +145,12 @@ func MarshalErrorSliceJSON(ptr unsafe.Pointer, stream *jsoniter.Stream) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func MarshalErrorJSONIsEmpty(_ unsafe.Pointer) bool {
|
func MarshalErrorJSONIsEmpty(ptr unsafe.Pointer) bool {
|
||||||
return false
|
return *((*error)(ptr)) == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func MarshalErrorSliceJSONIsEmpty(_ unsafe.Pointer) bool {
|
func MarshalErrorSliceJSONIsEmpty(ptr unsafe.Pointer) bool {
|
||||||
return false
|
return len(*((*[]error)(ptr))) <= 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// WriteJSON writes an interface value encoded as JSON to w
|
// WriteJSON writes an interface value encoded as JSON to w
|
||||||
|
@ -138,3 +138,51 @@ func TestEqualVersion(t *testing.T) {
|
|||||||
rr.Body.String(), expected)
|
rr.Body.String(), expected)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestErrorEncoderFuncOmit(t *testing.T) {
|
||||||
|
data, err := json.Marshal(struct {
|
||||||
|
Err error `json:"err,omitempty"`
|
||||||
|
Errs []error `json:"errs,omitempty"`
|
||||||
|
}{})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
dataAsMap := make(map[string]interface{})
|
||||||
|
err = json.Unmarshal(data, &dataAsMap)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, ok := dataAsMap["err"]
|
||||||
|
if ok {
|
||||||
|
t.Errorf("the `err` field should have been omitted")
|
||||||
|
}
|
||||||
|
_, ok = dataAsMap["errs"]
|
||||||
|
if ok {
|
||||||
|
t.Errorf("the `errs` field should have been omitted")
|
||||||
|
}
|
||||||
|
|
||||||
|
dataAsMap = make(map[string]interface{})
|
||||||
|
data, err = json.Marshal(struct {
|
||||||
|
Err error `json:"err"`
|
||||||
|
Errs []error `json:"errs"`
|
||||||
|
}{})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal(data, &dataAsMap)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, ok = dataAsMap["err"]
|
||||||
|
if !ok {
|
||||||
|
t.Errorf("the `err` field shouldn't have been omitted")
|
||||||
|
}
|
||||||
|
_, ok = dataAsMap["errs"]
|
||||||
|
if !ok {
|
||||||
|
t.Errorf("the `errs` field shouldn't have been omitted")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -967,7 +967,7 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error {
|
|||||||
// - application/json
|
// - application/json
|
||||||
// responses:
|
// responses:
|
||||||
// 200:
|
// 200:
|
||||||
// $ref: "#/responses/DocsImageDeleteResponse"
|
// $ref: "#/responses/DocsLibpodImagesRemoveResponse"
|
||||||
// 400:
|
// 400:
|
||||||
// $ref: "#/responses/BadParamError"
|
// $ref: "#/responses/BadParamError"
|
||||||
// 404:
|
// 404:
|
||||||
@ -1069,7 +1069,7 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error {
|
|||||||
// - application/json
|
// - application/json
|
||||||
// responses:
|
// responses:
|
||||||
// 200:
|
// 200:
|
||||||
// $ref: "#/responses/DocsImageDeleteResponse"
|
// $ref: "#/responses/DocsLibpodPruneResponse"
|
||||||
// 500:
|
// 500:
|
||||||
// $ref: '#/responses/InternalError'
|
// $ref: '#/responses/InternalError'
|
||||||
r.Handle(VersionedPath("/libpod/images/prune"), s.APIHandler(libpod.PruneImages)).Methods(http.MethodPost)
|
r.Handle(VersionedPath("/libpod/images/prune"), s.APIHandler(libpod.PruneImages)).Methods(http.MethodPost)
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package reports
|
package reports
|
||||||
|
|
||||||
type PruneReport struct {
|
type PruneReport struct {
|
||||||
Id string //nolint
|
Id string `json:"Id"` //nolint
|
||||||
Err error
|
Err error `json:"Err,omitempty"`
|
||||||
Size uint64
|
Size uint64 `json:"Size"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func PruneReportsIds(r []*PruneReport) []string {
|
func PruneReportsIds(r []*PruneReport) []string {
|
||||||
|
@ -57,7 +57,7 @@ func (ir *ImageEngine) Prune(ctx context.Context, opts entities.ImagePruneOption
|
|||||||
pruneOptions.Filters = append(pruneOptions.Filters, "containers=false")
|
pruneOptions.Filters = append(pruneOptions.Filters, "containers=false")
|
||||||
}
|
}
|
||||||
|
|
||||||
var pruneReports []*reports.PruneReport
|
pruneReports := make([]*reports.PruneReport, 0)
|
||||||
|
|
||||||
// Now prune all images until we converge.
|
// Now prune all images until we converge.
|
||||||
numPreviouslyRemovedImages := 1
|
numPreviouslyRemovedImages := 1
|
||||||
|
@ -218,6 +218,9 @@ if ! grep -q '400 Bad Request' "${TMPD}/headers.txt"; then
|
|||||||
BUILD_TEST_ERROR="1"
|
BUILD_TEST_ERROR="1"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
t POST libpod/images/prune 200
|
||||||
|
t POST libpod/images/prune 200 length=0 []
|
||||||
|
|
||||||
cleanBuildTest
|
cleanBuildTest
|
||||||
if [[ "${BUILD_TEST_ERROR}" ]]; then
|
if [[ "${BUILD_TEST_ERROR}" ]]; then
|
||||||
exit 1
|
exit 1
|
||||||
|
Reference in New Issue
Block a user