1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-03-03 15:02:35 +02:00

Activates debug information for environment variables (#3630)

* Activates debug information for environment variables

* Adds tests for environment variable reading

* Reduces batch size to send messages to Splunk to 5000
This commit is contained in:
ffeldmann 2022-03-14 10:17:55 +01:00 committed by GitHub
parent 69fc4103c2
commit b224f2294c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 1 deletions

View File

@ -101,6 +101,7 @@ func truthy(key string) bool {
// Wrapper function to read env variable and set default value
func getEnv(key, fallback string) string {
if value, ok := os.LookupEnv(key); ok {
log.Entry().Debugf("For: %s, found: %s", key, value)
return value
}
log.Entry().Debugf("Could not read env variable %v using fallback value %v", key, fallback)

View File

@ -55,3 +55,36 @@ func TestOrchestrator(t *testing.T) {
assert.False(t, tmp)
})
}
func Test_getEnv(t *testing.T) {
type args struct {
key string
fallback string
}
tests := []struct {
name string
args args
want string
envVar string
}{
{
name: "environment variable found",
args: args{key: "debug", fallback: "fallback"},
want: "found",
envVar: "debug",
},
{
name: "fallback variable",
args: args{key: "debug", fallback: "fallback"},
want: "fallback",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
defer resetEnv(os.Environ())
os.Clearenv()
os.Setenv(tt.envVar, "found")
assert.Equalf(t, tt.want, getEnv(tt.args.key, tt.args.fallback), "getEnv(%v, %v)", tt.args.key, tt.args.fallback)
})
}
}

View File

@ -64,7 +64,7 @@ func (s *Splunk) Initialize(correlationID, dsn, token, index string, sendLogs bo
s.splunkDsn = dsn
s.splunkIndex = index
s.correlationID = correlationID
s.postMessagesBatchSize = 6000
s.postMessagesBatchSize = 5000
s.sendLogs = sendLogs
return nil