Поправил клиента немного.

master
Andrey Ivanov 2020-11-06 19:10:11 +03:00 committed by tiburon
parent 57eaf7ae91
commit 5f909b50f8
3 changed files with 14 additions and 10 deletions

View File

@ -17,7 +17,7 @@ const testPortBase = 3000
func TestIntegrationPositive(t *testing.T) {
testPort := strconv.Itoa(testPortBase + 1)
wg := sync.WaitGroup{}
server := &http.Server{Addr: "localhost:" + testPort, Handler: http.FileServer(http.Dir("./test/data"))}
server := &http.Server{Addr: "localhost:" + testPort, Handler: http.FileServer(http.Dir("../test/data"))}
go func() {
err := server.ListenAndServe()
if err != nil {
@ -31,10 +31,17 @@ func TestIntegrationPositive(t *testing.T) {
//time.Sleep(30*time.Second)
// Реализовать тесты логики приложения (ресайзы по разным требованиям):
wg.Add(2)
wg.Add(3)
t.Run("test static", func(t *testing.T) {
defer wg.Done()
body, resp, err := request("http://localhost:"+testPort+"/gopher_original_1024x504.jpg", 15*time.Second)
require.NoError(t, err)
require.NotNil(t, body)
require.Equal(t, 200, resp.StatusCode)
})
t.Run("remote server return jpeg", func(t *testing.T) {
defer wg.Done()
body, resp, err := request("http://localhost:8080/fill/1024/504/localhost:"+testPort+"/gopher_original_1024x504.jpg", 15*time.Second)
body, resp, err := request("http://localhost:80/fill/1024/504/localhost:"+testPort+"/gopher_original_1024x504.jpg", 15*time.Second)
require.NoError(t, err)
require.NotNil(t, body)
require.Equal(t, 200, resp.StatusCode)
@ -54,7 +61,7 @@ func TestIntegrationPositive(t *testing.T) {
func TestIntegrationNegative(t *testing.T) {
testPort := strconv.Itoa(testPortBase + 2)
wg := sync.WaitGroup{}
server := &http.Server{Addr: "localhost:" + testPort, Handler: http.FileServer(http.Dir("./test/data"))}
server := &http.Server{Addr: "localhost:" + testPort, Handler: http.FileServer(http.Dir("../test/data"))}
go func() {
err := server.ListenAndServe()
if err != nil {

View File

@ -1,7 +1,6 @@
package application
import (
"context"
"errors"
"fmt"
"io/ioutil"
@ -44,10 +43,8 @@ func (q Query) id() string {
}
func (q Query) fromOrigin(headers http.Header, timeout time.Duration) ([]byte, *http.Response, error) {
client := &http.Client{}
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
req, err := http.NewRequestWithContext(ctx, "GET", "http://"+q.URL.Host+q.URL.Path, nil)
client := &http.Client{Timeout: timeout}
req, err := http.NewRequest("GET", "http://"+q.URL.Host+q.URL.Path, nil)
if err != nil {
return nil, nil, fmt.Errorf("can't create request: %w", err)
}

View File

@ -49,7 +49,7 @@ func (c *Config) SetDefault() {
c.Cache = struct {
Capacity int
StoragePath string
}{Capacity: 20, StoragePath: "./assets/cache"}
}{Capacity: 20, StoragePath: "../assets/cache"}
c.Query = struct{ Timeout int }{Timeout: 15}
c.Log = struct {
File string