jackc / pgtype

MIT License
314 stars 112 forks source link

Mock pgtype for testing #135

Closed mathiasHillmann closed 3 years ago

mathiasHillmann commented 3 years ago

I have the function coolFunction(arg1 coolStruct) of which the coolStruct is composed of the following fields:

type coolStruct struct {
    id    pgtype.Int4
        foo   pgtype.Numeric
    name  pgtype.Text
}

How can I assign value to the pgtype.* fields for testing?

jackc commented 3 years ago

All the fields are public. You can directly initialize them. e.g. s.id = pgtype.Int4{Int: 42, Status: pgtype.Present} or use the Set method.