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