Исправил лайаут. Починил интеграционные тесты. Еще что-то сделал...

master
Andrey Ivanov 2020-11-05 13:24:02 +03:00 committed by Andrey Ivanov
parent 0fc48a0858
commit fcadb15167
25 changed files with 34 additions and 20 deletions

View File

@ -1,11 +1,11 @@
build:
go build -o bin ./previewer/main.go
go build -o bin ./cmd/main.go
test:
go test -race ./previewer/...
go test -race ./cmd/... ./internal/...
lint: install-lint-deps
golangci-lint run ./previewer/...
golangci-lint run ./previewer/... ./internal/...
install-lint-deps:
rm -rf $(shell go env GOPATH)/bin/golangci-lint

View File

Before

Width:  |  Height:  |  Size: 41 KiB

After

Width:  |  Height:  |  Size: 41 KiB

View File

Before

Width:  |  Height:  |  Size: 222 KiB

After

Width:  |  Height:  |  Size: 222 KiB

View File

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 29 KiB

View File

Before

Width:  |  Height:  |  Size: 9.9 KiB

After

Width:  |  Height:  |  Size: 9.9 KiB

View File

Before

Width:  |  Height:  |  Size: 41 KiB

After

Width:  |  Height:  |  Size: 41 KiB

View File

Before

Width:  |  Height:  |  Size: 46 KiB

After

Width:  |  Height:  |  Size: 46 KiB

View File

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 63 KiB

View File

@ -6,8 +6,8 @@ import (
"os"
"os/signal"
"github.com/tiburon-777/OTUS_Project/previewer/application"
"github.com/tiburon-777/OTUS_Project/previewer/config"
"github.com/tiburon-777/OTUS_Project/internal/application"
"github.com/tiburon-777/OTUS_Project/internal/config"
)
var ConfigFile = flag.String("config", "/etc/previewer.conf", "Path to configuration file")

View File

@ -6,15 +6,24 @@ import (
"io/ioutil"
"log"
"net/http"
"strconv"
"sync"
"testing"
"time"
)
const testPortBase = 3000
func TestIntegrationPositive(t *testing.T) {
testPort := strconv.Itoa(testPortBase + 1)
wg := sync.WaitGroup{}
server := &http.Server{Addr: ":3000", Handler: http.FileServer(http.Dir("../examples"))}
go server.ListenAndServe()
server := &http.Server{Addr: "localhost:" + testPort, Handler: http.FileServer(http.Dir("../assets"))}
go func() {
err := server.ListenAndServe()
if err != nil {
log.Println(err.Error())
}
}()
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
go func(ctx context.Context) {
main()
@ -24,10 +33,10 @@ func TestIntegrationPositive(t *testing.T) {
wg.Add(2)
t.Run("remote server return jpeg", func(t *testing.T) {
defer wg.Done()
body, _, err := request("http://localhost:8080/fill/1024/504/localhost:3000/gopher_original_1024x504.jpg", 15*time.Second)
body, resp, err := request("http://localhost:8080/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)
require.Equal(t, 200, resp.StatusCode)
})
t.Run("found pic in cache", func(t *testing.T) {
defer wg.Done()
@ -42,10 +51,15 @@ func TestIntegrationPositive(t *testing.T) {
}
func TestIntegrationNegative(t *testing.T) {
// Развернуть веб сервис со статическими картинками
testPort := strconv.Itoa(testPortBase + 2)
wg := sync.WaitGroup{}
server := &http.Server{Addr: ":3000", Handler: http.FileServer(http.Dir("../examples"))}
go server.ListenAndServe()
server := &http.Server{Addr: "localhost:" + testPort, Handler: http.FileServer(http.Dir("../assets"))}
go func() {
err := server.ListenAndServe()
if err != nil {
log.Println(err.Error())
}
}()
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
// Запустить наше приложение
go func(ctx context.Context) {

View File

@ -5,9 +5,9 @@ import (
"net"
"net/http"
"github.com/tiburon-777/OTUS_Project/previewer/cache"
"github.com/tiburon-777/OTUS_Project/previewer/config"
"github.com/tiburon-777/OTUS_Project/previewer/logger"
"github.com/tiburon-777/OTUS_Project/internal/cache"
"github.com/tiburon-777/OTUS_Project/internal/config"
"github.com/tiburon-777/OTUS_Project/internal/logger"
)
type App struct {

View File

@ -5,10 +5,10 @@ import (
"net/http"
"time"
"github.com/tiburon-777/OTUS_Project/previewer/cache"
"github.com/tiburon-777/OTUS_Project/previewer/config"
"github.com/tiburon-777/OTUS_Project/previewer/converter"
"github.com/tiburon-777/OTUS_Project/previewer/logger"
"github.com/tiburon-777/OTUS_Project/internal/cache"
"github.com/tiburon-777/OTUS_Project/internal/config"
"github.com/tiburon-777/OTUS_Project/internal/converter"
"github.com/tiburon-777/OTUS_Project/internal/logger"
)
func handler(c cache.Cache, conf config.Config) http.Handler {

View File

@ -46,7 +46,7 @@ func (q Query) fromOrigin(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)
req, err := http.NewRequestWithContext(ctx, "GET", "http://"+q.URL.Host+q.URL.Path, nil)
if err != nil {
return nil, nil, err
}