generated from PenaSide/GolangTemplate
54 lines
1.0 KiB
Go
54 lines
1.0 KiB
Go
package e2e
|
|
|
|
import (
|
|
"bufio"
|
|
"fmt"
|
|
"github.com/stretchr/testify/assert"
|
|
"net/http"
|
|
"penahub.gitlab.yandexcloud.net/pena-services/customer/tests/helpers"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestAccountPipe(t *testing.T) {
|
|
url := "http://localhost:8082/account/pipe"
|
|
jwtUtil := helpers.InitializeJWT()
|
|
|
|
token, tokenErr := jwtUtil.Create("64e53ed187392e122e5d3d50")
|
|
if !assert.NoError(t, tokenErr) {
|
|
return
|
|
}
|
|
|
|
client := &http.Client{
|
|
Timeout: 100 * time.Second,
|
|
}
|
|
|
|
req, err := http.NewRequest("GET", url, nil)
|
|
if !assert.NoError(t, err) {
|
|
return
|
|
}
|
|
|
|
req.Header.Set("Authorization", "Bearer "+token)
|
|
req.Header.Set("Accept", "text/event-stream")
|
|
|
|
fmt.Println(token)
|
|
|
|
resp, err := client.Do(req)
|
|
if !assert.NoError(t, err) {
|
|
return
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
assert.Equal(t, http.StatusOK, resp.StatusCode, "Expected status code 200")
|
|
|
|
scanner := bufio.NewScanner(resp.Body)
|
|
for scanner.Scan() {
|
|
line := scanner.Text()
|
|
fmt.Println("Received:", line)
|
|
}
|
|
|
|
if err := scanner.Err(); err != nil {
|
|
t.Fatalf("Error reading response: %v", err)
|
|
}
|
|
}
|