Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package main

import (
"sync"
"testing"

"gorm.io/gorm/schema"
)

// GORM_REPO: https://github.com/go-gorm/gorm.git
Expand All @@ -18,3 +21,25 @@ func TestGORM(t *testing.T) {
t.Errorf("Failed, got error: %v", err)
}
}

func TestParseJSONBFieldWithDefaultValue(t *testing.T) {
type Payload struct {
ID string
}
type Table struct {
ID string `gorm:"primaryKey;type:uuid"`
Payload Payload `gorm:"serializer:json;type:jsonb;default:'{}'"`
Str string `gorm:"default:'default'"`
}

s, err := schema.Parse(&Table{}, &sync.Map{}, schema.NamingStrategy{})
if err != nil {
t.Fatalf("Unable to parse schema: %v", err)
}
if s.FieldsByDBName["payload"].DefaultValue != "{}" {
t.Errorf("Expected default value for payload to be `{}`, got %q", s.FieldsByDBName["payload"].DefaultValue)
}
if s.FieldsByDBName["str"].DefaultValue != "default" {
t.Errorf("Expected default value for str to be `default`, got %q", s.FieldsByDBName["str"].DefaultValue)
}
}
Loading