Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Filinto Duran <filinto@diagrid.io>
  • Loading branch information
filintod committed Nov 14, 2024
1 parent 9783d1b commit 4f9a6c2
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
31 changes: 31 additions & 0 deletions pkg/runfileconfig/run_file_config_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ var (
runFileForPrecedenceRuleDaprDir = filepath.Join(".", "testdata", "test_run_config_precedence_rule_dapr_dir.yaml")
runFileForLogDestination = filepath.Join(".", "testdata", "test_run_config_log_destination.yaml")
runFileForMultiResourcePaths = filepath.Join(".", "testdata", "test_run_config_multiple_resources_paths.yaml")

runFileForContainerImagePullPolicy = filepath.Join(".", "testdata", "test_run_config_container_image_pull_policy.yaml")
runFileForContainerImagePullPolicyInvalid = filepath.Join(".", "testdata", "test_run_config_container_image_pull_policy_invalid.yaml")
)

func TestRunConfigFile(t *testing.T) {

Check failure on line 40 in pkg/runfileconfig/run_file_config_parser_test.go

View workflow job for this annotation

GitHub Actions / Build linux_amd64 binaries

Function name: TestRunConfigFile, Cyclomatic Complexity: 4, Halstead Volume: 8579.99, Maintainability Index: 19 (maintidx)
Expand Down Expand Up @@ -144,6 +147,34 @@ func TestRunConfigFile(t *testing.T) {
}
})

t.Run("test containerImagePullPolicy", func(t *testing.T) {
t.Run("default value is Always", func(t *testing.T) {
config := RunFileConfig{}
config.parseAppsConfig(validRunFilePath)
err := config.validateRunConfig(runFileForPrecedenceRuleDaprDir)
assert.NoError(t, err)
assert.Equal(t, "Always", config.Apps[0].ContainerImagePullPolicy)
assert.Equal(t, "Always", config.Apps[1].ContainerImagePullPolicy)
})

t.Run("custom value is respected", func(t *testing.T) {
config := RunFileConfig{}
config.parseAppsConfig(runFileForContainerImagePullPolicy)
err := config.validateRunConfig(runFileForContainerImagePullPolicy)
assert.NoError(t, err)
assert.Equal(t, "IfNotPresent", config.Apps[0].ContainerImagePullPolicy)
assert.Equal(t, "Always", config.Apps[1].ContainerImagePullPolicy)
})

t.Run("invalid value is rejected", func(t *testing.T) {
config := RunFileConfig{}
config.parseAppsConfig(runFileForContainerImagePullPolicyInvalid)
err := config.validateRunConfig(runFileForContainerImagePullPolicyInvalid)
assert.Error(t, err)
assert.Contains(t, err.Error(), "invalid containerImagePullPolicy: Invalid, allowed values: Always, Never, IfNotPresent")
})
})

t.Run("test precedence logic with daprInstallDir for resources-path and dapr config file", func(t *testing.T) {
config := RunFileConfig{}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: 1
common:
resourcesPath: ./app/resources
appProtocol: HTTP
appHealthProbeTimeout: 10
env:
DEBUG: false
tty: sts
apps:
- appDirPath: ./webapp/
resourcesPath: ./resources
configFilePath: ./config.yaml
appPort: 8080
appHealthProbeTimeout: 1
containerImagePullPolicy: IfNotPresent
containerImage: ghcr.io/dapr/dapr-workflows-python-sdk:latest
- appID: backend
appDirPath: ./backend/
appProtocol: GRPC
appPort: 3000
unixDomainSocket: /tmp/test-socket
env:
DEBUG: true
containerImage: ghcr.io/dapr/dapr-workflows-csharp-sdk:latest
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: 1
common:
resourcesPath: ./app/resources
appProtocol: HTTP
appHealthProbeTimeout: 10
env:
DEBUG: false
tty: sts
apps:
- appDirPath: ./webapp/
resourcesPath: ./resources
configFilePath: ./config.yaml
appPort: 8080
appHealthProbeTimeout: 1
containerImagePullPolicy: Invalid
containerImage: ghcr.io/dapr/dapr-workflows-python-sdk:latest
- appID: backend
appDirPath: ./backend/
appProtocol: GRPC
appPort: 3000
unixDomainSocket: /tmp/test-socket
env:
DEBUG: true
containerImage: ghcr.io/dapr/dapr-workflows-csharp-sdk:latest

0 comments on commit 4f9a6c2

Please sign in to comment.