From 5f909b50f81ac3fe5dbbe40a5153ba289ce7c2a9 Mon Sep 17 00:00:00 2001 From: Andrey Ivanov Date: Fri, 6 Nov 2020 19:10:11 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=BA=D0=BB=D0=B8=D0=B5=D0=BD=D1=82=D0=B0=20=D0=BD?= =?UTF-8?q?=D0=B5=D0=BC=D0=BD=D0=BE=D0=B3=D0=BE.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/main_test.go | 15 +++++++++++---- internal/application/query.go | 7 ++----- internal/config/config.go | 2 +- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/cmd/main_test.go b/cmd/main_test.go index ee38484..4e4f0e2 100644 --- a/cmd/main_test.go +++ b/cmd/main_test.go @@ -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 { diff --git a/internal/application/query.go b/internal/application/query.go index 2b075b4..f5f7517 100644 --- a/internal/application/query.go +++ b/internal/application/query.go @@ -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) } diff --git a/internal/config/config.go b/internal/config/config.go index 406c893..b5791e1 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -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