mirror of
https://github.com/openfaas/faas.git
synced 2025-06-09 00:36:46 +00:00
64 lines
1.4 KiB
Go
64 lines
1.4 KiB
Go
// 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()
|
|
}
|
|
}
|