feat: 添加 Shares 公平共享类型和 SharesService
包含 SharesRespMsg、AssocSharesObjWrap、TRES 明细等类型。SharesService 提供 GetShares 方法,支持按 accounts 和 users 查询。 Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
84
internal/slurm/slurm_shares_test.go
Normal file
84
internal/slurm/slurm_shares_test.go
Normal file
@@ -0,0 +1,84 @@
|
||||
package slurm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSharesService_GetShares(t *testing.T) {
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/slurm/v0.0.40/shares", func(w http.ResponseWriter, r *http.Request) {
|
||||
testMethod(t, r, "GET")
|
||||
fmt.Fprint(w, `{"shares": {"shares": [], "total_shares": 100}}`)
|
||||
})
|
||||
server := httptest.NewServer(mux)
|
||||
defer server.Close()
|
||||
|
||||
client, _ := NewClient(server.URL, nil)
|
||||
resp, _, err := client.Shares.GetShares(context.Background(), nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if resp == nil {
|
||||
t.Fatal("expected non-nil response")
|
||||
}
|
||||
if resp.Shares == nil {
|
||||
t.Fatal("expected non-nil shares")
|
||||
}
|
||||
if resp.Shares.TotalShares == nil || *resp.Shares.TotalShares != 100 {
|
||||
t.Errorf("expected total_shares=100, got %v", resp.Shares.TotalShares)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSharesService_GetShares_WithOptions(t *testing.T) {
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/slurm/v0.0.40/shares", func(w http.ResponseWriter, r *http.Request) {
|
||||
testMethod(t, r, "GET")
|
||||
q := r.URL.Query()
|
||||
if q.Get("accounts") != "acc1" {
|
||||
t.Errorf("expected accounts=acc1, got %s", q.Get("accounts"))
|
||||
}
|
||||
if q.Get("users") != "user1" {
|
||||
t.Errorf("expected users=user1, got %s", q.Get("users"))
|
||||
}
|
||||
fmt.Fprint(w, `{"shares": {"shares": [], "total_shares": 50}}`)
|
||||
})
|
||||
server := httptest.NewServer(mux)
|
||||
defer server.Close()
|
||||
|
||||
client, _ := NewClient(server.URL, nil)
|
||||
opts := &GetSharesOptions{
|
||||
Accounts: Ptr("acc1"),
|
||||
Users: Ptr("user1"),
|
||||
}
|
||||
resp, _, err := client.Shares.GetShares(context.Background(), opts)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if resp == nil {
|
||||
t.Fatal("expected non-nil response")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSharesService_GetShares_Error(t *testing.T) {
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/slurm/v0.0.40/shares", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
fmt.Fprint(w, `{"errors": [{"error": "internal error"}]}`)
|
||||
})
|
||||
server := httptest.NewServer(mux)
|
||||
defer server.Close()
|
||||
|
||||
client, _ := NewClient(server.URL, nil)
|
||||
_, _, err := client.Shares.GetShares(context.Background(), nil)
|
||||
if err == nil {
|
||||
t.Fatal("expected error for 500 response")
|
||||
}
|
||||
if !strings.Contains(err.Error(), "500") {
|
||||
t.Errorf("expected error to contain 500, got %v", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user