package main

import (
	"goweb/database"
	"testing"
)

// func TestAdd(t *testing.T) {
// 	if database.CreateTable() != 0 {
// 		t.Errorf("数据库同步失败")
// 	}

// }

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("并没有找到")
}

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("并没有找到,或者失败")
}
