11package construct
22
33import (
4- "os"
54 "reflect"
65 "testing"
76
@@ -21,10 +20,6 @@ import (
2120 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2221)
2322
24- func init () {
25- os .Setenv (VersionUpgradeHookImageEnv , "version-upgrade-hook-image" )
26- }
27-
2823func newTestReplicaSet () mdbv1.MongoDBCommunity {
2924 return mdbv1.MongoDBCommunity {
3025 ObjectMeta : metav1.ObjectMeta {
@@ -40,12 +35,8 @@ func newTestReplicaSet() mdbv1.MongoDBCommunity {
4035}
4136
4237func TestMultipleCalls_DoNotCauseSideEffects (t * testing.T ) {
43- t .Setenv (MongodbRepoUrl , "docker.io/mongodb" )
44- t .Setenv (MongodbImageEnv , "mongodb-community-server" )
45- t .Setenv (AgentImageEnv , "agent-image" )
46-
4738 mdb := newTestReplicaSet ()
48- stsFunc := BuildMongoDBReplicaSetStatefulSetModificationFunction (& mdb , & mdb , os . Getenv ( AgentImageEnv ) , true )
39+ stsFunc := BuildMongoDBReplicaSetStatefulSetModificationFunction (& mdb , & mdb , "docker.io/mongodb" , "mongodb-community-server" , "ubi8" , "agent-image" , "version-upgrade-hook-image" , "fake-readinessProbeImage" , true )
4940 sts := & appsv1.StatefulSet {}
5041
5142 t .Run ("1st Call" , func (t * testing.T ) {
@@ -63,13 +54,10 @@ func TestMultipleCalls_DoNotCauseSideEffects(t *testing.T) {
6354}
6455
6556func TestManagedSecurityContext (t * testing.T ) {
66- t .Setenv (MongodbRepoUrl , "docker.io/mongodb" )
67- t .Setenv (MongodbImageEnv , "mongodb-community-server" )
68- t .Setenv (AgentImageEnv , "agent-image" )
6957 t .Setenv (podtemplatespec .ManagedSecurityContextEnv , "true" )
7058
7159 mdb := newTestReplicaSet ()
72- stsFunc := BuildMongoDBReplicaSetStatefulSetModificationFunction (& mdb , & mdb , os . Getenv ( AgentImageEnv ) , true )
60+ stsFunc := BuildMongoDBReplicaSetStatefulSetModificationFunction (& mdb , & mdb , "docker.io/mongodb" , "mongodb-community-server" , "ubi8" , "agent-image" , "version-upgrade-hook-image" , "fake-readinessProbeImage" , true )
7361
7462 sts := & appsv1.StatefulSet {}
7563 stsFunc (sts )
@@ -79,87 +67,77 @@ func TestManagedSecurityContext(t *testing.T) {
7967
8068func TestGetMongoDBImage (t * testing.T ) {
8169 type testConfig struct {
82- setArgs func (t * testing.T )
83- version string
84- expectedImage string
70+ mongodbRepoUrl string
71+ mongodbImage string
72+ mongodbImageType string
73+ version string
74+ expectedImage string
8575 }
8676 tests := map [string ]testConfig {
8777 "Default UBI8 Community image" : {
88- setArgs : func (t * testing.T ) {
89- t .Setenv (MongodbRepoUrl , "docker.io/mongodb" )
90- t .Setenv (MongodbImageEnv , "mongodb-community-server" )
91- },
92- version : "6.0.5" ,
93- expectedImage : "docker.io/mongodb/mongodb-community-server:6.0.5-ubi8" ,
78+ mongodbRepoUrl : "docker.io/mongodb" ,
79+ mongodbImage : "mongodb-community-server" ,
80+ mongodbImageType : "ubi8" ,
81+ version : "6.0.5" ,
82+ expectedImage : "docker.io/mongodb/mongodb-community-server:6.0.5-ubi8" ,
9483 },
9584 "Overridden UBI8 Enterprise image" : {
96- setArgs : func (t * testing.T ) {
97- t .Setenv (MongodbRepoUrl , "docker.io/mongodb" )
98- t .Setenv (MongodbImageEnv , "mongodb-enterprise-server" )
99- },
100- version : "6.0.5" ,
101- expectedImage : "docker.io/mongodb/mongodb-enterprise-server:6.0.5-ubi8" ,
85+ mongodbRepoUrl : "docker.io/mongodb" ,
86+ mongodbImage : "mongodb-enterprise-server" ,
87+ mongodbImageType : "ubi8" ,
88+ version : "6.0.5" ,
89+ expectedImage : "docker.io/mongodb/mongodb-enterprise-server:6.0.5-ubi8" ,
10290 },
10391 "Overridden UBI8 Enterprise image from Quay" : {
104- setArgs : func (t * testing.T ) {
105- t .Setenv (MongodbRepoUrl , "quay.io/mongodb" )
106- t .Setenv (MongodbImageEnv , "mongodb-enterprise-server" )
107- },
108- version : "6.0.5" ,
109- expectedImage : "quay.io/mongodb/mongodb-enterprise-server:6.0.5-ubi8" ,
92+ mongodbRepoUrl : "quay.io/mongodb" ,
93+ mongodbImage : "mongodb-enterprise-server" ,
94+ mongodbImageType : "ubi8" ,
95+ version : "6.0.5" ,
96+ expectedImage : "quay.io/mongodb/mongodb-enterprise-server:6.0.5-ubi8" ,
11097 },
11198 "Overridden Ubuntu Community image" : {
112- setArgs : func (t * testing.T ) {
113- t .Setenv (MongodbRepoUrl , "docker.io/mongodb" )
114- t .Setenv (MongodbImageEnv , "mongodb-community-server" )
115- t .Setenv (MongoDBImageType , "ubuntu2204" )
116- },
117- version : "6.0.5" ,
118- expectedImage : "docker.io/mongodb/mongodb-community-server:6.0.5-ubuntu2204" ,
99+ mongodbRepoUrl : "docker.io/mongodb" ,
100+ mongodbImage : "mongodb-community-server" ,
101+ mongodbImageType : "ubuntu2204" ,
102+ version : "6.0.5" ,
103+ expectedImage : "docker.io/mongodb/mongodb-community-server:6.0.5-ubuntu2204" ,
119104 },
120105 "Overridden UBI Community image" : {
121- setArgs : func (t * testing.T ) {
122- t .Setenv (MongodbRepoUrl , "docker.io/mongodb" )
123- t .Setenv (MongodbImageEnv , "mongodb-community-server" )
124- t .Setenv (MongoDBImageType , "ubi8" )
125- },
126- version : "6.0.5" ,
127- expectedImage : "docker.io/mongodb/mongodb-community-server:6.0.5-ubi8" ,
106+ mongodbRepoUrl : "docker.io/mongodb" ,
107+ mongodbImage : "mongodb-community-server" ,
108+ mongodbImageType : "ubi8" ,
109+ version : "6.0.5" ,
110+ expectedImage : "docker.io/mongodb/mongodb-community-server:6.0.5-ubi8" ,
128111 },
129112 "Docker Inc images" : {
130- setArgs : func (t * testing.T ) {
131- t .Setenv (MongodbRepoUrl , "docker.io" )
132- t .Setenv (MongodbImageEnv , "mongo" )
133- },
134- version : "6.0.5" ,
135- expectedImage : "docker.io/mongo:6.0.5" ,
113+ mongodbRepoUrl : "docker.io" ,
114+ mongodbImage : "mongo" ,
115+ mongodbImageType : "ubi8" ,
116+ version : "6.0.5" ,
117+ expectedImage : "docker.io/mongo:6.0.5" ,
136118 },
137119 "Deprecated AppDB images defined the old way" : {
138- setArgs : func (t * testing.T ) {
139- t .Setenv (MongodbRepoUrl , "quay.io" )
140- t .Setenv (MongodbImageEnv , "mongodb/mongodb-enterprise-appdb-database-ubi" )
141- // In this example, we intentionally don't use the suffix from the env. variable and let users
142- // define it in the version instead. There are some known customers who do this.
143- // This is a backwards compatibility case.
144- t .Setenv (MongoDBImageType , "will-be-ignored" )
145- },
146-
147- version : "5.0.14-ent" ,
148- expectedImage : "quay.io/mongodb/mongodb-enterprise-appdb-database-ubi:5.0.14-ent" ,
120+ mongodbRepoUrl : "quay.io" ,
121+ mongodbImage : "mongodb/mongodb-enterprise-appdb-database-ubi" ,
122+ // In this example, we intentionally don't use the suffix from the env. variable and let users
123+ // define it in the version instead. There are some known customers who do this.
124+ // This is a backwards compatibility case.
125+ mongodbImageType : "will-be-ignored" ,
126+ version : "5.0.14-ent" ,
127+ expectedImage : "quay.io/mongodb/mongodb-enterprise-appdb-database-ubi:5.0.14-ent" ,
149128 },
150129 }
151130 for testName := range tests {
152131 t .Run (testName , func (t * testing.T ) {
153132 testConfig := tests [testName ]
154- testConfig .setArgs (t )
155- image := getMongoDBImage (testConfig .version )
133+ image := getMongoDBImage (testConfig .mongodbRepoUrl , testConfig .mongodbImage , testConfig .mongodbImageType , testConfig .version )
156134 assert .Equal (t , testConfig .expectedImage , image )
157135 })
158136 }
159137}
160138
161139func TestMongod_Container (t * testing.T ) {
162- c := container .New (mongodbContainer ("4.2" , []corev1.VolumeMount {}, mdbv1 .NewMongodConfiguration ()))
140+ c := container .New (mongodbContainer ("fake-repo-url" , "fake-image" , "ubi8" , " 4.2" , []corev1.VolumeMount {}, mdbv1 .NewMongodConfiguration ()))
163141
164142 t .Run ("Has correct Env vars" , func (t * testing.T ) {
165143 assert .Len (t , c .Env , 1 )
@@ -168,7 +146,7 @@ func TestMongod_Container(t *testing.T) {
168146 })
169147
170148 t .Run ("Image is correct" , func (t * testing.T ) {
171- assert .Equal (t , getMongoDBImage ("4.2" ), c .Image )
149+ assert .Equal (t , getMongoDBImage ("fake-repo-url" , "fake-image" , "ubi8" , " 4.2" ), c .Image )
172150 })
173151
174152 t .Run ("Resource requirements are correct" , func (t * testing.T ) {
0 commit comments