mirror of
https://github.com/openfaas/faas.git
synced 2025-06-14 03:06:46 +00:00
Relocate config_test to tests package and
Export struct members of GatewayConfig{}
This commit is contained in:
parent
457d0be78b
commit
cc3308a555
@ -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,
|
||||
}
|
||||
|
@ -1,11 +1,13 @@
|
||||
// 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()
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user