Skip to content

Commit

Permalink
moving test functions to better location
Browse files Browse the repository at this point in the history
Signed-off-by: David Lawrence <david.lawrence@docker.com> (github: endophage)
  • Loading branch information
David Lawrence committed May 6, 2015
1 parent 9bbe1d8 commit 09d45de
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 39 deletions.
4 changes: 2 additions & 2 deletions cmd/tools/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/endophage/go-tuf"
"github.com/endophage/go-tuf/signed"
"github.com/endophage/go-tuf/store"
"github.com/endophage/go-tuf/util"
"github.com/endophage/go-tuf/testutil"
"github.com/flynn/go-docopt"
)

Expand Down Expand Up @@ -73,7 +73,7 @@ func runCommand(name string, args []string) error {
return err
}

db := util.GetSqliteDB()
db := testutil.GetSqliteDB()
local := store.DBStore(db, "")
signer := signed.Ed25519{}
repo, err := tuf.NewRepo(&signer, local, "sha256")
Expand Down
43 changes: 22 additions & 21 deletions repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
// "github.com/endophage/go-tuf/encrypted"
tuferr "github.com/endophage/go-tuf/errors"
"github.com/endophage/go-tuf/signed"
"github.com/endophage/go-tuf/testutil"
"github.com/endophage/go-tuf/util"
)

Expand Down Expand Up @@ -69,8 +70,8 @@ func (RepoSuite) TestNewRepo(c *C) {
"signatures": []
}`),
}
db := util.GetSqliteDB()
defer util.FlushDB(db)
db := testutil.GetSqliteDB()
defer testutil.FlushDB(db)
local := store.DBStore(db, "")

for k, v := range meta {
Expand Down Expand Up @@ -112,14 +113,14 @@ func (RepoSuite) TestNewRepo(c *C) {
func (RepoSuite) TestInit(c *C) {
trust := signed.NewEd25519()

db := util.GetSqliteDB()
defer util.FlushDB(db)
db := testutil.GetSqliteDB()
defer testutil.FlushDB(db)
local := store.DBStore(
db,
"",
//map[string][]byte{"/foo.txt": []byte("foo")},
)
local.AddBlob("/foo.txt", util.SampleMeta())
local.AddBlob("/foo.txt", testutil.SampleMeta())

r, err := NewRepo(trust, local, "sha256")
c.Assert(err, IsNil)
Expand All @@ -146,8 +147,8 @@ func genKey(c *C, r *Repo, role string) string {
func (RepoSuite) TestGenKey(c *C) {
trust := signed.NewEd25519()

sqldb := util.GetSqliteDB()
defer util.FlushDB(sqldb)
sqldb := testutil.GetSqliteDB()
defer testutil.FlushDB(sqldb)
local := store.DBStore(sqldb, "")
r, err := NewRepo(trust, local, "sha256")
c.Assert(err, IsNil)
Expand Down Expand Up @@ -277,8 +278,8 @@ func (RepoSuite) TestGenKey(c *C) {
func (RepoSuite) TestRevokeKey(c *C) {
trust := signed.NewEd25519()

db := util.GetSqliteDB()
defer util.FlushDB(db)
db := testutil.GetSqliteDB()
defer testutil.FlushDB(db)
local := store.DBStore(db, "")
r, err := NewRepo(trust, local, "sha256")
c.Assert(err, IsNil)
Expand Down Expand Up @@ -330,8 +331,8 @@ func (RepoSuite) TestSign(c *C) {
trust := signed.NewEd25519()

baseMeta := map[string]json.RawMessage{"root.json": []byte(`{"signed":{},"signatures":[]}`)}
db := util.GetSqliteDB()
defer util.FlushDB(db)
db := testutil.GetSqliteDB()
defer testutil.FlushDB(db)
local := store.DBStore(db, "")
local.SetMeta("root.json", baseMeta["root.json"])
r, err := NewRepo(trust, local, "sha256")
Expand Down Expand Up @@ -382,8 +383,8 @@ func (RepoSuite) TestCommit(c *C) {
trust := signed.NewEd25519()

//files := map[string][]byte{"/foo.txt": []byte("foo"), "/bar.txt": []byte("bar")}
db := util.GetSqliteDB()
defer util.FlushDB(db)
db := testutil.GetSqliteDB()
defer testutil.FlushDB(db)
local := store.DBStore(db, "")
r, err := NewRepo(trust, local, "sha256")
c.Assert(err, IsNil)
Expand All @@ -397,7 +398,7 @@ func (RepoSuite) TestCommit(c *C) {

// commit without snapshot.json
genKey(c, r, "targets")
local.AddBlob("/foo.txt", util.SampleMeta())
local.AddBlob("/foo.txt", testutil.SampleMeta())
c.Assert(r.AddTargets(nil, "foo.txt"), IsNil)
c.Assert(r.Commit(), DeepEquals, tuferr.ErrMissingMetadata{"snapshot.json"})

Expand All @@ -423,7 +424,7 @@ func (RepoSuite) TestCommit(c *C) {

// commit with an invalid targets hash in snapshot.json
c.Assert(r.Snapshot(CompressionTypeNone), IsNil)
local.AddBlob("/bar.txt", util.SampleMeta())
local.AddBlob("/bar.txt", testutil.SampleMeta())
c.Assert(r.AddTargets(nil, "bar.txt"), IsNil)
c.Assert(r.Commit(), DeepEquals, errors.New("tuf: invalid targets.json in snapshot.json: wrong length"))

Expand Down Expand Up @@ -665,8 +666,8 @@ func (RepoSuite) TestExpiresAndVersion(c *C) {
trust := signed.NewEd25519()

//files := map[string][]byte{"/foo.txt": []byte("foo")}
db := util.GetSqliteDB()
defer util.FlushDB(db)
db := testutil.GetSqliteDB()
defer testutil.FlushDB(db)
local := store.DBStore(db, "")
r, err := NewRepo(trust, local, "sha256")
c.Assert(err, IsNil)
Expand Down Expand Up @@ -710,7 +711,7 @@ func (RepoSuite) TestExpiresAndVersion(c *C) {

expires = time.Now().Add(6 * time.Hour)
genKey(c, r, "targets")
local.AddBlob("/foo.txt", util.SampleMeta())
local.AddBlob("/foo.txt", testutil.SampleMeta())
c.Assert(r.AddTargetsWithExpires(nil, expires, "foo.txt"), IsNil)
targets, err := r.targets()
c.Assert(err, IsNil)
Expand Down Expand Up @@ -755,8 +756,8 @@ func (RepoSuite) TestHashAlgorithm(c *C) {
trust := signed.NewEd25519()

//files := map[string][]byte{"/foo.txt": []byte("foo")}
db := util.GetSqliteDB()
defer util.FlushDB(db)
db := testutil.GetSqliteDB()
defer testutil.FlushDB(db)
local := store.DBStore(db, "docker.io/testImage")
type hashTest struct {
args []string
Expand All @@ -773,7 +774,7 @@ func (RepoSuite) TestHashAlgorithm(c *C) {
genKey(c, r, "root")
genKey(c, r, "targets")
genKey(c, r, "snapshot")
local.AddBlob("/foo.txt", util.SampleMeta())
local.AddBlob("/foo.txt", testutil.SampleMeta())
c.Assert(r.AddTargets(nil, "foo.txt"), IsNil)
c.Assert(r.Snapshot(CompressionTypeNone), IsNil)
c.Assert(r.Timestamp(), IsNil)
Expand Down
30 changes: 15 additions & 15 deletions store/dbstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ import (
"testing"

"github.com/endophage/go-tuf/data"
"github.com/endophage/go-tuf/util"
"github.com/endophage/go-tuf/testutil"
)

// TestDBStore just ensures we can initialize an empty store.
// Nothing to test, just ensure no crashes :-)
func TestDBStore(t *testing.T) {
db := util.GetSqliteDB()
defer util.FlushDB(db)
db := testutil.GetSqliteDB()
defer testutil.FlushDB(db)
_ = DBStore(db, "")
}

func TestLoadFiles(t *testing.T) {
db := util.GetSqliteDB()
defer util.FlushDB(db)
db := testutil.GetSqliteDB()
defer testutil.FlushDB(db)
store := DBStore(db, "docker.io/testImage")
testmeta := util.SampleMeta()
testmeta := testutil.SampleMeta()
store.AddBlob("/foo.txt", testmeta)

called := false
Expand Down Expand Up @@ -52,10 +52,10 @@ func TestLoadFiles(t *testing.T) {
}

func TestAddBlob(t *testing.T) {
db := util.GetSqliteDB()
defer util.FlushDB(db)
db := testutil.GetSqliteDB()
defer testutil.FlushDB(db)
store := DBStore(db, "docker.io/testImage")
testmeta := util.SampleMeta()
testmeta := testutil.SampleMeta()
store.AddBlob("/foo.txt", testmeta)

called := false
Expand Down Expand Up @@ -100,10 +100,10 @@ func TestAddBlob(t *testing.T) {

func TestRemoveBlob(t *testing.T) {
testPath := "/foo.txt"
db := util.GetSqliteDB()
defer util.FlushDB(db)
db := testutil.GetSqliteDB()
defer testutil.FlushDB(db)
store := DBStore(db, "docker.io/testImage")
meta := util.SampleMeta()
meta := testutil.SampleMeta()

store.AddBlob(testPath, meta)

Expand All @@ -124,10 +124,10 @@ func TestRemoveBlob(t *testing.T) {
}

func TestLoadFilesWithPath(t *testing.T) {
db := util.GetSqliteDB()
defer util.FlushDB(db)
db := testutil.GetSqliteDB()
defer testutil.FlushDB(db)
store := DBStore(db, "docker.io/testImage")
meta := util.SampleMeta()
meta := testutil.SampleMeta()

store.AddBlob("/foo.txt", meta)
store.AddBlob("/bar.txt", meta)
Expand Down
2 changes: 1 addition & 1 deletion util/testutils.go → testutil/utils.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package util
package testutil

import (
"database/sql"
Expand Down

0 comments on commit 09d45de

Please sign in to comment.