Skip to content

Commit

Permalink
Remove tests using newTestCollectionWithSchema
Browse files Browse the repository at this point in the history
All users of this are very old unit tests that test nothing that isn't already covered by a large number of integration tests. It is not worth rewriting them.
  • Loading branch information
AndrewSisley committed Oct 2, 2023
1 parent e08bcaf commit 6aef3e7
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 562 deletions.
106 changes: 0 additions & 106 deletions db/collection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,117 +12,11 @@ package db

import (
"context"
"reflect"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/sourcenetwork/defradb/client"
)

func newTestCollectionWithSchema(
t *testing.T,
ctx context.Context,
db *implicitTxnDB,
) (client.Collection, error) {
desc := client.CollectionDescription{
Name: "users",
Schema: client.SchemaDescription{
Fields: []client.FieldDescription{
{
Name: "_key",
Kind: client.FieldKind_DocKey,
},
{
Name: "Name",
Kind: client.FieldKind_STRING,
Typ: client.LWW_REGISTER,
},
{
Name: "Age",
Kind: client.FieldKind_INT,
Typ: client.LWW_REGISTER,
},
{
Name: "Weight",
Kind: client.FieldKind_FLOAT,
Typ: client.LWW_REGISTER,
},
},
},
}

txn, err := db.NewTxn(ctx, false)
require.NoError(t, err)

col, err := db.createCollection(ctx, txn, desc)
if err != nil {
return col, err
}

return col, txn.Commit(ctx)
}

func TestNewCollectionWithSchema(t *testing.T) {
ctx := context.Background()
db, err := newMemoryDB(ctx)
assert.NoError(t, err)

col, err := newTestCollectionWithSchema(t, ctx, db)
assert.NoError(t, err)

schema := col.Schema()
desc := col.Description()

assert.True(t, reflect.DeepEqual(schema, desc.Schema))
assert.Equal(t, "users", col.Name())
assert.Equal(t, uint32(1), col.ID())
assert.False(t, reflect.DeepEqual(schema, client.SchemaDescription{}))
assert.Equal(t, 4, len(schema.Fields))

for i := 0; i < 4; i++ {
assert.Equal(t, client.FieldID(i), schema.Fields[i].ID)
}
}

func TestNewCollectionReturnsErrorGivenDuplicateSchema(t *testing.T) {
ctx := context.Background()
db, err := newMemoryDB(ctx)
assert.NoError(t, err)

_, err = newTestCollectionWithSchema(t, ctx, db)
assert.NoError(t, err)

_, err = newTestCollectionWithSchema(t, ctx, db)
assert.Errorf(t, err, "collection already exists")
}

func TestGetCollectionByName(t *testing.T) {
ctx := context.Background()
db, err := newMemoryDB(ctx)
assert.NoError(t, err)

_, err = newTestCollectionWithSchema(t, ctx, db)
assert.NoError(t, err)

col, err := db.GetCollectionByName(ctx, "users")
assert.NoError(t, err)

schema := col.Schema()
desc := col.Description()

assert.True(t, reflect.DeepEqual(schema, desc.Schema))
assert.Equal(t, "users", col.Name())
assert.Equal(t, uint32(1), col.ID())
assert.False(t, reflect.DeepEqual(schema, client.SchemaDescription{}))
assert.Equal(t, 4, len(schema.Fields))

for i := 0; i < 4; i++ {
assert.Equal(t, client.FieldID(i), schema.Fields[i].ID)
}
}

func TestGetCollectionByNameReturnsErrorGivenNonExistantCollection(t *testing.T) {
ctx := context.Background()
db, err := newMemoryDB(ctx)
Expand Down
Loading

0 comments on commit 6aef3e7

Please sign in to comment.