Исправил лайаут. Починил интеграционные тесты. Еще что-то сделал...
6
Makefile
|
@ -1,11 +1,11 @@
|
||||||
build:
|
build:
|
||||||
go build -o bin ./previewer/main.go
|
go build -o bin ./cmd/main.go
|
||||||
|
|
||||||
test:
|
test:
|
||||||
go test -race ./previewer/...
|
go test -race ./cmd/... ./internal/...
|
||||||
|
|
||||||
lint: install-lint-deps
|
lint: install-lint-deps
|
||||||
golangci-lint run ./previewer/...
|
golangci-lint run ./previewer/... ./internal/...
|
||||||
|
|
||||||
install-lint-deps:
|
install-lint-deps:
|
||||||
rm -rf $(shell go env GOPATH)/bin/golangci-lint
|
rm -rf $(shell go env GOPATH)/bin/golangci-lint
|
||||||
|
|
Before Width: | Height: | Size: 41 KiB After Width: | Height: | Size: 41 KiB |
Before Width: | Height: | Size: 222 KiB After Width: | Height: | Size: 222 KiB |
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 29 KiB |
Before Width: | Height: | Size: 9.9 KiB After Width: | Height: | Size: 9.9 KiB |
Before Width: | Height: | Size: 41 KiB After Width: | Height: | Size: 41 KiB |
Before Width: | Height: | Size: 46 KiB After Width: | Height: | Size: 46 KiB |
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
After Width: | Height: | Size: 63 KiB |
|
@ -6,8 +6,8 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
|
||||||
"github.com/tiburon-777/OTUS_Project/previewer/application"
|
"github.com/tiburon-777/OTUS_Project/internal/application"
|
||||||
"github.com/tiburon-777/OTUS_Project/previewer/config"
|
"github.com/tiburon-777/OTUS_Project/internal/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ConfigFile = flag.String("config", "/etc/previewer.conf", "Path to configuration file")
|
var ConfigFile = flag.String("config", "/etc/previewer.conf", "Path to configuration file")
|
|
@ -6,15 +6,24 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const testPortBase = 3000
|
||||||
|
|
||||||
func TestIntegrationPositive(t *testing.T) {
|
func TestIntegrationPositive(t *testing.T) {
|
||||||
|
testPort := strconv.Itoa(testPortBase + 1)
|
||||||
wg := sync.WaitGroup{}
|
wg := sync.WaitGroup{}
|
||||||
server := &http.Server{Addr: ":3000", Handler: http.FileServer(http.Dir("../examples"))}
|
server := &http.Server{Addr: "localhost:" + testPort, Handler: http.FileServer(http.Dir("../assets"))}
|
||||||
go server.ListenAndServe()
|
go func() {
|
||||||
|
err := server.ListenAndServe()
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err.Error())
|
||||||
|
}
|
||||||
|
}()
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
go func(ctx context.Context) {
|
go func(ctx context.Context) {
|
||||||
main()
|
main()
|
||||||
|
@ -24,10 +33,10 @@ func TestIntegrationPositive(t *testing.T) {
|
||||||
wg.Add(2)
|
wg.Add(2)
|
||||||
t.Run("remote server return jpeg", func(t *testing.T) {
|
t.Run("remote server return jpeg", func(t *testing.T) {
|
||||||
defer wg.Done()
|
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.NoError(t, err)
|
||||||
require.NotNil(t, body)
|
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) {
|
t.Run("found pic in cache", func(t *testing.T) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
|
@ -42,10 +51,15 @@ func TestIntegrationPositive(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIntegrationNegative(t *testing.T) {
|
func TestIntegrationNegative(t *testing.T) {
|
||||||
// Развернуть веб сервис со статическими картинками
|
testPort := strconv.Itoa(testPortBase + 2)
|
||||||
wg := sync.WaitGroup{}
|
wg := sync.WaitGroup{}
|
||||||
server := &http.Server{Addr: ":3000", Handler: http.FileServer(http.Dir("../examples"))}
|
server := &http.Server{Addr: "localhost:" + testPort, Handler: http.FileServer(http.Dir("../assets"))}
|
||||||
go server.ListenAndServe()
|
go func() {
|
||||||
|
err := server.ListenAndServe()
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err.Error())
|
||||||
|
}
|
||||||
|
}()
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
// Запустить наше приложение
|
// Запустить наше приложение
|
||||||
go func(ctx context.Context) {
|
go func(ctx context.Context) {
|
|
@ -5,9 +5,9 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/tiburon-777/OTUS_Project/previewer/cache"
|
"github.com/tiburon-777/OTUS_Project/internal/cache"
|
||||||
"github.com/tiburon-777/OTUS_Project/previewer/config"
|
"github.com/tiburon-777/OTUS_Project/internal/config"
|
||||||
"github.com/tiburon-777/OTUS_Project/previewer/logger"
|
"github.com/tiburon-777/OTUS_Project/internal/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
type App struct {
|
type App struct {
|
|
@ -5,10 +5,10 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/tiburon-777/OTUS_Project/previewer/cache"
|
"github.com/tiburon-777/OTUS_Project/internal/cache"
|
||||||
"github.com/tiburon-777/OTUS_Project/previewer/config"
|
"github.com/tiburon-777/OTUS_Project/internal/config"
|
||||||
"github.com/tiburon-777/OTUS_Project/previewer/converter"
|
"github.com/tiburon-777/OTUS_Project/internal/converter"
|
||||||
"github.com/tiburon-777/OTUS_Project/previewer/logger"
|
"github.com/tiburon-777/OTUS_Project/internal/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
func handler(c cache.Cache, conf config.Config) http.Handler {
|
func handler(c cache.Cache, conf config.Config) http.Handler {
|
|
@ -46,7 +46,7 @@ func (q Query) fromOrigin(timeout time.Duration) ([]byte, *http.Response, error)
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||||
defer cancel()
|
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 {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|