|
1 | 1 | package config |
2 | 2 |
|
3 | 3 | import "testing" |
| 4 | +import "time" |
4 | 5 |
|
5 | 6 | func TestNew(t *testing.T) { |
6 | 7 | defaults, err := New([]string{}) |
@@ -35,4 +36,135 @@ func Test_OperationalMode_AfterBurn(t *testing.T) { |
35 | 36 | if actual.OperationalMode != ModeAfterBurn { |
36 | 37 | t.Errorf("Want %s. got: %s", WatchdogMode(ModeAfterBurn), WatchdogMode(actual.OperationalMode)) |
37 | 38 | } |
| 39 | + |
| 40 | +} |
| 41 | + |
| 42 | +func Test_ContentType_Default(t *testing.T) { |
| 43 | + env := []string{} |
| 44 | + |
| 45 | + actual, err := New(env) |
| 46 | + if err != nil { |
| 47 | + t.Errorf("Expected no errors") |
| 48 | + } |
| 49 | + |
| 50 | + if actual.ContentType != "application/octet-stream" { |
| 51 | + t.Errorf("Default (ContentType) Want %s. got: %s", actual.ContentType, "octet-stream") |
| 52 | + } |
| 53 | +} |
| 54 | + |
| 55 | +func Test_ContentType_Override(t *testing.T) { |
| 56 | + env := []string{ |
| 57 | + "content_type=application/json", |
| 58 | + } |
| 59 | + |
| 60 | + actual, err := New(env) |
| 61 | + if err != nil { |
| 62 | + t.Errorf("Expected no errors") |
| 63 | + } |
| 64 | + |
| 65 | + if actual.ContentType != "application/json" { |
| 66 | + t.Errorf("(ContentType) Want %s. got: %s", actual.ContentType, "application/json") |
| 67 | + } |
| 68 | +} |
| 69 | + |
| 70 | +func Test_FunctionProcessLegacyName(t *testing.T) { |
| 71 | + env := []string{ |
| 72 | + "fprocess=env", |
| 73 | + } |
| 74 | + |
| 75 | + actual, err := New(env) |
| 76 | + if err != nil { |
| 77 | + t.Errorf("Expected no errors") |
| 78 | + } |
| 79 | + |
| 80 | + if actual.FunctionProcess != "env" { |
| 81 | + t.Errorf("Want %s. got: %s", "env", actual.FunctionProcess) |
| 82 | + } |
| 83 | +} |
| 84 | + |
| 85 | +func Test_FunctionProcessAlternativeName(t *testing.T) { |
| 86 | + env := []string{ |
| 87 | + "function_process=env", |
| 88 | + } |
| 89 | + |
| 90 | + actual, err := New(env) |
| 91 | + if err != nil { |
| 92 | + t.Errorf("Expected no errors") |
| 93 | + } |
| 94 | + |
| 95 | + if actual.FunctionProcess != "env" { |
| 96 | + t.Errorf("Want %s. got: %s", "env", actual.FunctionProcess) |
| 97 | + } |
| 98 | +} |
| 99 | + |
| 100 | +func Test_PortOverride(t *testing.T) { |
| 101 | + env := []string{ |
| 102 | + "port=8081", |
| 103 | + } |
| 104 | + |
| 105 | + actual, err := New(env) |
| 106 | + if err != nil { |
| 107 | + t.Errorf("Expected no errors") |
| 108 | + } |
| 109 | + |
| 110 | + if actual.TCPPort != 8081 { |
| 111 | + t.Errorf("Want %s. got: %s", 8081, actual.TCPPort) |
| 112 | + } |
| 113 | +} |
| 114 | + |
| 115 | +func Test_Timeouts(t *testing.T) { |
| 116 | + cases := []struct { |
| 117 | + readTimeout time.Duration |
| 118 | + writeTimeout time.Duration |
| 119 | + hardTimeout time.Duration |
| 120 | + env []string |
| 121 | + name string |
| 122 | + }{ |
| 123 | + { |
| 124 | + name: "Defaults", |
| 125 | + readTimeout: time.Second * 10, |
| 126 | + writeTimeout: time.Second * 10, |
| 127 | + hardTimeout: time.Second * 10, |
| 128 | + env: []string{}, |
| 129 | + }, |
| 130 | + { |
| 131 | + name: "Custom read-timeout", |
| 132 | + readTimeout: time.Second * 5, |
| 133 | + writeTimeout: time.Second * 10, |
| 134 | + hardTimeout: time.Second * 10, |
| 135 | + env: []string{"read_timeout=5s"}, |
| 136 | + }, |
| 137 | + { |
| 138 | + name: "Custom write-timeout", |
| 139 | + readTimeout: time.Second * 10, |
| 140 | + writeTimeout: time.Second * 5, |
| 141 | + hardTimeout: time.Second * 10, |
| 142 | + env: []string{"write_timeout=5s"}, |
| 143 | + }, |
| 144 | + { |
| 145 | + name: "Custom hard-timeout", |
| 146 | + readTimeout: time.Second * 10, |
| 147 | + writeTimeout: time.Second * 10, |
| 148 | + hardTimeout: time.Second * 5, |
| 149 | + env: []string{"hard_timeout=5s"}, |
| 150 | + }, |
| 151 | + } |
| 152 | + |
| 153 | + for _, testCase := range cases { |
| 154 | + actual, err := New(testCase.env) |
| 155 | + if err != nil { |
| 156 | + t.Errorf("(%s) Expected no errors", testCase.name) |
| 157 | + } |
| 158 | + if testCase.readTimeout != actual.HTTPReadTimeout { |
| 159 | + t.Errorf("(%s) HTTPReadTimeout want: %s, got: %s", testCase.name, actual.HTTPReadTimeout, testCase.readTimeout) |
| 160 | + } |
| 161 | + if testCase.writeTimeout != actual.HTTPWriteTimeout { |
| 162 | + t.Errorf("(%s) HTTPWriteTimeout want: %s, got: %s", testCase.name, actual.HTTPWriteTimeout, testCase.writeTimeout) |
| 163 | + } |
| 164 | + if testCase.hardTimeout != actual.HardTimeout { |
| 165 | + t.Errorf("(%s) HardTimeout want: %s, got: %s", testCase.name, actual.HardTimeout, testCase.hardTimeout) |
| 166 | + } |
| 167 | + |
| 168 | + } |
| 169 | + |
38 | 170 | } |
0 commit comments