pcm-participant/cloud/service/service_test.go

136 lines
5.4 KiB
Go

package service
import (
"context"
"fmt"
"github.com/smartystreets/goconvey/convey"
"gitlink.org.cn/JointCloud/pcm-participant-cloud/container"
"gitlink.org.cn/JointCloud/pcm-participant-cloud/platform"
eci "gitlink.org.cn/JointCloud/pcm-participant-eci"
k8s "gitlink.org.cn/JointCloud/pcm-participant-k8s"
"testing"
"time"
)
func TestCreateService(t *testing.T) {
convey.Convey("Test Service", t, func() {
k8s, err := k8s.New("", "", platform.Id(123))
if err != nil {
t.Fatalf("failed to create k8s client: %v", err)
}
eci, err := eci.New("", "", "cn-hangzhou", platform.Id(456))
if err != nil {
t.Fatalf("failed to create eci client: %v", err)
}
svc, err := NewService(k8s, eci)
if err != nil {
t.Fatalf("failed to create service: %v", err)
}
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
convey.Convey("all train algorithms", func() {
param := container.CreateParam{
ContainerGroupName: "hello-llama",
Image: "ghcr.io/ggml-org/llama.cpp:server",
//Image: "nginx:latest",
Name: "hello-llama",
Args: []string{"-m", "/models/ERNIE-4.5-0.3B-PT-GGUF/ernie-4.5-0.3b-pt-q4_k_m.gguf", "--port", "8000", "--host", "0.0.0.0", "-n", "512"},
MountPath: "/models",
Port: 8000,
NodePort: 30000,
Cpu: "100m",
Memory: "256Mi",
}
ctn, err := svc.CreateContainer(ctx, "123", &param)
if err != nil {
fmt.Println(err)
}
convey.So(err, convey.ShouldBeNil)
convey.So(ctn, convey.ShouldNotBeEmpty)
})
})
}
func TestDeleteService(t *testing.T) {
convey.Convey("Test Service", t, func() {
k8s, err := k8s.New("eyJhbGciOiJSUzI1NiIsImtpZCI6IkNzNXRMOE5VdWdiVHJ2U2JtU3ZKWk5razRwZlJHWWZmV3M0aVNHLUJJOHMifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJhZG1pbi11c2VyLXRva2VuLTg0bW5sIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQubmFtZSI6ImFkbWluLXVzZXIiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC51aWQiOiJjOWU1NjU1OC1lZTRhLTQ1MGUtYTljNy03NGNhNDU4NzEyNGEiLCJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6a3ViZS1zeXN0ZW06YWRtaW4tdXNlciJ9.IxXITCqR8Yv-C3mkC3ItwkDLhNueFk_HMF7QhFtjch8miVhUYH3g2Uh70EB5M_3F8vZIF3CoYd3TLG_1acg2JR9Tf7Ipiwzol3npXIqG27QQJ-px3q2i3CMqwjogKjCSEMWTxHS03CDOCJUFLL2qKIa4U-QmEUYnbOFnNsoXDr7zkgRyREi5QUqlEB1ODMlEy8wb6n1g8E9AqNxnYBeHywAAS8ZMkTiKlEdhi-7Jgblkcssmb_P_5xbWelIy6HfBZuumJICzd8b5JRrkX7m7MaIx4TgNETa17kCFi1JnC6MvC1u3UGQQ7MKiXrud06cN9Sphgnu5nIkFjF5TWpSuaA", "https://119.45.100.73:6443", platform.Id(123))
if err != nil {
t.Fatalf("failed to create k8s client: %v", err)
}
eci, err := eci.New("LTAI5tLdKjnos44aLvN1XWJk", "FIF0zpGpA8Q0dEraw28VAUTKg7sVLR", "cn-hangzhou", platform.Id(456))
if err != nil {
t.Fatalf("failed to create eci client: %v", err)
}
svc, err := NewService(k8s, eci)
if err != nil {
t.Fatalf("failed to create service: %v", err)
}
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
convey.Convey("all train algorithms", func() {
param := container.DeleteParam{
//DeleteParameter: &container.EciDeleteParam{
//RegionId: "cn-hangzhou",
//ContainerGroupId: "eci-bp1f6qix5wkkeqhzoc77",
//},
Name: "hello-llama",
}
err := svc.DeleteContainer(ctx, "123", &param)
if err != nil {
fmt.Println(err)
}
convey.So(err, convey.ShouldBeNil)
convey.So(nil, convey.ShouldNotBeEmpty)
})
})
}
func TestGetService(t *testing.T) {
convey.Convey("Test Service", t, func() {
k8s, err := k8s.New("eyJhbGciOiJSUzI1NiIsImtpZCI6IkNzNXRMOE5VdWdiVHJ2U2JtU3ZKWk5razRwZlJHWWZmV3M0aVNHLUJJOHMifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJhZG1pbi11c2VyLXRva2VuLTg0bW5sIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQubmFtZSI6ImFkbWluLXVzZXIiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC51aWQiOiJjOWU1NjU1OC1lZTRhLTQ1MGUtYTljNy03NGNhNDU4NzEyNGEiLCJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6a3ViZS1zeXN0ZW06YWRtaW4tdXNlciJ9.IxXITCqR8Yv-C3mkC3ItwkDLhNueFk_HMF7QhFtjch8miVhUYH3g2Uh70EB5M_3F8vZIF3CoYd3TLG_1acg2JR9Tf7Ipiwzol3npXIqG27QQJ-px3q2i3CMqwjogKjCSEMWTxHS03CDOCJUFLL2qKIa4U-QmEUYnbOFnNsoXDr7zkgRyREi5QUqlEB1ODMlEy8wb6n1g8E9AqNxnYBeHywAAS8ZMkTiKlEdhi-7Jgblkcssmb_P_5xbWelIy6HfBZuumJICzd8b5JRrkX7m7MaIx4TgNETa17kCFi1JnC6MvC1u3UGQQ7MKiXrud06cN9Sphgnu5nIkFjF5TWpSuaA", "https://119.45.100.73:6443", platform.Id(123))
if err != nil {
t.Fatalf("failed to create k8s client: %v", err)
}
eci, err := eci.New("LTAI5tLdKjnos44aLvN1XWJk", "FIF0zpGpA8Q0dEraw28VAUTKg7sVLR", "cn-hangzhou", platform.Id(456))
if err != nil {
t.Fatalf("failed to create eci client: %v", err)
}
svc, err := NewService(k8s, eci)
if err != nil {
t.Fatalf("failed to create service: %v", err)
}
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
convey.Convey("all train algorithms", func() {
param := container.GetParam{
Name: "hello-nginx",
GetParameter: &container.EciGetParam{},
}
resp, err := svc.GetContainer(ctx, "456", &param)
if err != nil {
fmt.Println(err)
}
fmt.Println(resp)
convey.So(err, convey.ShouldBeNil)
convey.So(resp, convey.ShouldNotBeEmpty)
})
})
}