Skip to content

Commit

Permalink
tests/lib/fakestore: return confinement in snap details
Browse files Browse the repository at this point in the history
Signed-off-by: Maciej Borzecki <[email protected]>
  • Loading branch information
bboozzoo committed Oct 29, 2018
1 parent a960454 commit b9c8127
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 10 deletions.
11 changes: 9 additions & 2 deletions tests/lib/fakestore/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ type essentialInfo struct {
Version string
Size uint64
Digest string
Confinement string
}

var errInfo = errors.New("cannot get info")
Expand Down Expand Up @@ -226,6 +227,7 @@ func snapEssentialInfo(w http.ResponseWriter, fn, snapID string, bs asserts.Back
Version: info.Version,
Digest: snapDigest,
Size: size,
Confinement: string(info.Confinement),
}, nil
}

Expand All @@ -244,6 +246,7 @@ type detailsReplyJSON struct {
Version string `json:"version"`
Revision int `json:"revision"`
DownloadDigest string `json:"download_sha3_384"`
Confinement string `json:"confinement"`
}

func (s *Store) searchEndpoint(w http.ResponseWriter, req *http.Request) {
Expand Down Expand Up @@ -293,6 +296,7 @@ func (s *Store) detailsEndpoint(w http.ResponseWriter, req *http.Request) {
Version: essInfo.Version,
Revision: essInfo.Revision,
DownloadDigest: hexify(essInfo.Digest),
Confinement: essInfo.Confinement,
}

// use indent because this is a development tool, output
Expand Down Expand Up @@ -429,6 +433,7 @@ func (s *Store) bulkEndpoint(w http.ResponseWriter, req *http.Request) {
Version: essInfo.Version,
Revision: essInfo.Revision,
DownloadDigest: hexify(essInfo.Digest),
Confinement: essInfo.Confinement,
})
}
}
Expand Down Expand Up @@ -523,8 +528,9 @@ type detailsResultV2 struct {
Sha3_384 string `json:"sha3-384"`
Size uint64 `json:"size"`
} `json:"download"`
Version string `json:"version"`
Revision int `json:"revision"`
Version string `json:"version"`
Revision int `json:"revision"`
Confinement string `json:"confinement"`
}

func (s *Store) snapActionEndpoint(w http.ResponseWriter, req *http.Request) {
Expand Down Expand Up @@ -606,6 +612,7 @@ func (s *Store) snapActionEndpoint(w http.ResponseWriter, req *http.Request) {
Name: essInfo.Name,
Version: essInfo.Version,
Revision: essInfo.Revision,
Confinement: essInfo.Confinement,
},
}
res.Snap.Publisher.ID = essInfo.DeveloperID
Expand Down
46 changes: 38 additions & 8 deletions tests/lib/fakestore/store/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ func (s *storeTestSuite) TestDetailsEndpointWithAssertions(c *C) {
"version": "7",
"revision": float64(77),
"download_sha3_384": sha3_384,
"confinement": "strict",
})
}

Expand All @@ -164,6 +165,29 @@ func (s *storeTestSuite) TestDetailsEndpoint(c *C) {
"version": "1",
"revision": float64(424242),
"download_sha3_384": sha3_384,
"confinement": "strict",
})

snapFn = s.makeTestSnap(c, "name: foo-classic\nversion: 1\nconfinement: classic")
resp, err = s.StoreGet(`/api/v1/snaps/details/foo-classic`)
c.Assert(err, IsNil)
defer resp.Body.Close()

c.Assert(resp.StatusCode, Equals, 200)
c.Assert(json.NewDecoder(resp.Body).Decode(&body), IsNil)
sha3_384, _ = getSha(snapFn)
c.Check(body, DeepEquals, map[string]interface{}{
"architecture": []interface{}{"all"},
"snap_id": "",
"package_name": "foo-classic",
"origin": "canonical",
"developer_id": "canonical",
"anon_download_url": s.store.URL() + "/download/foo-classic_1_all.snap",
"download_url": s.store.URL() + "/download/foo-classic_1_all.snap",
"version": "1",
"revision": float64(424242),
"download_sha3_384": sha3_384,
"confinement": "classic",
})
}

Expand Down Expand Up @@ -197,6 +221,7 @@ func (s *storeTestSuite) TestBulkEndpoint(c *C) {
"version": "1",
"revision": float64(424242),
"download_sha3_384": sha3_384,
"confinement": "strict",
}})
}

Expand Down Expand Up @@ -229,6 +254,7 @@ func (s *storeTestSuite) TestBulkEndpointWithAssertions(c *C) {
"version": "10",
"revision": float64(99),
"download_sha3_384": sha3_384,
"confinement": "strict",
}})
}

Expand Down Expand Up @@ -430,8 +456,9 @@ func (s *storeTestSuite) TestSnapActionEndpoint(c *C) {
"sha3-384": sha3_384,
"size": float64(size),
},
"version": "1",
"revision": float64(424242),
"version": "1",
"revision": float64(424242),
"confinement": "strict",
},
})
}
Expand Down Expand Up @@ -472,8 +499,9 @@ func (s *storeTestSuite) TestSnapActionEndpointWithAssertions(c *C) {
"sha3-384": sha3_384,
"size": float64(size),
},
"version": "10",
"revision": float64(99),
"version": "10",
"revision": float64(99),
"confinement": "strict",
},
})
}
Expand Down Expand Up @@ -513,8 +541,9 @@ func (s *storeTestSuite) TestSnapActionEndpointRefreshAll(c *C) {
"sha3-384": sha3_384,
"size": float64(size),
},
"version": "1",
"revision": float64(424242),
"version": "1",
"revision": float64(424242),
"confinement": "strict",
},
})
}
Expand Down Expand Up @@ -555,8 +584,9 @@ func (s *storeTestSuite) TestSnapActionEndpointWithAssertionsInstall(c *C) {
"sha3-384": sha3_384,
"size": float64(size),
},
"version": "10",
"revision": float64(99),
"version": "10",
"revision": float64(99),
"confinement": "strict",
},
})
}

0 comments on commit b9c8127

Please sign in to comment.