data_workshop/case_test.go
huangsimin 27c0277ba8 init
2020-05-19 18:12:18 +08:00

48 lines
1.2 KiB
Go

package main
import (
"encoding/gob"
"os"
"testing"
)
// func TestCheckCountry2(t *testing.T) {
// gob.Register(Country{})
// SaveGob("./data/country.gob", reflect.TypeOf(Country{}), NewKeyKind("country-name-", "Name"), NewKeyKind("country-pic-%s", "Pic"))
// }
// func TestLastName(t *testing.T) {
// gob.Register(Country{})
// ln := &KeyList{}
// LoadGob("./data/lastname.gob", ln)
// t.Error(ln.GetLength(), string(ln.Keys[0].([]byte)))
// nln := KeyList{}
// for _, buf := range ln.Keys {
// lnn := LastName{}
// lnn.Name = buf.([]byte)
// nln.AppendKey(lnn)
// }
// SaveData("./data/lastname-test.gob", nln)
// }
func TestS(t *testing.T) {
gob.Register(Country{})
ln := &KeyList{}
LoadGob("./data/lastname1.gob", ln)
t.Error(len(ln.Keys))
country := ln.Keys[0].(Country)
f, _ := os.OpenFile("./1.png", os.O_CREATE|os.O_TRUNC|os.O_RDWR, os.ModePerm)
f.Write(country.Pic)
}
func TestReadData(t *testing.T) {
gob.Register(Country{})
ln := &KeyList{}
LoadGob("./data/country.gob", ln)
t.Error(len(ln.Keys))
country := ln.Keys[0].(Country)
f, _ := os.OpenFile("./1.png", os.O_CREATE|os.O_TRUNC|os.O_RDWR, os.ModePerm)
f.Write(country.Pic)
}