go_echo_wol/main_test.go

58 lines
1.2 KiB
Go
Raw Normal View History

2023-09-04 18:00:09 +08:00
package main
import (
"goweb/database"
2023-09-04 18:00:09 +08:00
"testing"
)
// func TestAdd(t *testing.T) {
// if database.CreateTable() != 0 {
// t.Errorf("数据库同步失败")
// }
// }
2023-09-04 18:00:09 +08:00
func TestAdd_Delwol(t *testing.T) {
wol := new(database.Wol)
wol.Mac = "8F:26:58:C1:85:83"
wol.Name = "text"
database.Insert(wol)
wolarray := make([]database.Wol, 0)
database.Getallwol(&wolarray)
for _, item := range wolarray {
if item.Name == wol.Name {
database.Del(item.ID)
return
}
}
t.Errorf("并没有找到")
2023-09-04 18:00:09 +08:00
}
2023-09-15 10:57:29 +08:00
func TestEdi_wol(t *testing.T) {
wol := new(database.Wol)
wol.Mac = "8F:26:58:C1:85:83"
wol.Name = "text1"
database.Insert(wol)
wolarray := make([]database.Wol, 0)
database.Getallwol(&wolarray)
var idReturnedOnInsertion int64 = -1
for _, item := range wolarray {
if item.Mac == wol.Mac && item.Name == wol.Name {
idReturnedOnInsertion = item.ID
break
}
}
wol2 := new(database.Wol)
wol2.Name = "testchang"
wol2.Mac = "97:88:90:99:8D:93"
database.Edi(wol2, idReturnedOnInsertion)
changwoled := new(database.Wol)
database.GetWolById(idReturnedOnInsertion, changwoled)
if changwoled.Mac == wol2.Mac && changwoled.Name == wol2.Name {
database.Del(idReturnedOnInsertion)
return
}
t.Errorf("并没有找到,或者失败")
}