Files
qdrant-helm/test/qdrant_additional_labels_test.go
dependabot[bot] 820964b58f Bump golangci/golangci-lint-action from 6 to 7 (#318)
* Bump golangci/golangci-lint-action from 6 to 7

Bumps [golangci/golangci-lint-action](https://github.com/golangci/golangci-lint-action) from 6 to 7.
- [Release notes](https://github.com/golangci/golangci-lint-action/releases)
- [Commits](https://github.com/golangci/golangci-lint-action/compare/v6...v7)

---
updated-dependencies:
- dependency-name: golangci/golangci-lint-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* Update golangci-lint version

* Fix lint issues

* Update dependency

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Bastian Hofmann <mail@bastianhofmann.de>
2025-04-10 13:23:46 +02:00

155 lines
4.8 KiB
Go

package test
import (
"path/filepath"
"strings"
"testing"
monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
"github.com/stretchr/testify/require"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
networkingv1 "k8s.io/api/networking/v1"
"github.com/gruntwork-io/terratest/modules/helm"
"github.com/gruntwork-io/terratest/modules/k8s"
"github.com/gruntwork-io/terratest/modules/logger"
"github.com/gruntwork-io/terratest/modules/random"
)
func TestAdditionalLabelsAreSetOnStatefulset(t *testing.T) {
t.Parallel()
helmChartPath, err := filepath.Abs("../charts/qdrant")
releaseName := "qdrant"
require.NoError(t, err)
namespaceName := "qdrant-" + strings.ToLower(random.UniqueId())
logger.Log(t, "Namespace: %s\n", namespaceName)
options := &helm.Options{
SetJsonValues: map[string]string{
"additionalLabels": `{"test": "additionalLabels"}`,
"podLabels": `{"test": "podLabels"}`,
"service.additionalLabels": `{"test": "serviceAdditionalLabels"}`,
},
KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName),
}
output := helm.RenderTemplate(t, options, helmChartPath, releaseName, []string{"templates/statefulset.yaml"})
var statefulSet appsv1.StatefulSet
helm.UnmarshalK8SYaml(t, output, &statefulSet)
require.Contains(t, statefulSet.Labels, "test")
require.Equal(t, "additionalLabels", statefulSet.Labels["test"])
require.Contains(t, statefulSet.Spec.Template.Labels, "test")
require.Equal(t, "podLabels", statefulSet.Spec.Template.Labels["test"])
}
func TestAdditionalLabelsAreSetOnService(t *testing.T) {
t.Parallel()
helmChartPath, err := filepath.Abs("../charts/qdrant")
releaseName := "qdrant"
require.NoError(t, err)
namespaceName := "qdrant-" + strings.ToLower(random.UniqueId())
logger.Log(t, "Namespace: %s\n", namespaceName)
options := &helm.Options{
SetJsonValues: map[string]string{
"service.additionalLabels": `{"test": "serviceAdditionalLabels"}`,
},
KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName),
}
output := helm.RenderTemplate(t, options, helmChartPath, releaseName, []string{"templates/service.yaml"})
var service corev1.Service
helm.UnmarshalK8SYaml(t, output, &service)
require.Contains(t, service.Labels, "test")
require.Equal(t, "serviceAdditionalLabels", service.Labels["test"])
}
func TestAdditionalLabelsAreSetOnServiceHeadless(t *testing.T) {
t.Parallel()
helmChartPath, err := filepath.Abs("../charts/qdrant")
releaseName := "qdrant"
require.NoError(t, err)
namespaceName := "qdrant-" + strings.ToLower(random.UniqueId())
logger.Log(t, "Namespace: %s\n", namespaceName)
options := &helm.Options{
SetJsonValues: map[string]string{
"service.additionalLabels": `{"test": "serviceAdditionalLabels"}`,
},
KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName),
}
output := helm.RenderTemplate(t, options, helmChartPath, releaseName, []string{"templates/service-headless.yaml"})
var service corev1.Service
helm.UnmarshalK8SYaml(t, output, &service)
require.Contains(t, service.Labels, "test")
require.Equal(t, "serviceAdditionalLabels", service.Labels["test"])
}
func TestAdditionalLabelsAreSetOnServiceMonitor(t *testing.T) {
t.Parallel()
helmChartPath, err := filepath.Abs("../charts/qdrant")
releaseName := "qdrant"
require.NoError(t, err)
namespaceName := "qdrant-" + strings.ToLower(random.UniqueId())
logger.Log(t, "Namespace: %s\n", namespaceName)
options := &helm.Options{
SetJsonValues: map[string]string{
"metrics.serviceMonitor.enabled": `true`,
"metrics.serviceMonitor.additionalLabels": `{"test": "serviceMonitorAdditionalLabels"}`,
},
KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName),
}
output := helm.RenderTemplate(t, options, helmChartPath, releaseName, []string{"templates/servicemonitor.yaml"})
var serviceMonitor monitoringv1.ServiceMonitor
helm.UnmarshalK8SYaml(t, output, &serviceMonitor)
require.Contains(t, serviceMonitor.Labels, "test")
require.Equal(t, "serviceMonitorAdditionalLabels", serviceMonitor.Labels["test"])
}
func TestAdditionalLabelsAreSetOnIngress(t *testing.T) {
t.Parallel()
helmChartPath, err := filepath.Abs("../charts/qdrant")
releaseName := "qdrant"
require.NoError(t, err)
namespaceName := "qdrant-" + strings.ToLower(random.UniqueId())
logger.Log(t, "Namespace: %s\n", namespaceName)
options := &helm.Options{
SetJsonValues: map[string]string{
"ingress.enabled": `true`,
"ingress.additionalLabels": `{"test": "ingressAdditionalLabels"}`,
},
KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName),
}
output := helm.RenderTemplate(t, options, helmChartPath, releaseName, []string{"templates/ingress.yaml"})
var ingress networkingv1.Ingress
helm.UnmarshalK8SYaml(t, output, &ingress)
require.Contains(t, ingress.Labels, "test")
require.Equal(t, "ingressAdditionalLabels", ingress.Labels["test"])
}