Skip to content

Commit 2f7b7aa

Browse files
author
Grzegorz Kołakowski
committed
Add client_test.go
1 parent c30bac9 commit 2f7b7aa

1 file changed

Lines changed: 78 additions & 0 deletions

File tree

internal/flink/client_test.go

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package flink
2+
3+
import (
4+
"encoding/json"
5+
"io"
6+
"net/http"
7+
"net/http/httptest"
8+
"testing"
9+
10+
"github.com/go-logr/logr"
11+
"gotest.tools/v3/assert"
12+
)
13+
14+
func TestTriggerSavepointPayload(t *testing.T) {
15+
tests := []struct {
16+
name string
17+
cancel bool
18+
formatType string
19+
expectedBody map[string]interface{}
20+
}{
21+
{
22+
name: "with formatType NATIVE",
23+
formatType: "NATIVE",
24+
expectedBody: map[string]interface{}{
25+
"target-directory": "/savepoints",
26+
"cancel-job": false,
27+
"formatType": "NATIVE",
28+
},
29+
},
30+
{
31+
name: "with formatType CANONICAL",
32+
formatType: "CANONICAL",
33+
expectedBody: map[string]interface{}{
34+
"target-directory": "/savepoints",
35+
"cancel-job": false,
36+
"formatType": "CANONICAL",
37+
},
38+
},
39+
{
40+
name: "without formatType",
41+
formatType: "",
42+
expectedBody: map[string]interface{}{
43+
"target-directory": "/savepoints",
44+
"cancel-job": false,
45+
},
46+
},
47+
{
48+
name: "cancel with formatType",
49+
cancel: true,
50+
formatType: "NATIVE",
51+
expectedBody: map[string]interface{}{
52+
"target-directory": "/savepoints",
53+
"cancel-job": true,
54+
"formatType": "NATIVE",
55+
},
56+
},
57+
}
58+
59+
for _, tt := range tests {
60+
t.Run(tt.name, func(t *testing.T) {
61+
var capturedBody map[string]interface{}
62+
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
63+
body, _ := io.ReadAll(r.Body)
64+
json.Unmarshal(body, &capturedBody)
65+
w.Header().Set("Content-Type", "application/json")
66+
w.Write([]byte(`{"request-id": "abc123"}`))
67+
}))
68+
defer server.Close()
69+
70+
client := NewClient(logr.Discard(), server.Client())
71+
triggerID, err := client.TriggerSavepoint(server.URL, "job-1", "/savepoints", tt.cancel, tt.formatType)
72+
73+
assert.NilError(t, err)
74+
assert.Equal(t, triggerID.RequestID, "abc123")
75+
assert.DeepEqual(t, capturedBody, tt.expectedBody)
76+
})
77+
}
78+
}

0 commit comments

Comments
 (0)