pcm-participant/ai/service/service_test.go

69 lines
1.7 KiB
Go

package service
import (
"context"
"fmt"
json "github.com/json-iterator/go"
"github.com/smartystreets/goconvey/convey"
aiconf "gitlink.org.cn/JointCloud/pcm-participant-ai/config"
"gitlink.org.cn/JointCloud/pcm-participant-ai/platform"
openI "gitlink.org.cn/JointCloud/pcm-participant-openi"
"gitlink.org.cn/JointCloud/pcm-participant-openi/common"
"testing"
"time"
)
func TestService(t *testing.T) {
convey.Convey("Test Service", t, func() {
o, _ := openI.New(aiconf.Cfg[aiconf.OpenI].Username, aiconf.Cfg[aiconf.OpenI].Password, aiconf.Cfg[aiconf.OpenI].APIKey, platform.Id(123), aiconf.Cfg[aiconf.OpenI].DataRepo)
//oct, _ := octopus.New(aiconf.Cfg[aiconf.Octopus].URL, aiconf.Cfg[aiconf.Octopus].Username, aiconf.Cfg[aiconf.Octopus].Password, platform.Id(456))
common.InitClient()
svc, err := NewService(o)
if err != nil {
}
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
convey.Convey("all train algorithms", func() {
algorithms, err := svc.AllTrainAlgorithms(ctx)
if err != nil {
fmt.Println(err)
}
convey.So(err, convey.ShouldBeNil)
convey.So(algorithms, convey.ShouldNotBeEmpty)
for _, algorithm := range algorithms {
marshal, err := json.Marshal(algorithm)
if err != nil {
return
}
fmt.Println(string(marshal))
}
})
convey.Convey("all train resources", func() {
resources, err := svc.AllTrainResources(ctx)
if err != nil {
fmt.Println(err)
}
convey.So(err, convey.ShouldBeNil)
convey.So(resources, convey.ShouldNotBeEmpty)
for _, res := range resources {
marshal, err := json.Marshal(res)
if err != nil {
return
}
fmt.Println(string(marshal))
}
})
})
}