@@ -45,6 +45,7 @@ func TestLoad_DefaultValues(t *testing.T) {
4545 assert .Equal (t , "./ocaplogs" , viper .GetString ("logsDir" ))
4646 assert .Equal (t , "http://localhost:5000" , viper .GetString ("api.serverUrl" ))
4747 assert .Equal (t , "" , viper .GetString ("api.apiKey" ))
48+ assert .Equal (t , "10m" , viper .GetString ("api.uploadTimeout" ))
4849 assert .Equal (t , "localhost" , viper .GetString ("db.host" ))
4950 assert .Equal (t , "5432" , viper .GetString ("db.port" ))
5051 assert .Equal (t , "postgres" , viper .GetString ("db.username" ))
@@ -127,6 +128,39 @@ func TestGetStorageConfig_Override(t *testing.T) {
127128 assert .Equal (t , 10 * time .Minute , sc .SQLite .DumpInterval )
128129}
129130
131+ func TestGetAPIConfig_Defaults (t * testing.T ) {
132+ t .Cleanup (viper .Reset )
133+
134+ dir := t .TempDir ()
135+ require .NoError (t , os .WriteFile (filepath .Join (dir , "ocap_recorder.cfg.json" ), []byte (`{}` ), 0644 ))
136+ require .NoError (t , Load (dir ))
137+
138+ cfg := GetAPIConfig ()
139+ assert .Equal (t , "http://localhost:5000" , cfg .ServerURL )
140+ assert .Equal (t , "" , cfg .APIKey )
141+ assert .Equal (t , 10 * time .Minute , cfg .UploadTimeout )
142+ }
143+
144+ func TestGetAPIConfig_Override (t * testing.T ) {
145+ t .Cleanup (viper .Reset )
146+
147+ dir := t .TempDir ()
148+ cfgJSON := `{
149+ "api": {
150+ "serverUrl": "http://example.com:8080",
151+ "apiKey": "mykey",
152+ "uploadTimeout": "5m"
153+ }
154+ }`
155+ require .NoError (t , os .WriteFile (filepath .Join (dir , "ocap_recorder.cfg.json" ), []byte (cfgJSON ), 0644 ))
156+ require .NoError (t , Load (dir ))
157+
158+ cfg := GetAPIConfig ()
159+ assert .Equal (t , "http://example.com:8080" , cfg .ServerURL )
160+ assert .Equal (t , "mykey" , cfg .APIKey )
161+ assert .Equal (t , 5 * time .Minute , cfg .UploadTimeout )
162+ }
163+
130164func TestGetOTelConfig_Defaults (t * testing.T ) {
131165 t .Cleanup (viper .Reset )
132166
0 commit comments