Repository navigation
Expand file tree
/
Copy pathcompute_output_test.go
More file actions
69 lines (60 loc) · 2.19 KB
/
Copy pathcompute_output_test.go
File metadata and controls
69 lines (60 loc) · 2.19 KB
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
package viya
import (
"net/http"
"net/http/httptest"
"net/url"
"testing"
)
func TestGetComputeJobLogDecodesLines(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if got, want := r.URL.Path, "/compute/sessions/session-1/jobs/0/log"; got != want {
t.Fatalf("path = %q, want %q", got, want)
}
if got, want := r.Header.Get("Accept"), "application/json, application/vnd.sas.collection+json;version=2, application/vnd.sas.error+json"; got != want {
t.Fatalf("Accept = %q, want %q", got, want)
}
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(`{"count":2,"items":[{"line":"NOTE: start","type":"note"},{"line":"run;","type":"source"}]}`))
}))
defer server.Close()
u, err := url.Parse(server.URL)
if err != nil {
t.Fatalf("url.Parse() error = %v", err)
}
client := NewClient(t.Context(), WithBaseURL(u))
log, err := client.GetComputeJobLog(t.Context(), "session-1", "0")
if err != nil {
t.Fatalf("GetComputeJobLog() error = %v", err)
}
if got, want := len(log.Items), 2; got != want {
t.Fatalf("len(Items) = %d, want %d", got, want)
}
if got, want := log.Items[0].Type, "note"; got != want {
t.Fatalf("Type = %q, want %q", got, want)
}
}
func TestGetComputeJobListingTextReturnsPlainText(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if got, want := r.URL.Path, "/compute/sessions/session-1/jobs/0/listing"; got != want {
t.Fatalf("path = %q, want %q", got, want)
}
if got, want := r.Header.Get("Accept"), "text/plain, application/vnd.sas.error+json"; got != want {
t.Fatalf("Accept = %q, want %q", got, want)
}
w.Header().Set("Content-Type", "text/plain")
_, _ = w.Write([]byte("listing line\n"))
}))
defer server.Close()
u, err := url.Parse(server.URL)
if err != nil {
t.Fatalf("url.Parse() error = %v", err)
}
client := NewClient(t.Context(), WithBaseURL(u))
text, err := client.GetComputeJobListingText(t.Context(), "session-1", "0")
if err != nil {
t.Fatalf("GetComputeJobListingText() error = %v", err)
}
if got, want := text, "listing line"; got != want {
t.Fatalf("text = %q, want %q", got, want)
}
}