package test import ( aa "goactuator/actuator" pb "goactuator/scalebox" "log" "os" "testing" ) func init() { _=os.Setenv("grpc_server","127.0.0.1:50051") } func TestGetSlotList(t *testing.T){ var want=[] struct{ id int32 host string text string }{ {1,"host-1","docker run -d python:3.8"},{3,"host-1","docker run -d python:3.8"}, } commandList, err := aa.GetRunnableSlotList() if err!=nil{ t.Error(err) } if len(commandList)!=len(want){ t.Error("not what we want") } for i,j:=range commandList{ if j.Id!=want[i].id || j.Host!=want[i].host ||j.CommandText!=want[i].text{ t.Error("wrong value") } } } func TestGetWorkerList(t *testing.T) { cmdList,err:=aa.GetRunnableDaemonList() if err!=nil{ t.Error(err) } for _,cmd:= range cmdList{ log.Printf("id:%v,host:%v,text:%v",cmd.Id,cmd.Host,cmd.CommandText) } } func TestGetTerminatedWorkerList(t *testing.T) { cmdList,err:=aa.GetTerminatedDaemonList() if err!=nil{ t.Error(err) } for _,cmd:= range cmdList{ log.Printf("id:%v,host:%v,text:%v",cmd.Id,cmd.Host,cmd.CommandText) } } func TestSetSlotInit(t *testing.T) { cmdPkg:=pb.Command{ Id: 1, Host: "", CommandText: "", } err:=aa.SetSlotInitialized(&cmdPkg) if err!=nil{ t.Error(err) } }