This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
otter-space-sdk/pkg/models/orm_test.go
soxx 2a752adcac
All checks were successful
Gitea Build Check / Build (push) Successful in 10m49s
test(postgres): added more tests
Signed-off-by: soxx <soxx@fenpa.ws>
2024-06-24 17:07:41 +02:00

56 lines
999 B
Go

package models
import (
"gorm.io/gorm"
"testing"
"time"
)
func TestBaseModel_BeforeCreate(t *testing.T) {
type fields struct {
ID string
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt gorm.DeletedAt
}
type args struct {
db *gorm.DB
}
tests := []struct {
name string
fields fields
args args
wantErr bool
}{
{
name: "Test 1: Prefilled ID",
fields: fields{
ID: "1",
},
args: args{db: nil},
wantErr: false,
},
{
name: "Test 1: Autogenerate ID",
fields: fields{
ID: "",
},
args: args{db: nil},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
base := &BaseModel{
ID: tt.fields.ID,
CreatedAt: tt.fields.CreatedAt,
UpdatedAt: tt.fields.UpdatedAt,
DeletedAt: tt.fields.DeletedAt,
}
if err := base.BeforeCreate(tt.args.db); (err != nil) != tt.wantErr {
t.Errorf("BeforeCreate() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}