mirror of
https://github.com/openfaas/faas.git
synced 2025-06-18 12:06:37 +00:00
Relocate config_test to tests package and
Export struct members of GatewayConfig{}
This commit is contained in:
committed by
Alex Ellis
parent
457d0be78b
commit
cc3308a555
63
gateway/tests/config_test.go
Normal file
63
gateway/tests/config_test.go
Normal file
@ -0,0 +1,63 @@
|
||||
// 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 tests
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
gateway "github.com/alexellis/faas/gateway"
|
||||
)
|
||||
|
||||
type EnvBucket struct {
|
||||
Items map[string]string
|
||||
}
|
||||
|
||||
func NewEnvBucket() EnvBucket {
|
||||
return EnvBucket{
|
||||
Items: make(map[string]string),
|
||||
}
|
||||
}
|
||||
|
||||
func (e EnvBucket) Getenv(key string) string {
|
||||
return e.Items[key]
|
||||
}
|
||||
|
||||
func (e EnvBucket) Setenv(key string, value string) {
|
||||
e.Items[key] = value
|
||||
}
|
||||
|
||||
func TestRead_EmptyTimeoutConfig(t *testing.T) {
|
||||
defaults := NewEnvBucket()
|
||||
readConfig := gateway.ReadConfig{}
|
||||
|
||||
config := readConfig.Read(defaults)
|
||||
|
||||
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")
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
func TestRead_ReadAndWriteTimeoutConfig(t *testing.T) {
|
||||
defaults := NewEnvBucket()
|
||||
defaults.Setenv("read_timeout", "10")
|
||||
defaults.Setenv("write_timeout", "60")
|
||||
|
||||
readConfig := gateway.ReadConfig{}
|
||||
config := readConfig.Read(defaults)
|
||||
|
||||
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)
|
||||
t.Fail()
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user