优化数据库结构与数据插入逻辑
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"platform/pkg/remote"
|
||||
"platform/pkg/testutil"
|
||||
"platform/web/common"
|
||||
"platform/web/models"
|
||||
"reflect"
|
||||
"strings"
|
||||
@@ -116,7 +117,7 @@ func Test_cache(t *testing.T) {
|
||||
UserID: 100,
|
||||
ProxyID: 10,
|
||||
ProxyPort: 8080,
|
||||
Protocol: "http",
|
||||
Protocol: 1,
|
||||
Expiration: expiration,
|
||||
},
|
||||
{
|
||||
@@ -124,7 +125,7 @@ func Test_cache(t *testing.T) {
|
||||
UserID: 101,
|
||||
ProxyID: 11,
|
||||
ProxyPort: 8081,
|
||||
Protocol: "socks5",
|
||||
Protocol: 3,
|
||||
Expiration: expiration,
|
||||
},
|
||||
}
|
||||
@@ -330,7 +331,7 @@ func Test_channelService_CreateChannel(t *testing.T) {
|
||||
ResourceID: 1,
|
||||
Type: 1,
|
||||
Live: 180,
|
||||
Expire: time.Now().AddDate(1, 0, 0),
|
||||
Expire: common.LocalDateTime(time.Now().AddDate(1, 0, 0)),
|
||||
DailyLimit: 10000,
|
||||
}
|
||||
db.Create(resourcePss)
|
||||
@@ -419,8 +420,8 @@ func Test_channelService_CreateChannel(t *testing.T) {
|
||||
// 验证结果
|
||||
var gotMap = make(map[int]PortInfo)
|
||||
for _, port := range got {
|
||||
if port.Proto != "http" {
|
||||
return fmt.Errorf("期望协议为 http,得到 %s", port.Proto)
|
||||
if port.Proto != 1 {
|
||||
return fmt.Errorf("期望协议为 1(http),得到 %d", port.Proto)
|
||||
}
|
||||
if port.Host != proxy.Host {
|
||||
return fmt.Errorf("期望主机为 %s,得到 %s", proxy.Host, port.Host)
|
||||
@@ -432,8 +433,8 @@ func Test_channelService_CreateChannel(t *testing.T) {
|
||||
var channels []*models.Channel
|
||||
db.Where("user_id = ? and deleted_at is null", userAuth.Payload.Id).Find(&channels)
|
||||
for _, ch := range channels {
|
||||
if ch.Protocol != "http" {
|
||||
return fmt.Errorf("通道协议不正确,期望 http,得到 %s", ch.Protocol)
|
||||
if ch.Protocol != 1 {
|
||||
return fmt.Errorf("通道协议不正确,期望 1(http),得到 %d", ch.Protocol)
|
||||
}
|
||||
if ch.UserID != userAuth.Payload.Id {
|
||||
return fmt.Errorf("通道用户ID不正确,期望 %d,得到 %d", userAuth.Payload.Id, ch.UserID)
|
||||
@@ -449,8 +450,8 @@ func Test_channelService_CreateChannel(t *testing.T) {
|
||||
if ch.AuthPass != true && ch.AuthIP != false {
|
||||
return fmt.Errorf("通道认证类型不正确,期望 Pass,得到 %v", ch.AuthPass)
|
||||
}
|
||||
if ch.Protocol != info.Proto {
|
||||
return fmt.Errorf("通道协议不正确,期望 %s,得到 %s", info.Proto, ch.Protocol)
|
||||
if ch.Protocol != int32(info.Proto) {
|
||||
return fmt.Errorf("通道协议不正确,期望 %d,得到 %d", info.Proto, ch.Protocol)
|
||||
}
|
||||
if ch.Username != *info.Username {
|
||||
return fmt.Errorf("通道用户名不正确,期望 %s,得到 %s", *info.Username, ch.Username)
|
||||
@@ -485,7 +486,7 @@ func Test_channelService_CreateChannel(t *testing.T) {
|
||||
if pss.DailyUsed != 3 {
|
||||
return fmt.Errorf("套餐每日用量不正确,期望 3,得到 %d", pss.DailyUsed)
|
||||
}
|
||||
if pss.DailyLast.IsZero() {
|
||||
if time.Time(pss.DailyLast).IsZero() {
|
||||
return fmt.Errorf("套餐每日最后更新时间不应为空")
|
||||
}
|
||||
if pss.Used != 3 {
|
||||
@@ -569,8 +570,8 @@ func Test_channelService_CreateChannel(t *testing.T) {
|
||||
// 验证结果
|
||||
var gotMap = make(map[int]PortInfo)
|
||||
for _, port := range got {
|
||||
if port.Proto != "http" {
|
||||
return fmt.Errorf("期望协议为 http,得到 %s", port.Proto)
|
||||
if port.Proto != 1 {
|
||||
return fmt.Errorf("期望协议为 1(http),得到 %d", port.Proto)
|
||||
}
|
||||
if port.Host != proxy.Host {
|
||||
return fmt.Errorf("期望主机为 %s,得到 %s", proxy.Host, port.Host)
|
||||
@@ -582,8 +583,8 @@ func Test_channelService_CreateChannel(t *testing.T) {
|
||||
var channels []*models.Channel
|
||||
db.Where("user_id = ? and deleted_at is null", userAuth.Payload.Id).Find(&channels)
|
||||
for _, ch := range channels {
|
||||
if ch.Protocol != "http" {
|
||||
return fmt.Errorf("通道协议不正确,期望 http,得到 %s", ch.Protocol)
|
||||
if ch.Protocol != 1 {
|
||||
return fmt.Errorf("通道协议不正确,期望 1(http),得到 %d", ch.Protocol)
|
||||
}
|
||||
if ch.UserID != userAuth.Payload.Id {
|
||||
return fmt.Errorf("通道用户ID不正确,期望 %d,得到 %d", userAuth.Payload.Id, ch.UserID)
|
||||
@@ -599,8 +600,8 @@ func Test_channelService_CreateChannel(t *testing.T) {
|
||||
if ch.AuthPass != false && ch.AuthIP != true {
|
||||
return fmt.Errorf("通道认证类型不正确,期望 Pass,得到 %v", ch.AuthPass)
|
||||
}
|
||||
if ch.Protocol != info.Proto {
|
||||
return fmt.Errorf("通道协议不正确,期望 %s,得到 %s", info.Proto, ch.Protocol)
|
||||
if ch.Protocol != int32(info.Proto) {
|
||||
return fmt.Errorf("通道协议不正确,期望 %d,得到 %d", info.Proto, ch.Protocol)
|
||||
}
|
||||
if ch.Expiration.IsZero() {
|
||||
return fmt.Errorf("通道过期时间不应为空")
|
||||
@@ -629,7 +630,7 @@ func Test_channelService_CreateChannel(t *testing.T) {
|
||||
if pss.DailyUsed != 3 {
|
||||
return fmt.Errorf("套餐每日用量不正确,期望 3,得到 %d", pss.DailyUsed)
|
||||
}
|
||||
if pss.DailyLast.IsZero() {
|
||||
if time.Time(pss.DailyLast).IsZero() {
|
||||
return fmt.Errorf("套餐每日最后更新时间不应为空")
|
||||
}
|
||||
if pss.Used != 3 {
|
||||
@@ -713,8 +714,8 @@ func Test_channelService_CreateChannel(t *testing.T) {
|
||||
// 验证结果
|
||||
var gotMap = make(map[int]PortInfo)
|
||||
for _, port := range got {
|
||||
if port.Proto != "socks5" {
|
||||
return fmt.Errorf("期望协议为 http,得到 %s", port.Proto)
|
||||
if port.Proto != 3 {
|
||||
return fmt.Errorf("期望协议为 1(http),得到 %d", port.Proto)
|
||||
}
|
||||
if port.Host != proxy.Host {
|
||||
return fmt.Errorf("期望主机为 %s,得到 %s", proxy.Host, port.Host)
|
||||
@@ -726,8 +727,8 @@ func Test_channelService_CreateChannel(t *testing.T) {
|
||||
var channels []*models.Channel
|
||||
db.Where("user_id = ? and deleted_at is null", userAuth.Payload.Id).Find(&channels)
|
||||
for _, ch := range channels {
|
||||
if ch.Protocol != "http" {
|
||||
return fmt.Errorf("通道协议不正确,期望 http,得到 %s", ch.Protocol)
|
||||
if ch.Protocol != 1 {
|
||||
return fmt.Errorf("通道协议不正确,期望 1(http),得到 %d", ch.Protocol)
|
||||
}
|
||||
if ch.UserID != userAuth.Payload.Id {
|
||||
return fmt.Errorf("通道用户ID不正确,期望 %d,得到 %d", userAuth.Payload.Id, ch.UserID)
|
||||
@@ -743,8 +744,8 @@ func Test_channelService_CreateChannel(t *testing.T) {
|
||||
if ch.AuthPass != true && ch.AuthIP != false {
|
||||
return fmt.Errorf("通道认证类型不正确,期望 Pass,得到 %v", ch.AuthPass)
|
||||
}
|
||||
if ch.Protocol != info.Proto {
|
||||
return fmt.Errorf("通道协议不正确,期望 %s,得到 %s", info.Proto, ch.Protocol)
|
||||
if ch.Protocol != int32(info.Proto) {
|
||||
return fmt.Errorf("通道协议不正确,期望 %d,得到 %d", info.Proto, ch.Protocol)
|
||||
}
|
||||
if ch.Username != *info.Username {
|
||||
return fmt.Errorf("通道用户名不正确,期望 %s,得到 %s", *info.Username, ch.Username)
|
||||
@@ -779,7 +780,7 @@ func Test_channelService_CreateChannel(t *testing.T) {
|
||||
if pss.DailyUsed != 3 {
|
||||
return fmt.Errorf("套餐每日用量不正确,期望 3,得到 %d", pss.DailyUsed)
|
||||
}
|
||||
if pss.DailyLast.IsZero() {
|
||||
if time.Time(pss.DailyLast).IsZero() {
|
||||
return fmt.Errorf("套餐每日最后更新时间不应为空")
|
||||
}
|
||||
if pss.Used != 3 {
|
||||
@@ -831,7 +832,7 @@ func Test_channelService_CreateChannel(t *testing.T) {
|
||||
ResourceID: 2,
|
||||
Type: 1,
|
||||
Live: 180,
|
||||
Expire: time.Now().AddDate(1, 0, 0),
|
||||
Expire: common.LocalDateTime(time.Now().AddDate(1, 0, 0)),
|
||||
DailyLimit: 10000,
|
||||
}
|
||||
db.Create(resourcePss2)
|
||||
@@ -1022,9 +1023,9 @@ func Test_channelService_RemoveChannels(t *testing.T) {
|
||||
|
||||
// 创建通道
|
||||
channels := []models.Channel{
|
||||
{ID: 1, UserID: 101, ProxyID: 1, ProxyPort: 10001, Protocol: "http", Expiration: time.Now().Add(24 * time.Hour)},
|
||||
{ID: 2, UserID: 101, ProxyID: 1, ProxyPort: 10002, Protocol: "http", Expiration: time.Now().Add(24 * time.Hour)},
|
||||
{ID: 3, UserID: 101, ProxyID: 2, ProxyPort: 10001, Protocol: "socks5", Expiration: time.Now().Add(24 * time.Hour)},
|
||||
{ID: 1, UserID: 101, ProxyID: 1, ProxyPort: 10001, Protocol: 1, Expiration: time.Now().Add(24 * time.Hour)},
|
||||
{ID: 2, UserID: 101, ProxyID: 1, ProxyPort: 10002, Protocol: 1, Expiration: time.Now().Add(24 * time.Hour)},
|
||||
{ID: 3, UserID: 101, ProxyID: 2, ProxyPort: 10001, Protocol: 3, Expiration: time.Now().Add(24 * time.Hour)},
|
||||
}
|
||||
|
||||
// 保存预设数据
|
||||
@@ -1136,9 +1137,9 @@ func Test_channelService_RemoveChannels(t *testing.T) {
|
||||
|
||||
// 创建通道
|
||||
channels := []models.Channel{
|
||||
{ID: 1, UserID: 101, ProxyID: 1, ProxyPort: 10001, Protocol: "http", Expiration: time.Now().Add(24 * time.Hour)},
|
||||
{ID: 2, UserID: 101, ProxyID: 1, ProxyPort: 10002, Protocol: "http", Expiration: time.Now().Add(24 * time.Hour)},
|
||||
{ID: 3, UserID: 101, ProxyID: 2, ProxyPort: 10001, Protocol: "socks5", Expiration: time.Now().Add(24 * time.Hour)},
|
||||
{ID: 1, UserID: 101, ProxyID: 1, ProxyPort: 10001, Protocol: 1, Expiration: time.Now().Add(24 * time.Hour)},
|
||||
{ID: 2, UserID: 101, ProxyID: 1, ProxyPort: 10002, Protocol: 1, Expiration: time.Now().Add(24 * time.Hour)},
|
||||
{ID: 3, UserID: 101, ProxyID: 2, ProxyPort: 10001, Protocol: 3, Expiration: time.Now().Add(24 * time.Hour)},
|
||||
}
|
||||
|
||||
// 保存预设数据
|
||||
@@ -1250,9 +1251,9 @@ func Test_channelService_RemoveChannels(t *testing.T) {
|
||||
|
||||
// 创建通道
|
||||
channels := []models.Channel{
|
||||
{ID: 1, UserID: 101, ProxyID: 1, ProxyPort: 10001, Protocol: "http", Expiration: time.Now().Add(24 * time.Hour)},
|
||||
{ID: 2, UserID: 101, ProxyID: 1, ProxyPort: 10002, Protocol: "http", Expiration: time.Now().Add(24 * time.Hour)},
|
||||
{ID: 3, UserID: 102, ProxyID: 2, ProxyPort: 10001, Protocol: "socks5", Expiration: time.Now().Add(24 * time.Hour)},
|
||||
{ID: 1, UserID: 101, ProxyID: 1, ProxyPort: 10001, Protocol: 1, Expiration: time.Now().Add(24 * time.Hour)},
|
||||
{ID: 2, UserID: 101, ProxyID: 1, ProxyPort: 10002, Protocol: 1, Expiration: time.Now().Add(24 * time.Hour)},
|
||||
{ID: 3, UserID: 102, ProxyID: 2, ProxyPort: 10001, Protocol: 3, Expiration: time.Now().Add(24 * time.Hour)},
|
||||
}
|
||||
|
||||
// 保存预设数据
|
||||
|
||||
Reference in New Issue
Block a user