Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
94 lines
2.6 KiB
Go
94 lines
2.6 KiB
Go
package slurm
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
)
|
|
|
|
func TestSlurmdbInstancesService_GetInstances(t *testing.T) {
|
|
mux := http.NewServeMux()
|
|
mux.HandleFunc("/slurmdb/v0.0.40/instances", func(w http.ResponseWriter, r *http.Request) {
|
|
testMethod(t, r, "GET")
|
|
fmt.Fprint(w, `{"instances": []}`)
|
|
})
|
|
server := httptest.NewServer(mux)
|
|
defer server.Close()
|
|
|
|
client, _ := NewClient(server.URL, nil)
|
|
resp, _, err := client.SlurmdbInstances.GetInstances(context.Background(), nil)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
if resp == nil {
|
|
t.Fatal("expected non-nil response")
|
|
}
|
|
}
|
|
|
|
func TestSlurmdbInstancesService_GetInstancesWithOptions(t *testing.T) {
|
|
mux := http.NewServeMux()
|
|
mux.HandleFunc("/slurmdb/v0.0.40/instances", func(w http.ResponseWriter, r *http.Request) {
|
|
testMethod(t, r, "GET")
|
|
q := r.URL.Query()
|
|
if q.Get("cluster") != "test-cluster" {
|
|
t.Errorf("expected cluster=test-cluster, got %s", q.Get("cluster"))
|
|
}
|
|
if q.Get("extra") != "some-extra" {
|
|
t.Errorf("expected extra=some-extra, got %s", q.Get("extra"))
|
|
}
|
|
if q.Get("instance_id") != "i-12345" {
|
|
t.Errorf("expected instance_id=i-12345, got %s", q.Get("instance_id"))
|
|
}
|
|
if q.Get("instance_type") != "t2.micro" {
|
|
t.Errorf("expected instance_type=t2.micro, got %s", q.Get("instance_type"))
|
|
}
|
|
fmt.Fprint(w, `{"instances": []}`)
|
|
})
|
|
server := httptest.NewServer(mux)
|
|
defer server.Close()
|
|
|
|
client, _ := NewClient(server.URL, nil)
|
|
opts := &GetInstancesOptions{
|
|
Cluster: Ptr("test-cluster"),
|
|
Extra: Ptr("some-extra"),
|
|
InstanceID: Ptr("i-12345"),
|
|
InstanceType: Ptr("t2.micro"),
|
|
}
|
|
resp, _, err := client.SlurmdbInstances.GetInstances(context.Background(), opts)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
if resp == nil {
|
|
t.Fatal("expected non-nil response")
|
|
}
|
|
}
|
|
|
|
func TestSlurmdbInstancesService_GetInstance(t *testing.T) {
|
|
mux := http.NewServeMux()
|
|
mux.HandleFunc("/slurmdb/v0.0.40/instance", func(w http.ResponseWriter, r *http.Request) {
|
|
testMethod(t, r, "GET")
|
|
fmt.Fprint(w, `{"instances": []}`)
|
|
})
|
|
server := httptest.NewServer(mux)
|
|
defer server.Close()
|
|
|
|
client, _ := NewClient(server.URL, nil)
|
|
resp, _, err := client.SlurmdbInstances.GetInstance(context.Background(), nil)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
if resp == nil {
|
|
t.Fatal("expected non-nil response")
|
|
}
|
|
}
|
|
|
|
func TestSlurmdbInstancesService_GetInstances_InvalidURL(t *testing.T) {
|
|
client, _ := NewClient("http://invalid-host-does-not-exist.local", nil)
|
|
_, _, err := client.SlurmdbInstances.GetInstances(context.Background(), nil)
|
|
if err == nil {
|
|
t.Fatal("expected error for invalid URL")
|
|
}
|
|
}
|