107 lines
1.6 KiB
Go
107 lines
1.6 KiB
Go
package target
|
|
|
|
import (
|
|
"encoding/json"
|
|
"git.loafle.net/overflow/commons_go/model/timestamp"
|
|
"git.loafle.net/overflow/overflow_service/proxy/infra"
|
|
"git.loafle.net/overflow/overflow_service/proxy/probe"
|
|
"testing"
|
|
|
|
|
|
"io/ioutil"
|
|
"reflect"
|
|
)
|
|
|
|
func TestTargetRegist(t *testing.T) {
|
|
ts := NewTargetService()
|
|
|
|
p := &probe.Probe{}
|
|
p.Id = json.Number("1")
|
|
i := &infra.Infra{}
|
|
i.Id = json.Number("1")
|
|
|
|
target := &Target{
|
|
CreateDate: timestamp.Now(),
|
|
Probe: p,
|
|
Infra: i,
|
|
}
|
|
res, err := ts.Regist(target)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Log(res)
|
|
|
|
}
|
|
|
|
func TestTargetList(t *testing.T) {
|
|
ts := NewTargetService()
|
|
p := &probe.Probe{
|
|
Id: "1",
|
|
}
|
|
res, err := ts.ReadAllByProbe(p)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Log(res)
|
|
}
|
|
|
|
func TestTargetRead(t *testing.T) {
|
|
ts := NewTargetService()
|
|
res, err := ts.Read("1")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Log(res)
|
|
}
|
|
|
|
func TestTargetDelete(t *testing.T) {
|
|
ts := NewTargetService()
|
|
target := &Target{
|
|
Id: "1",
|
|
}
|
|
res, err := ts.Remove(target)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Log(res)
|
|
}
|
|
|
|
func TestTargetDiscovery(t *testing.T) {
|
|
|
|
contents,_ := ioutil.ReadFile("../../dh.json")
|
|
|
|
ti := TargetInfo{}
|
|
|
|
err := json.Unmarshal(contents, &ti)
|
|
|
|
if err != nil{
|
|
t.Fatal(err)
|
|
}
|
|
|
|
t.Log(ti)
|
|
|
|
ts := NewTargetService()
|
|
ppp := probe.Probe{}
|
|
ppp.Id = "1"
|
|
ti.Probe = &ppp
|
|
out, err := ts.RegistTarget(&ti)
|
|
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
t.Log(out)
|
|
}
|
|
|
|
func TestInterface(t *testing.T) {
|
|
|
|
aaa := &infra.InfraMachine{}
|
|
|
|
var o interface{} = aaa
|
|
|
|
tt := reflect.TypeOf(o)
|
|
t.Log(tt.Name())
|
|
t.Log(tt.String())
|
|
|
|
}
|