Skip to content

Commit

Permalink
Create unit tests for Core
Browse files Browse the repository at this point in the history
- Migrate `go test` to `helm unittest`
- Migrate Trivy existing unit tests to `helm unittest`
- Add unit tests for Core

Signed-off-by: Carlos Vega <[email protected]>
  • Loading branch information
cvegagimenez committed Jul 9, 2024
1 parent 1569536 commit 42000ea
Show file tree
Hide file tree
Showing 9 changed files with 1,248 additions and 173 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/unittest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ jobs:
restore-keys: |
${{ runner.os }}-go-
- name: Install Helm Unit Test Plugin
run: |
helm plugin install https://github.com/helm-unittest/helm-unittest --version v0.4.4
- name: Run unit tests
working-directory: ./test
run:
go test -v github.com/goharbor/harbor-helm/unittest
helm unittest -f 'test/unittest/*.yaml' .
180 changes: 180 additions & 0 deletions test/unittest/core_configmap_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
suite: CoreConfigMap

tests:
- it: witTrivy
set:
trivy:
enabled: true
template: templates/core/core-cm.yaml
asserts:
- equal:
path: data.WITH_TRIVY
value: "true"

- it: RedisUrlHarborInternal
set:
redis:
internal:
harborDatabaseIndex: test-index
type: internal
template: templates/core/core-cm.yaml
asserts:
- equal:
path: data._REDIS_URL_HARBOR
value: redis://RELEASE-NAME-harbor-redis:6379/test-index?idle_timeout_seconds=30

- it: RedisUrlHarborExternal
set:
redis:
external:
harborDatabaseIndex: test-index
type: external
template: templates/core/core-cm.yaml
asserts:
- equal:
path: data._REDIS_URL_HARBOR
value: redis://192.168.0.2:6379/test-index?idle_timeout_seconds=30

- it: CacheLayerDatabaseIndex
set:
redis:
internal:
cacheLayerDatabaseIndex: test-index
type: internal
template: templates/core/core-cm.yaml
asserts:
- equal:
path: data._REDIS_URL_CACHE_LAYER
value: redis://RELEASE-NAME-harbor-redis:6379/test-index?idle_timeout_seconds=30

- it: RegsitryCredentialUsername
set:
registry:
credentials:
username: test-username
template: templates/core/core-cm.yaml
asserts:
- equal:
path: data.REGISTRY_CREDENTIAL_USERNAME
value: test-username

- it: UaaSecretName
set:
uaaSecretName: true
template: templates/core/core-cm.yaml
asserts:
- equal:
path: data.UAA_CA_ROOT
value: /etc/core/auth-ca/auth-ca.crt

- it: MetricEnabled
set:
metrics:
enabled: true
core:
path: /customMetrics
port: 8080
template: templates/core/core-cm.yaml
asserts:
- equal:
path: data.METRIC_ENABLE
value: "true"
- equal:
path: data.METRIC_PATH
value: /customMetrics
- equal:
path: data.METRIC_PORT
value: "8080"
- equal:
path: data.METRIC_NAMESPACE
value: harbor
- equal:
path: data.METRIC_SUBSYSTEM
value: core

- it: GcTimeWindowHours
set:
core:
gcTimeWindowHours: 2
template: templates/core/core-cm.yaml
asserts:
- equal:
path: data.GC_TIME_WINDOW_HOURS
value: "2"

- it: GcTimeWindowHours
set:
core:
artifactPullAsyncFlushDuration: 30
template: templates/core/core-cm.yaml
asserts:
- equal:
path: data.ARTIFACT_PULL_ASYNC_FLUSH_DURATION
value: "30"

- it: GdprDeleteUser
set:
core:
gdpr:
deleteUser: true
auditLogsCompliant: false
template: templates/core/core-cm.yaml
asserts:
- equal:
path: data.GDPR_DELETE_USER
value: "true"
- notExists:
path: data.GDPR_AUDIT_LOGS

- it: GdprAuditLogsCompliant
set:
core:
gdpr:
deleteUser: false
auditLogsCompliant: true
template: templates/core/core-cm.yaml
asserts:
- equal:
path: data.GDPR_AUDIT_LOGS
value: "true"
- notExists:
path: data.GDPR_DELETE_USER

- it: GdprDeleteUserAuditLogsCompliant
set:
core:
gdpr:
deleteUser: true
auditLogsCompliant: true
template: templates/core/core-cm.yaml
asserts:
- equal:
path: data.GDPR_DELETE_USER
value: "true"
- equal:
path: data.GDPR_AUDIT_LOGS
value: "true"

- it: CacheEnabled
set:
cache:
enabled: true
expireHours: 3
template: templates/core/core-cm.yaml
asserts:
- equal:
path: data.CACHE_ENABLED
value: "true"
- equal:
path: data.CACHE_EXPIRE_HOURS
value: "3"

- it: CuotaUpdate
set:
core:
quotaUpdateProvider: 3
template: templates/core/core-cm.yaml
asserts:
- equal:
path: data.QUOTA_UPDATE_PROVIDER
value: "3"
Loading

0 comments on commit 42000ea

Please sign in to comment.