Skip to content
Snippets Groups Projects
Commit cc3308a5 authored by leigh schrandt's avatar leigh schrandt Committed by Alex Ellis
Browse files

Relocate config_test to tests package and

Export struct members of GatewayConfig{}
parent 457d0be7
No related branches found
No related tags found
No related merge requests found
......@@ -18,8 +18,6 @@ COPY requests requests
COPY tests tests
COPY server.go .
COPY readconfig.go .
COPY config_test.go .
RUN go test && \
go test -v ./tests && \
RUN go test -v ./tests && \
CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .
......@@ -17,8 +17,6 @@ COPY handlers handlers
COPY server.go .
COPY readconfig.go .
COPY config_test.go .
RUN go test && \
go test -v ./tests && \
RUN go test -v ./tests && \
CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .
......@@ -9,7 +9,6 @@ COPY requests requests
COPY tests tests
COPY server.go .
COPY readconfig.go .
COPY config_test.go .
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o gateway .
......
......@@ -10,7 +10,6 @@ COPY requests requests
COPY tests tests
COPY server.go .
COPY readconfig.go .
COPY config_test.go .
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o gateway .
......@@ -48,14 +48,14 @@ func (ReadConfig) Read(hasEnv HasEnv) GatewayConfig {
readTimeout := parseIntValue(hasEnv.Getenv("read_timeout"), 8)
writeTimeout := parseIntValue(hasEnv.Getenv("write_timeout"), 8)
cfg.readTimeout = time.Duration(readTimeout) * time.Second
cfg.writeTimeout = time.Duration(writeTimeout) * time.Second
cfg.ReadTimeout = time.Duration(readTimeout) * time.Second
cfg.WriteTimeout = time.Duration(writeTimeout) * time.Second
return cfg
}
// GatewayConfig for the process.
type GatewayConfig struct {
readTimeout time.Duration
writeTimeout time.Duration
ReadTimeout time.Duration
WriteTimeout time.Duration
}
......@@ -23,8 +23,8 @@ func main() {
readConfig := ReadConfig{}
config := readConfig.Read(osEnv)
log.Printf("HTTP Read Timeout: %s", config.readTimeout)
log.Printf("HTTP Write Timeout: %s", config.writeTimeout)
log.Printf("HTTP Read Timeout: %s", config.ReadTimeout)
log.Printf("HTTP Write Timeout: %s", config.WriteTimeout)
var dockerClient *client.Client
var err error
......@@ -71,8 +71,8 @@ func main() {
s := &http.Server{
Addr: fmt.Sprintf(":%d", tcpPort),
ReadTimeout: config.readTimeout,
WriteTimeout: config.writeTimeout,
ReadTimeout: config.ReadTimeout,
WriteTimeout: config.WriteTimeout,
MaxHeaderBytes: http.DefaultMaxHeaderBytes, // 1MB - can be overridden by setting Server.MaxHeaderBytes.
Handler: r,
}
......
// Copyright (c) Alex Ellis 2017. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
package main
package tests
import (
"testing"
"time"
gateway "github.com/alexellis/faas/gateway"
)
type EnvBucket struct {
......@@ -28,16 +30,16 @@ func (e EnvBucket) Setenv(key string, value string) {
func TestRead_EmptyTimeoutConfig(t *testing.T) {
defaults := NewEnvBucket()
readConfig := ReadConfig{}
readConfig := gateway.ReadConfig{}
config := readConfig.Read(defaults)
if (config.readTimeout) != time.Duration(8)*time.Second {
t.Log("readTimeout incorrect")
if (config.ReadTimeout) != time.Duration(8)*time.Second {
t.Log("ReadTimeout incorrect")
t.Fail()
}
if (config.writeTimeout) != time.Duration(8)*time.Second {
t.Log("writeTimeout incorrect")
if (config.WriteTimeout) != time.Duration(8)*time.Second {
t.Log("WriteTimeout incorrect")
t.Fail()
}
}
......@@ -47,15 +49,15 @@ func TestRead_ReadAndWriteTimeoutConfig(t *testing.T) {
defaults.Setenv("read_timeout", "10")
defaults.Setenv("write_timeout", "60")
readConfig := ReadConfig{}
readConfig := gateway.ReadConfig{}
config := readConfig.Read(defaults)
if (config.readTimeout) != time.Duration(10)*time.Second {
t.Logf("readTimeout incorrect, got: %d\n", config.readTimeout)
if (config.ReadTimeout) != time.Duration(10)*time.Second {
t.Logf("ReadTimeout incorrect, got: %d\n", config.ReadTimeout)
t.Fail()
}
if (config.writeTimeout) != time.Duration(60)*time.Second {
t.Logf("writeTimeout incorrect, got: %d\n", config.writeTimeout)
if (config.WriteTimeout) != time.Duration(60)*time.Second {
t.Logf("WriteTimeout incorrect, got: %d\n", config.WriteTimeout)
t.Fail()
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment