Skip to content

Commit

Permalink
添加单元测试
Browse files Browse the repository at this point in the history
  • Loading branch information
steden committed Dec 29, 2023
1 parent 92a03b6 commit a4f7510
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions test/mapToEntity_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package test

import (
"github.com/farseer-go/mapper"
"github.com/stretchr/testify/assert"
"testing"
)

type BaseEntity struct {
AppId int64 // 应用ID
AppName string // 应用名称
}
type MapEntity struct {
BaseEntity
UserId int
UserName string
}

func TestMapToEntity(t *testing.T) {
m := make(map[string]any)
m["AppId"] = int64(1)
m["AppName"] = "test"
m["UserId"] = 888
m["UserName"] = "steden"
entity := mapper.Single[MapEntity](m)
assert.Equal(t, m["AppId"], entity.AppId)
assert.Equal(t, m["AppName"], entity.AppName)
assert.Equal(t, m["UserId"], entity.UserId)
assert.Equal(t, m["UserName"], entity.UserName)
}

0 comments on commit a4f7510

Please sign in to comment.