generated from kedacore/github-template
-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into add-e2e-test
- Loading branch information
Showing
10 changed files
with
195 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
kind: Cluster | ||
apiVersion: kind.x-k8s.io/v1alpha4 | ||
kubeadmConfigPatches: | ||
- | | ||
kind: ClusterConfiguration | ||
etcd: | ||
local: | ||
dataDir: /tmp/etcd # /tmp is mapped to tmpfs in kind's nodes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
Copyright 2023 The KEDA Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package util | ||
|
||
import ( | ||
"os" | ||
"strconv" | ||
"time" | ||
) | ||
|
||
func ResolveOsEnvBool(envName string, defaultValue bool) (bool, error) { | ||
valueStr, found := os.LookupEnv(envName) | ||
|
||
if found && valueStr != "" { | ||
return strconv.ParseBool(valueStr) | ||
} | ||
|
||
return defaultValue, nil | ||
} | ||
|
||
func ResolveOsEnvInt(envName string, defaultValue int) (int, error) { | ||
valueStr, found := os.LookupEnv(envName) | ||
|
||
if found && valueStr != "" { | ||
return strconv.Atoi(valueStr) | ||
} | ||
|
||
return defaultValue, nil | ||
} | ||
|
||
func ResolveOsEnvDuration(envName string) (*time.Duration, error) { | ||
valueStr, found := os.LookupEnv(envName) | ||
|
||
if found && valueStr != "" { | ||
value, err := time.ParseDuration(valueStr) | ||
return &value, err | ||
} | ||
|
||
return nil, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package util | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestResolveMissingOsEnvBool(t *testing.T) { | ||
actual, err := ResolveOsEnvBool("missing_bool", true) | ||
assert.True(t, actual) | ||
assert.Nil(t, err) | ||
|
||
t.Setenv("empty_bool", "") | ||
actual, err = ResolveOsEnvBool("empty_bool", true) | ||
assert.True(t, actual) | ||
assert.Nil(t, err) | ||
} | ||
|
||
func TestResolveInvalidOsEnvBool(t *testing.T) { | ||
t.Setenv("blank_bool", " ") | ||
actual, err := ResolveOsEnvBool("blank_bool", true) | ||
assert.False(t, actual) | ||
assert.NotNil(t, err) | ||
|
||
t.Setenv("invalid_bool", "deux heures") | ||
actual, err = ResolveOsEnvBool("invalid_bool", true) | ||
assert.False(t, actual) | ||
assert.NotNil(t, err) | ||
} | ||
|
||
func TestResolveValidOsEnvBool(t *testing.T) { | ||
t.Setenv("valid_bool", "true") | ||
actual, err := ResolveOsEnvBool("valid_bool", false) | ||
assert.True(t, actual) | ||
assert.Nil(t, err) | ||
|
||
t.Setenv("valid_bool", "false") | ||
actual, err = ResolveOsEnvBool("valid_bool", true) | ||
assert.False(t, actual) | ||
assert.Nil(t, err) | ||
} | ||
|
||
func TestResolveMissingOsEnvInt(t *testing.T) { | ||
actual, err := ResolveOsEnvInt("missing_int", 1) | ||
assert.Equal(t, 1, actual) | ||
assert.Nil(t, err) | ||
|
||
t.Setenv("empty_int", "") | ||
actual, err = ResolveOsEnvInt("empty_int", 1) | ||
assert.Equal(t, 1, actual) | ||
assert.Nil(t, err) | ||
} | ||
|
||
func TestResolveInvalidOsEnvInt(t *testing.T) { | ||
t.Setenv("blank_int", " ") | ||
actual, err := ResolveOsEnvInt("blank_int", 1) | ||
assert.Equal(t, 0, actual) | ||
assert.NotNil(t, err) | ||
|
||
t.Setenv("invalid_int", "deux heures") | ||
actual, err = ResolveOsEnvInt("invalid_int", 1) | ||
assert.Equal(t, 0, actual) | ||
assert.NotNil(t, err) | ||
} | ||
|
||
func TestResolveValidOsEnvInt(t *testing.T) { | ||
t.Setenv("valid_int", "2") | ||
actual, err := ResolveOsEnvInt("valid_int", 1) | ||
assert.Equal(t, 2, actual) | ||
assert.Nil(t, err) | ||
} | ||
|
||
func TestResolveMissingOsEnvDuration(t *testing.T) { | ||
actual, err := ResolveOsEnvDuration("missing_duration") | ||
assert.Nil(t, actual) | ||
assert.Nil(t, err) | ||
|
||
t.Setenv("empty_duration", "") | ||
actual, err = ResolveOsEnvDuration("empty_duration") | ||
assert.Nil(t, actual) | ||
assert.Nil(t, err) | ||
} | ||
|
||
func TestResolveInvalidOsEnvDuration(t *testing.T) { | ||
t.Setenv("blank_duration", " ") | ||
actual, err := ResolveOsEnvDuration("blank_duration") | ||
assert.Equal(t, time.Duration(0), *actual) | ||
assert.NotNil(t, err) | ||
|
||
t.Setenv("invalid_duration", "deux heures") | ||
actual, err = ResolveOsEnvDuration("invalid_duration") | ||
assert.Equal(t, time.Duration(0), *actual) | ||
assert.NotNil(t, err) | ||
} | ||
|
||
func TestResolveValidOsEnvDuration(t *testing.T) { | ||
t.Setenv("valid_duration_seconds", "8s") | ||
actual, err := ResolveOsEnvDuration("valid_duration_seconds") | ||
assert.Equal(t, time.Duration(8)*time.Second, *actual) | ||
assert.Nil(t, err) | ||
|
||
t.Setenv("valid_duration_minutes", "30m") | ||
actual, err = ResolveOsEnvDuration("valid_duration_minutes") | ||
assert.Equal(t, time.Duration(30)*time.Minute, *actual) | ||
assert.Nil(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters