1
// Copyright 2015 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
4
// TODO frankban: remove this package after updating entities in the production
5
// db with their SHA256 hash value. Entities are updated by running the
8
package hashtesting // import "gopkg.in/juju/charmstore.v5-unstable/internal/storetesting/hashtesting"
13
jujutesting "github.com/juju/testing"
14
gc "gopkg.in/check.v1"
15
"gopkg.in/juju/charm.v6-unstable"
16
"gopkg.in/mgo.v2/bson"
18
"gopkg.in/juju/charmstore.v5-unstable/internal/charmstore"
19
"gopkg.in/juju/charmstore.v5-unstable/internal/router"
22
func CheckSHA256Laziness(c *gc.C, store *charmstore.Store, id *charm.URL, check func()) {
23
updated := make(chan struct{}, 1)
25
// Patch charmstore.UpdateEntitySHA256 so that we can know whether it has
26
// been called or not.
27
original := charmstore.UpdateEntitySHA256
28
restore := jujutesting.PatchValue(
29
&charmstore.UpdateEntitySHA256,
30
func(store *charmstore.Store, id *router.ResolvedURL, sum256 string) {
31
original(store, id, sum256)
36
// Update the entity removing the SHA256 hash.
37
store.DB.Entities().UpdateId(id, bson.D{{
38
"$set", bson.D{{"blobhash256", ""}},
41
// Run the code under test.
44
// Ensure the db is updated asynchronously.
47
case <-time.After(5 * time.Second):
48
c.Fatalf("timed out waiting for update")
51
// Run the code under test. again.
54
// We should not update the SHA256 the second time.
57
c.Fatalf("update called twice")
58
case <-time.After(10 * time.Millisecond):