feat(slurmdb): add TresService
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
82
internal/slurm/slurmdb_tres_test.go
Normal file
82
internal/slurm/slurmdb_tres_test.go
Normal file
@@ -0,0 +1,82 @@
|
||||
package slurm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSlurmdbTresService_GetTres(t *testing.T) {
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/slurmdb/v0.0.40/tres", func(w http.ResponseWriter, r *http.Request) {
|
||||
testMethod(t, r, "GET")
|
||||
fmt.Fprint(w, `{"TRES": [{"type": "cpu", "id": 1, "count": 100}]}`)
|
||||
})
|
||||
server := httptest.NewServer(mux)
|
||||
defer server.Close()
|
||||
|
||||
client, _ := NewClient(server.URL, nil)
|
||||
resp, _, err := client.SlurmdbTres.GetTres(context.Background())
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if resp == nil {
|
||||
t.Fatal("expected non-nil response")
|
||||
}
|
||||
if len(resp.TRES) != 1 {
|
||||
t.Fatalf("expected 1 TRES entry, got %d", len(resp.TRES))
|
||||
}
|
||||
if *resp.TRES[0].Type != "cpu" {
|
||||
t.Errorf("expected TRES type 'cpu', got %q", *resp.TRES[0].Type)
|
||||
}
|
||||
if *resp.TRES[0].ID != 1 {
|
||||
t.Errorf("expected TRES id 1, got %d", *resp.TRES[0].ID)
|
||||
}
|
||||
if *resp.TRES[0].Count != 100 {
|
||||
t.Errorf("expected TRES count 100, got %d", *resp.TRES[0].Count)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSlurmdbTresService_PostTres(t *testing.T) {
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/slurmdb/v0.0.40/tres", func(w http.ResponseWriter, r *http.Request) {
|
||||
testMethod(t, r, "POST")
|
||||
fmt.Fprint(w, `{"TRES": []}`)
|
||||
})
|
||||
server := httptest.NewServer(mux)
|
||||
defer server.Close()
|
||||
|
||||
client, _ := NewClient(server.URL, nil)
|
||||
resp, _, err := client.SlurmdbTres.PostTres(context.Background(), &OpenapiTresResp{})
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if resp == nil {
|
||||
t.Fatal("expected non-nil response")
|
||||
}
|
||||
if len(resp.TRES) != 0 {
|
||||
t.Errorf("expected empty TRES, got %d entries", len(resp.TRES))
|
||||
}
|
||||
}
|
||||
|
||||
func TestSlurmdbTresService_GetTres_Error(t *testing.T) {
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/slurmdb/v0.0.40/tres", 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.SlurmdbTres.GetTres(context.Background())
|
||||
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