package bun import ( "os" "path/filepath" "testing" "git.warky.dev/wdevs/relspecgo/pkg/readers" ) func TestReader_GeneratedAndIdentityMarkers(t *testing.T) { src := `package models import "github.com/uptrace/bun" type Person struct { bun.BaseModel ` + "`bun:\"table:people,alias:p\"`" + ` ID int64 ` + "`bun:\"id,pk,type:bigint,autoincrement,identity\"`" + ` Seq int64 ` + "`bun:\"seq,type:bigint,scanonly,identity,notnull\"`" + ` FullName string ` + "`bun:\"full_name,type:text,scanonly,generated,nullzero\"`" + ` First string ` + "`bun:\"first,type:text,nullzero\"`" + ` } ` path := filepath.Join(t.TempDir(), "person.go") if err := os.WriteFile(path, []byte(src), 0o644); err != nil { t.Fatal(err) } db, err := NewReader(&readers.ReaderOptions{FilePath: path}).ReadDatabase() if err != nil { t.Fatalf("ReadDatabase() error = %v", err) } cols := db.Schemas[0].Tables[0].Columns if !cols["id"].Identity || cols["id"].IdentityGeneration != "ALWAYS" { t.Errorf("id: identity = %v/%q, want true/ALWAYS", cols["id"].Identity, cols["id"].IdentityGeneration) } if !cols["seq"].Identity || cols["seq"].IdentityGeneration != "ALWAYS" { t.Errorf("seq: identity = %v/%q, want true/ALWAYS", cols["seq"].Identity, cols["seq"].IdentityGeneration) } if !cols["full_name"].Generated { t.Error("full_name should be generated") } if cols["first"].Generated || cols["first"].Identity { t.Error("first must be an ordinary column") } }