common/structs/storage/article_test.go

65 lines
1.4 KiB
Go
Raw Normal View History

2024-08-04 20:46:49 +08:00
package storage
import (
"fmt"
"testing"
v2 "gitea.timerzz.com/kedaya_haitao/common/structs/v2"
"gorm.io/driver/postgres"
"gorm.io/gorm"
)
func GetDevDB() (*gorm.DB, error) {
dsn := fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%s sslmode=disable TimeZone=Asia/Shanghai", "192.168.31.55", "timerzz", "zhhg1997", "kedaya_dev", "5432")
return gorm.Open(postgres.Open(dsn), &gorm.Config{})
}
var article = v2.Article{
2024-09-03 17:18:48 +08:00
Name: "test2",
EnglishName: "test2",
2024-08-04 20:46:49 +08:00
Pid: "111",
Brand: "col",
Desc: "desc",
Image: "http://123",
Available: false,
2024-09-03 17:18:48 +08:00
CostPrice: 321,
2024-08-04 20:46:49 +08:00
Providers: []v2.ProviderArticle{
{
2024-09-03 17:18:48 +08:00
ID: 1,
2024-08-04 20:46:49 +08:00
Pid: "111",
2024-09-03 17:18:48 +08:00
Brand: "col",
2024-08-04 20:46:49 +08:00
Link: "http://123",
ProviderId: "coach2",
2024-09-03 17:18:48 +08:00
SkuID: "sku2",
2024-08-04 20:46:49 +08:00
Cost: v2.ProviderPrice{
2024-09-03 17:18:48 +08:00
OriginalPrice: 222,
FinalPrice: 222,
CalMark: "aaa",
2024-08-04 20:46:49 +08:00
},
HistoryPrice: []v2.ProviderPrice{
{
2024-09-03 17:18:48 +08:00
OriginalPrice: 222,
FinalPrice: 222,
2024-08-04 20:46:49 +08:00
CalMark: "uuuuu",
},
},
},
},
2024-09-03 17:18:48 +08:00
SellPrice: 222,
2024-08-04 20:46:49 +08:00
Sellers: []v2.SellerArticle{},
2024-09-03 17:18:48 +08:00
Rate: 222,
Remark: "222",
2024-08-04 20:46:49 +08:00
}
func TestUpsetArticle(t *testing.T) {
db, _ := GetDevDB()
storage := NewStorage(db)
err := db.AutoMigrate(&v2.Article{}, &v2.ProviderArticle{}, &v2.ProviderPrice{}, &v2.SellerArticle{}, &v2.SellerPrice{})
if err != nil {
t.Fatal(err)
}
if err = storage.Article().Upsert(article); err != nil {
t.Fatal(err)
}
}