mirror of
https://github.com/openfaas/faas.git
synced 2025-06-19 04:26:35 +00:00
Add timeouts and unit test config.
This commit is contained in:
91
watchdog/config_test.go
Normal file
91
watchdog/config_test.go
Normal file
@ -0,0 +1,91 @@
|
||||
package main
|
||||
|
||||
import "testing"
|
||||
|
||||
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_WriteDebug_DefaultIsTrueConfig(t *testing.T) {
|
||||
defaults := NewEnvBucket()
|
||||
readConfig := ReadConfig{}
|
||||
|
||||
config := readConfig.Read(defaults)
|
||||
|
||||
if config.writeDebug != true {
|
||||
t.Logf("writeDebug should have been true")
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
func TestRead_WriteDebug_FalseConfig(t *testing.T) {
|
||||
defaults := NewEnvBucket()
|
||||
readConfig := ReadConfig{}
|
||||
defaults.Setenv("writeDebug", "true")
|
||||
|
||||
config := readConfig.Read(defaults)
|
||||
|
||||
if config.writeDebug != true {
|
||||
t.Logf("writeDebug should have been true")
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
func TestRead_FprocessConfig(t *testing.T) {
|
||||
defaults := NewEnvBucket()
|
||||
readConfig := ReadConfig{}
|
||||
defaults.Setenv("fprocess", "cat")
|
||||
|
||||
config := readConfig.Read(defaults)
|
||||
|
||||
if config.faasProcess != "cat" {
|
||||
t.Logf("fprocess envVariable incorrect, got: %s.\n", config.faasProcess)
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
func TestRead_EmptyTimeoutConfig(t *testing.T) {
|
||||
defaults := NewEnvBucket()
|
||||
readConfig := ReadConfig{}
|
||||
|
||||
config := readConfig.Read(defaults)
|
||||
|
||||
if (config.readTimeout) != 5 {
|
||||
t.Log("readTimeout incorrect")
|
||||
t.Fail()
|
||||
}
|
||||
if (config.writeTimeout) != 5 {
|
||||
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 := ReadConfig{}
|
||||
config := readConfig.Read(defaults)
|
||||
|
||||
if (config.readTimeout) != 10 {
|
||||
t.Logf("readTimeout incorrect, got: %d\n", config.readTimeout)
|
||||
t.Fail()
|
||||
}
|
||||
if (config.writeTimeout) != 60 {
|
||||
t.Logf("writeTimeout incorrect, got: %d\n", config.writeTimeout)
|
||||
t.Fail()
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user