mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-05-08 22:30:41 +00:00
Custom JSON marshalling for PackageDiff, updated test for snapshot diff API. #168
This commit is contained in:
@@ -2,6 +2,8 @@ package deb
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"github.com/AlekSi/pointer"
|
||||||
"github.com/ugorji/go/codec"
|
"github.com/ugorji/go/codec"
|
||||||
"sort"
|
"sort"
|
||||||
)
|
)
|
||||||
@@ -154,6 +156,27 @@ type PackageDiff struct {
|
|||||||
Left, Right *Package
|
Left, Right *Package
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check interface
|
||||||
|
var (
|
||||||
|
_ json.Marshaler = PackageDiff{}
|
||||||
|
)
|
||||||
|
|
||||||
|
// MarshalJSON implements json.Marshaler interface
|
||||||
|
func (d PackageDiff) MarshalJSON() ([]byte, error) {
|
||||||
|
serialized := struct {
|
||||||
|
Left, Right *string
|
||||||
|
}{}
|
||||||
|
|
||||||
|
if d.Left != nil {
|
||||||
|
serialized.Left = pointer.ToString(string(d.Left.Key("")))
|
||||||
|
}
|
||||||
|
if d.Right != nil {
|
||||||
|
serialized.Right = pointer.ToString(string(d.Right.Key("")))
|
||||||
|
}
|
||||||
|
|
||||||
|
return json.Marshal(serialized)
|
||||||
|
}
|
||||||
|
|
||||||
// PackageDiffs is a list of PackageDiff records
|
// PackageDiffs is a list of PackageDiff records
|
||||||
type PackageDiffs []PackageDiff
|
type PackageDiffs []PackageDiff
|
||||||
|
|
||||||
|
|||||||
@@ -158,7 +158,7 @@ class SnapshotsAPITestSearch(APITest):
|
|||||||
|
|
||||||
class SnapshotsAPITestDiff(APITest):
|
class SnapshotsAPITestDiff(APITest):
|
||||||
"""
|
"""
|
||||||
POST /api/snapshot/:name/diff/:name2
|
GET /api/snapshot/:name/diff/:name2
|
||||||
"""
|
"""
|
||||||
def check(self):
|
def check(self):
|
||||||
repos = [self.random_name() for x in xrange(2)]
|
repos = [self.random_name() for x in xrange(2)]
|
||||||
@@ -180,7 +180,19 @@ class SnapshotsAPITestDiff(APITest):
|
|||||||
self.check_equal(resp.status_code, 201)
|
self.check_equal(resp.status_code, 201)
|
||||||
|
|
||||||
resp = self.get("/api/snapshots/" + snapshots[0] + "/diff/" + snapshots[1])
|
resp = self.get("/api/snapshots/" + snapshots[0] + "/diff/" + snapshots[1])
|
||||||
|
|
||||||
self.check_equal(resp.status_code, 200)
|
self.check_equal(resp.status_code, 200)
|
||||||
self.check_subset({"Right": None}, resp.json()[0])
|
self.check_equal(resp.json(), [{'Left': 'Pi386 libboost-program-options-dev 1.49.0.1 918d2f433384e378',
|
||||||
self.check_subset({"Name": "libboost-program-options-dev"}, resp.json()[0]["Left"])
|
'Right': None}])
|
||||||
|
|
||||||
|
resp = self.get("/api/snapshots/" + snapshots[1] + "/diff/" + snapshots[0])
|
||||||
|
self.check_equal(resp.status_code, 200)
|
||||||
|
self.check_equal(resp.json(), [{'Right': 'Pi386 libboost-program-options-dev 1.49.0.1 918d2f433384e378',
|
||||||
|
'Left': None}])
|
||||||
|
|
||||||
|
resp = self.get("/api/snapshots/" + snapshots[0] + "/diff/" + snapshots[0])
|
||||||
|
self.check_equal(resp.status_code, 200)
|
||||||
|
self.check_equal(resp.json(), [])
|
||||||
|
|
||||||
|
resp = self.get("/api/snapshots/" + snapshots[1] + "/diff/" + snapshots[1])
|
||||||
|
self.check_equal(resp.status_code, 200)
|
||||||
|
self.check_equal(resp.json(), [])
|
||||||
|
|||||||
Reference in New Issue
Block a user