Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding tests for grafana version #1480

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 49 additions & 1 deletion controllers/reconcilers/grafana/deployment_reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (

"github.com/grafana/grafana-operator/v5/api/v1beta1"
config2 "github.com/grafana/grafana-operator/v5/controllers/config"

"github.com/stretchr/testify/assert"
v14 "k8s.io/api/core/v1"
)

func Test_getGrafanaImage(t *testing.T) {
Expand Down Expand Up @@ -46,3 +46,51 @@ func Test_getGrafanaImage_withEnvironmentOverride(t *testing.T) {

assert.Equal(t, expectedDeploymentImage, getGrafanaImage(cr))
}

func Test_getGrafanaImage_withDeployment(t *testing.T) {
expectedDeploymentImage := "myprivate-repo/grafana:10.4.0"
cr := &v1beta1.Grafana{
Spec: v1beta1.GrafanaSpec{
Deployment: &v1beta1.DeploymentV1{
Spec: v1beta1.DeploymentV1Spec{
Template: &v1beta1.DeploymentV1PodTemplateSpec{
Spec: &v1beta1.DeploymentV1PodSpec{
Containers: []v14.Container{
{
Name: "grafana",
Image: expectedDeploymentImage,
},
},
},
},
},
},
},
}

assert.Equal(t, expectedDeploymentImage, getGrafanaImage(cr))
}

func Test_getGrafanaImage_withDeploymentOverwrite(t *testing.T) {
expectedDeploymentImage := "myprivate-repo/grafana:10.4.0"
cr := &v1beta1.Grafana{
Spec: v1beta1.GrafanaSpec{
Deployment: &v1beta1.DeploymentV1{
Spec: v1beta1.DeploymentV1Spec{
Template: &v1beta1.DeploymentV1PodTemplateSpec{
Spec: &v1beta1.DeploymentV1PodSpec{
Containers: []v14.Container{
{
Name: "grafana",
Image: expectedDeploymentImage,
},
},
},
},
},
},
Version: "10.3.0",
},
}
assert.Equal(t, expectedDeploymentImage, getGrafanaImage(cr))
}
18 changes: 18 additions & 0 deletions tests/e2e/example-test/00-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,21 @@ status:
stage: complete
stageStatus: success
version: 10.3.5
---
apiVersion: grafana.integreatly.org/v1beta1
kind: Grafana
metadata:
name: grafana-ten-deployment
status:
stage: complete
stageStatus: success
version: 10.4.0
---
apiVersion: grafana.integreatly.org/v1beta1
kind: Grafana
metadata:
name: grafana-ten-deployment-overwrite
status:
stage: complete
stageStatus: success
version: 10.4.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
apiVersion: grafana.integreatly.org/v1beta1
kind: Grafana
metadata:
name: grafana-ten-deployment-overwrite
labels:
dashboards: "grafana-deployment"
spec:
client:
preferIngress: false
deployment:
spec:
replicas: 2
template:
spec:
containers:
- name: grafana
image: grafana/grafana:10.4.0
version: 10.3.5
config:
log:
mode: "console"
auth:
disable_login_form: "false"
security:
admin_user: root
admin_password: secret
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: grafana.integreatly.org/v1beta1
kind: Grafana
metadata:
name: grafana-ten-deployment
labels:
dashboards: "grafana-deployment"
spec:
client:
preferIngress: false
deployment:
spec:
replicas: 2
template:
spec:
containers:
- name: grafana
image: grafana/grafana:10.4.0
config:
log:
mode: "console"
auth:
disable_login_form: "false"
security:
admin_user: root
admin_password: secret
4 changes: 4 additions & 0 deletions tests/e2e/example-test/chainsaw-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ spec:
file: 00-create-grafana.yaml
- apply:
file: 00-create-versioned-grafana.yaml
- apply:
file: 00-create-versioned-grafana-deployment.yaml
- apply:
file: 00-create-versioned-grafana-deployment-overwrite.yaml
- assert:
file: 00-assert.yaml
- name: step-01
Expand Down
Loading