Skip to content

Fix int32/int64 cast order in dbtest faker - #70

Merged
sergeyfast merged 1 commit into
masterfrom
fix/dbtest-int-cast
Oct 9, 2026
Merged

sergeyfast merged 1 commit into
masterfrom
fix/dbtest-int-cast

Conversation

@sergeyfast

Copy link
Copy Markdown
Member

Problem

Since #62 (the fix for #56), dbtest wraps the int32/int64 cast around the
whole assignment:

int64(in.TgUserID = gofakeit.IntRange(1, 10))

This is not valid Go, so in v0.6.1 mfd-generator dbtest fails to format
the output and aborts on any model with a non-nullable column mapped to
int32 or int64 (e.g. int8/bigint).

Fix

Cast the fake value first, then assign: toInt64().assign(col) instead of
assign(col).toInt64(), in both ByNameAndType and ByType:

in.TgUserID = int64(gofakeit.IntRange(1, 10))

Tests

  • Add TestFakeFiller_IntCast: int32/int64 columns via ByType and
    ByNameAndType produce the expected statement, and it parses as Go.
    Fails on master, passes with the fix.
  • The newsportal testdata maps all integer columns to int except one
    nullable *int64, which is not faked, so the golden files did not catch
    this.

- Cast the fake value before assignment in ByNameAndType and ByType:
  int64(in.X = ...) is not valid Go and aborted dbtest generation
  for models with int32/int64 columns since #62
- Add TestFakeFiller_IntCast for int32/int64 columns
@sergeyfast
sergeyfast requested a review from DmiTryAgain October 8, 2026 20:58
@sergeyfast
sergeyfast merged commit ddba73e into master Oct 9, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants