Skip to content

Commit

Permalink
Change composite type test to use decimal SQL type
Browse files Browse the repository at this point in the history
  • Loading branch information
Dadido3 committed Apr 28, 2023
1 parent c9c1fff commit f1cd1a0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions db-test/gorm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func TestCompositeType(t *testing.T) {
}

// Create custom composite type.
if err := gormDB.Exec("DROP TYPE IF EXISTS d3money; CREATE TYPE d3money AS (amount VARCHAR, currency VARCHAR);").Error; err != nil {
if err := gormDB.Exec("DROP TYPE IF EXISTS d3money; CREATE TYPE d3money AS (amount DECIMAL, currency VARCHAR);").Error; err != nil {
t.Fatalf("Failed to create d3money composite type: %v", err)
}

Expand Down Expand Up @@ -117,7 +117,7 @@ func TestCompositeType(t *testing.T) {

// Test direct access to the fields of the composite type.
type CompositeFields struct {
Amount string
Amount decimal.Decimal
Currency string
}

Expand All @@ -126,7 +126,7 @@ func TestCompositeType(t *testing.T) {
t.Errorf("Failed to query account 1: %v", err)
}

a1ExpectedFields := CompositeFields{a1.Balance.Decimal().String(), a1.Balance.Currency().UniqueCode()}
a1ExpectedFields := CompositeFields{a1.Balance.Decimal(), a1.Balance.Currency().UniqueCode()}
if !reflect.DeepEqual(a1ReadFields, a1ExpectedFields) {
t.Errorf("Queried balance fields %+v don't match expected fields %+v", a1ReadFields, a1ExpectedFields)
}
Expand All @@ -136,7 +136,7 @@ func TestCompositeType(t *testing.T) {
t.Errorf("Failed to query account 2: %v", err)
}

a2ExpectedFields := CompositeFields{a2.Balance.Decimal().String(), ""}
a2ExpectedFields := CompositeFields{a2.Balance.Decimal(), ""}
if !reflect.DeepEqual(a2ReadFields, a2ExpectedFields) {
t.Errorf("Queried balance fields %+v don't match expected fields %+v", a2ReadFields, a2ExpectedFields)
}
Expand Down
4 changes: 2 additions & 2 deletions db-test/schemas.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import (
)

type TestAccount struct {
ID uint `gorm:"primarykey"`
ID uint `gorm:"primaryKey"`
CreatedAt time.Time
UpdatedAt time.Time

Balance money.Value
}

type TestAccountCompositeType struct {
ID uint `gorm:"primarykey"`
ID uint `gorm:"primaryKey"`
CreatedAt time.Time
UpdatedAt time.Time

Expand Down

0 comments on commit f1cd1a0

Please sign in to comment.