- .github
- action
-
cmd
-
flux
-
testdata
- build-kustomization
- check
- cluster_info
- create_secret
- create_source_git
- create_source_helm
- diff-artifact
-
diff-kustomization
- deployment.yaml
- diff-with-deployment.golden
- diff-with-dockerconfigjson-sops-secret.golden
- diff-with-drifted-key-sops-secret.golden
- diff-with-drifted-secret.golden
- diff-with-drifted-service.golden
- diff-with-drifted-stringdata-sops-secret.golden
- diff-with-drifted-value-sops-secret.golden
- dockerconfigjson-sops-secret.yaml
- flux-kustomization-multiobj.yaml
- key-sops-secret.yaml
- kustomization.yaml
- nothing-is-deployed.golden
- secret.yaml
- service.yaml
- stringdata-sops-secret.yaml
- value-sops-secret.yaml
- envsubst
- export
- get
- helmrelease
- image
-
kustomization
- create_kustomization_from_git.golden
- create_source_git.golden
- delete_kustomization_from_git.golden
- get_kustomization_from_git.golden
- reconcile_kustomization_from_git.golden
- resume_kustomization_from_git.golden
- resume_kustomization_from_git_multiple_args.golden
- resume_kustomization_from_git_multiple_args_wait.golden
- suspend_kustomization_from_git.golden
- suspend_kustomization_from_git_multiple_args.golden
- logs
- oci
- trace
- tree
- alert.go
- alert_provider.go
- bootstrap.go
- bootstrap_bitbucket_server.go
- bootstrap_git.go
- bootstrap_gitea.go
- bootstrap_github.go
- bootstrap_gitlab.go
- build.go
- build_artifact.go
- build_artifact_test.go
- build_kustomization.go
- build_kustomization_test.go
- check.go
- check_test.go
- cluster_info.go
- cluster_info_test.go
- completion.go
- completion_bash.go
- completion_fish.go
- completion_powershell.go
- completion_zsh.go
- create.go
- create_alert.go
- create_alertprovider.go
- create_helmrelease.go
- create_image.go
- create_image_policy.go
- create_image_repository.go
- create_image_update.go
- create_kustomization.go
- create_receiver.go
- create_secret.go
- create_secret_git.go
- create_secret_git_test.go
- create_secret_helm.go
- create_secret_helm_test.go
- create_secret_oci.go
- create_secret_oci_test.go
- create_secret_tls.go
- create_secret_tls_test.go
- create_source.go
- create_source_bucket.go
- create_source_git.go
- create_source_git_test.go
- create_source_helm.go
- create_source_helm_test.go
- create_source_oci.go
- create_source_oci_test.go
- create_tenant.go
- create_test.go
- delete.go
- delete_alert.go
- delete_alertprovider.go
- delete_helmrelease.go
- delete_image.go
- delete_image_policy.go
- delete_image_repository.go
- delete_image_update.go
- delete_kustomization.go
- delete_receiver.go
- delete_source.go
- delete_source_bucket.go
- delete_source_git.go
- delete_source_helm.go
- delete_source_oci.go
- diff.go
- diff_artifact.go
- diff_artifact_test.go
- diff_kustomization.go
- diff_kustomization_test.go
- docgen.go
- envsubst.go
- envsubst_test.go
- events.go
- events_test.go
- export.go
- export_alert.go
- export_alertprovider.go
- export_helmrelease.go
- export_image.go
- export_image_policy.go
- export_image_repository.go
- export_image_update.go
- export_kustomization.go
- export_receiver.go
- export_secret.go
- export_source.go
- export_source_bucket.go
- export_source_git.go
- export_source_helm.go
- export_source_oci.go
- export_test.go
- get.go
- get_alert.go
- get_alertprovider.go
- get_all.go
- get_helmrelease.go
- get_image.go
- get_image_all.go
- get_image_policy.go
- get_image_repository.go
- get_image_update.go
- get_kustomization.go
- get_receiver.go
- get_source.go
- get_source_all.go
- get_source_bucket.go
- get_source_chart.go
- get_source_git.go
- get_source_helm.go
- get_source_oci.go
- get_test.go
- helmrelease.go
- helmrelease_test.go
- image.go
- image_test.go
- install.go
- install_test.go
- kustomization.go
- kustomization_test.go
- list.go
- list_artifact.go
- log.go
- logs.go
- logs_e2e_test.go
- logs_unit_test.go
- main.go
- main_e2e_test.go
- main_test.go
- main_unit_test.go
- manifests.embed.go
- object.go
- pull.go
- pull_artifact.go
- push.go
- push_artifact.go
- readiness.go
- readiness_test.go
- receiver.go
- reconcile.go
- reconcile_helmrelease.go
- reconcile_image.go
- reconcile_image_repository.go
- reconcile_image_updateauto.go
- reconcile_kustomization.go
- reconcile_receiver.go
- reconcile_source.go
- reconcile_source_bucket.go
- reconcile_source_chart.go
- reconcile_source_git.go
- reconcile_source_helm.go
- reconcile_source_oci.go
- reconcile_with_source.go
- resume.go
- resume_alert.go
- resume_alertprovider.go
- resume_helmrelease.go
- resume_image.go
- resume_image_repository.go
- resume_image_updateauto.go
- resume_kustomization.go
- resume_receiver.go
- resume_source.go
- resume_source_bucket.go
- resume_source_chart.go
- resume_source_git.go
- resume_source_helm.go
- resume_source_oci.go
- source.go
- source_oci_test.go
- stats.go
- status.go
- suspend.go
- suspend_alert.go
- suspend_alertprovider.go
- suspend_helmrelease.go
- suspend_image.go
- suspend_image_repository.go
- suspend_image_updateauto.go
- suspend_kustomization.go
- suspend_receiver.go
- suspend_source.go
- suspend_source_bucket.go
- suspend_source_chart.go
- suspend_source_git.go
- suspend_source_helm.go
- suspend_source_oci.go
- tag.go
- tag_artifact.go
- trace.go
- trace_test.go
- tree.go
- tree_kustomization.go
- tree_kustomization_test.go
- uninstall.go
- version.go
- version_test.go
- version_utils.go
- version_utils_test.go
-
testdata
-
flux
- docs
- install
-
internal
- build
-
flags
- crds.go
- crds_test.go
- decryption_provider.go
- decryption_provider_test.go
- ecdsa_curve.go
- ecdsa_curve_test.go
- helm_chart_source.go
- helm_chart_source_test.go
- kustomization_source.go
- kustomization_source_test.go
- log_level.go
- log_level_test.go
- public_key_algorithm.go
- public_key_algorithm_test.go
- rsa_key_bits.go
- rsa_key_bits_test.go
- safe_relative_path.go
- safe_relative_path_test.go
- source_bucket_provider.go
- source_bucket_provider_test.go
- source_oci_provider.go
- source_oci_verify_provider.go
- source_oci_verify_provider_test.go
- tree
- utils
-
manifests
- bases
- crds
- install
- integrations
- monitoring
- openshift
- policies
- rbac
- scripts
- pkg
- rfcs
- tests
- .gitignore
- .goreleaser.yml
- CODE_OF_CONDUCT.md
- CONTRIBUTING.md
- DCO
- Dockerfile
- LICENSE
- MAINTAINERS
- Makefile
- README.md
- go.mod
- go.sum
- netlify.toml
Explanation
This code defines tests for the trace command in the Flux v2 CLI. The trace command displays the reconciliation history of Kubernetes resources.
Test Cases
The TestTraceNoArgs test checks that the command fails if it is not provided with the required arguments (<resource>/<name> or <resource> <name>).
The TestTrace test suite covers various scenarios, using different resource types:
- Deployment: This tests tracing a deployment object.
- HelmRelease: This tests tracing a HelmRelease object.
- HelmRelease from OCI registry: This tests tracing a HelmRelease object that uses an OCI registry.
Test Logic
Each test case in the TestTrace suite uses a golden file to compare the output of the trace command with the expected output. The golden file is a template containing placeholders that are replaced with actual values during the test.
Here’s a breakdown of the steps involved:
- Create a Test Object: The
CreateObjectFilefunction creates a YAML file representing the resource object under test. This file is used as input to thetracecommand. - Run the
traceCommand: TherunTestCmdfunction executes thetracecommand with the specified arguments. - Compare Output with Golden File: The
assertGoldenTemplateFilefunction compares the actual output of thetracecommand with the content of the golden file, after replacing the placeholders in the golden file with actual values.
Helper Functions
toLocalTime: This helper function converts a UTC timestamp string to a local timestamp string.allocateNamespace: This helper function allocates a unique namespace for testing.
Conclusion
This code provides comprehensive testing for the trace command, ensuring that it correctly handles different resource types and displays accurate reconciliation history information. It uses golden files and template replacement for a robust and maintainable approach to testing.
Graph
The graph shows the usage of functions within the codebase.
Select a code symbol to view it's graph