a bit more testing
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
package document_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"gotemplate/internal/database"
|
||||
"gotemplate/internal/database/repository"
|
||||
"gotemplate/internal/result"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/pashagolub/pgxmock/v3"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestStore(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, err := pgxmock.NewConn()
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
defer db.Close(ctx)
|
||||
|
||||
queries := repository.New(db)
|
||||
|
||||
resultStore := result.ResultStore{
|
||||
QueryID: uuid.New(),
|
||||
DocumentID: uuid.New(),
|
||||
Value: "val",
|
||||
CleanVersion: int32(1),
|
||||
TextVersion: int32(1),
|
||||
QueryVersion: int32(1),
|
||||
}
|
||||
|
||||
db.ExpectExec("name: SetResult :exec").WithArgs(pgxmock.AnyArg(), database.MustToDBUUID(resultStore.QueryID), database.MustToDBUUID(resultStore.DocumentID), resultStore.Value, resultStore.CleanVersion, resultStore.TextVersion, resultStore.QueryVersion).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
|
||||
id, err := result.Store(ctx, queries, &resultStore)
|
||||
assert.Nil(t, err)
|
||||
assert.NotNil(t, id)
|
||||
|
||||
errr := "database failing"
|
||||
db.ExpectExec("name: SetResult :exec").WithArgs(pgxmock.AnyArg(), database.MustToDBUUID(resultStore.QueryID), database.MustToDBUUID(resultStore.DocumentID), resultStore.Value, resultStore.CleanVersion, resultStore.TextVersion, resultStore.QueryVersion).
|
||||
WillReturnError(fmt.Errorf(errr))
|
||||
|
||||
id, err = result.Store(ctx, queries, &resultStore)
|
||||
assert.EqualError(t, err, errr)
|
||||
assert.Equal(t, uuid.Nil, id)
|
||||
}
|
||||
Reference in New Issue
Block a user