-
Notifications
You must be signed in to change notification settings - Fork 0
/
main-test.go
52 lines (41 loc) · 1.32 KB
/
main-test.go
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
package main
import (
"net/http"
"net/http/httptest"
"strings"
"testing"
)
func TestEncryptHandler(t *testing.T) {
reqBody := `{"value": "test_value"}`
req, err := http.NewRequest("POST", "/api/encrypt", strings.NewReader(reqBody))
if err != nil {
t.Fatal(err)
}
rr := httptest.NewRecorder()
handler := http.HandlerFunc(EncryptHandler)
handler.ServeHTTP(rr, req)
if status := rr.Code; status != http.StatusOK {
t.Errorf("Handler returned wrong status code: got %v want %v", status, http.StatusOK)
}
expected := `{"encrypted_value":"encrypted_value_placeholder"}`
if rr.Body.String() != expected {
t.Errorf("Handler returned unexpected body: got %v want %v", rr.Body.String(), expected)
}
}
func TestDecryptHandler(t *testing.T) {
reqBody := `{"value": "test_value"}`
req, err := http.NewRequest("POST", "/api/decrypt", strings.NewReader(reqBody))
if err != nil {
t.Fatal(err)
}
rr := httptest.NewRecorder()
handler := http.HandlerFunc(DecryptHandler)
handler.ServeHTTP(rr, req)
if status := rr.Code; status != http.StatusOK {
t.Errorf("Handler returned wrong status code: got %v want %v", status, http.StatusOK)
}
expected := `{"encrypted_value":"decrypted_value_placeholder"}`
if rr.Body.String() != expected {
t.Errorf("Handler returned unexpected body: got %v want %v", rr.Body.String(), expected)
}
}