/
fake_serve_httpclient.go
81 lines (64 loc) · 2.22 KB
/
fake_serve_httpclient.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package utils
import (
"context"
"fmt"
"net/http"
"sync/atomic"
rayv1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1"
)
type FakeRayDashboardClient struct {
BaseDashboardClient
multiAppStatuses map[string]*ServeApplicationStatus
serveDetails ServeDetails
GetJobInfoMock atomic.Pointer[func(context.Context, string) (*RayJobInfo, error)]
}
var _ RayDashboardClientInterface = (*FakeRayDashboardClient)(nil)
func (r *FakeRayDashboardClient) InitClient(url string) {
r.client = http.Client{}
r.dashboardURL = "http://" + url
}
func (r *FakeRayDashboardClient) UpdateDeployments(_ context.Context, configJson []byte) error {
fmt.Print("UpdateDeployments fake succeeds.")
return nil
}
func (r *FakeRayDashboardClient) GetMultiApplicationStatus(_ context.Context) (map[string]*ServeApplicationStatus, error) {
return r.multiAppStatuses, nil
}
func (r *FakeRayDashboardClient) GetServeDetails(_ context.Context) (*ServeDetails, error) {
return &r.serveDetails, nil
}
func (r *FakeRayDashboardClient) SetMultiApplicationStatuses(statuses map[string]*ServeApplicationStatus) {
r.multiAppStatuses = statuses
}
func (r *FakeRayDashboardClient) GetJobInfo(ctx context.Context, jobId string) (*RayJobInfo, error) {
if mock := r.GetJobInfoMock.Load(); mock != nil {
return (*mock)(ctx, jobId)
}
return &RayJobInfo{JobStatus: rayv1.JobStatusRunning}, nil
}
func (r *FakeRayDashboardClient) ListJobs(ctx context.Context) (*[]RayJobInfo, error) {
if mock := r.GetJobInfoMock.Load(); mock != nil {
info, err := (*mock)(ctx, "job_id")
if err != nil {
return nil, err
}
return &[]RayJobInfo{*info}, nil
}
return nil, nil
}
func (r *FakeRayDashboardClient) SubmitJob(_ context.Context, rayJob *rayv1.RayJob) (jobId string, err error) {
return "", nil
}
func (r *FakeRayDashboardClient) SubmitJobReq(_ context.Context, request *RayJobRequest, name *string) (string, error) {
return "", nil
}
func (r *FakeRayDashboardClient) GetJobLog(_ context.Context, jobName string) (*string, error) {
lg := "log"
return &lg, nil
}
func (r *FakeRayDashboardClient) StopJob(_ context.Context, jobName string) (err error) {
return nil
}
func (r *FakeRayDashboardClient) DeleteJob(_ context.Context, jobName string) error {
return nil
}