@@ -39,56 +39,124 @@ func TestServiceHashWithIgnorableValues(t *testing.T) {
3939 assert .Equal (t , hash1 , hash2 )
4040}
4141
42- func TestServiceDependenciesHashWithoutChangesContent (t * testing.T ) {
43- hash1 , err := ServiceDependenciesHash ( projectConfig ( "myConfigSource" , "a" , "" , "" ), serviceConfig ("myContext1" , "always" , 1 ))
42+ func TestServiceConfigsHashWithoutChangesContent (t * testing.T ) {
43+ hash1 , err := ServiceConfigsHash ( projectWithConfigs ( "a" , "" , "" ), serviceConfig ("myContext1" , "always" , 1 ))
4444 assert .NilError (t , err )
45- hash2 , err := ServiceDependenciesHash ( projectConfig ( "myConfigSource" , "a" , "" , "" ), serviceConfig ("myContext2" , "never" , 2 ))
45+ hash2 , err := ServiceConfigsHash ( projectWithConfigs ( "a" , "" , "" ), serviceConfig ("myContext2" , "never" , 2 ))
4646 assert .NilError (t , err )
4747 assert .Assert (t , hash1 == hash2 )
4848}
4949
50- func TestServiceDependenciesHashWithChangedConfigContent (t * testing.T ) {
51- hash1 , err := ServiceDependenciesHash ( projectConfig ( "myConfigSource" , "a" , "" , "" ), serviceConfig ("myContext1" , "always" , 1 ))
50+ func TestServiceConfigsHashWithChangedConfigContent (t * testing.T ) {
51+ hash1 , err := ServiceConfigsHash ( projectWithConfigs ( "a" , "" , "" ), serviceConfig ("myContext1" , "always" , 1 ))
5252 assert .NilError (t , err )
53- hash2 , err := ServiceDependenciesHash ( projectConfig ( "myConfigSource" , "b" , "" , "" ), serviceConfig ("myContext2" , "never" , 2 ))
53+ hash2 , err := ServiceConfigsHash ( projectWithConfigs ( "b" , "" , "" ), serviceConfig ("myContext2" , "never" , 2 ))
5454 assert .NilError (t , err )
5555 assert .Assert (t , hash1 != hash2 )
5656}
5757
58- func TestServiceDependenciesHashWithChangedConfigEnvironment (t * testing.T ) {
59- hash1 , err := ServiceDependenciesHash ( projectConfig ( "myConfigSource" , "" , "a" , "" ), serviceConfig ("myContext1" , "always" , 1 ))
58+ func TestServiceConfigsHashWithChangedConfigEnvironment (t * testing.T ) {
59+ hash1 , err := ServiceConfigsHash ( projectWithConfigs ( "" , "a" , "" ), serviceConfig ("myContext1" , "always" , 1 ))
6060 assert .NilError (t , err )
61- hash2 , err := ServiceDependenciesHash ( projectConfig ( "myConfigSource" , "" , "b" , "" ), serviceConfig ("myContext2" , "never" , 2 ))
61+ hash2 , err := ServiceConfigsHash ( projectWithConfigs ( "" , "b" , "" ), serviceConfig ("myContext2" , "never" , 2 ))
6262 assert .NilError (t , err )
6363 assert .Assert (t , hash1 != hash2 )
6464}
6565
66- func TestServiceDependenciesHashWithChangedConfigFile (t * testing.T ) {
67- hash1 , err := ServiceDependenciesHash (
68- projectConfig ( "myConfigSource" , "" , "" , "./testdata/config1.txt" ),
66+ func TestServiceConfigsHashWithChangedConfigFile (t * testing.T ) {
67+ hash1 , err := ServiceConfigsHash (
68+ projectWithConfigs ( "" , "" , "./testdata/config1.txt" ),
6969 serviceConfig ("myContext1" , "always" , 1 ),
7070 )
7171 assert .NilError (t , err )
72- hash2 , err := ServiceDependenciesHash (
73- projectConfig ( "myConfigSource" , "" , "" , "./testdata/config2.txt" ),
72+ hash2 , err := ServiceConfigsHash (
73+ projectWithConfigs ( "" , "" , "./testdata/config2.txt" ),
7474 serviceConfig ("myContext2" , "never" , 2 ),
7575 )
7676 assert .NilError (t , err )
7777 assert .Assert (t , hash1 != hash2 )
7878}
7979
80- func projectConfig (configName , configContent , configEnvironment , configFile string ) * types.Project {
80+ func TestServiceSecretsHashWithoutChangesContent (t * testing.T ) {
81+ hash1 , err := ServiceSecretsHash (projectWithSecrets ("a" , "" , "" ), serviceConfig ("myContext1" , "always" , 1 ))
82+ assert .NilError (t , err )
83+ hash2 , err := ServiceSecretsHash (projectWithSecrets ("a" , "" , "" ), serviceConfig ("myContext2" , "never" , 2 ))
84+ assert .NilError (t , err )
85+ assert .Assert (t , hash1 == hash2 )
86+ }
87+
88+ func TestServiceSecretsHashWithChangedSecretContent (t * testing.T ) {
89+ hash1 , err := ServiceSecretsHash (projectWithSecrets ("a" , "" , "" ), serviceConfig ("myContext1" , "always" , 1 ))
90+ assert .NilError (t , err )
91+ hash2 , err := ServiceSecretsHash (projectWithSecrets ("b" , "" , "" ), serviceConfig ("myContext2" , "never" , 2 ))
92+ assert .NilError (t , err )
93+ assert .Assert (t , hash1 != hash2 )
94+ }
95+
96+ func TestServiceSecretsHashWithChangedSecretEnvironment (t * testing.T ) {
97+ hash1 , err := ServiceSecretsHash (projectWithSecrets ("" , "a" , "" ), serviceConfig ("myContext1" , "always" , 1 ))
98+ assert .NilError (t , err )
99+ hash2 , err := ServiceSecretsHash (projectWithSecrets ("" , "b" , "" ), serviceConfig ("myContext2" , "never" , 2 ))
100+ assert .NilError (t , err )
101+ assert .Assert (t , hash1 != hash2 )
102+ }
103+
104+ func TestServiceSecretsHashWithChangedSecretFile (t * testing.T ) {
105+ hash1 , err := ServiceSecretsHash (
106+ projectWithSecrets ("" , "" , "./testdata/config1.txt" ),
107+ serviceConfig ("myContext1" , "always" , 1 ),
108+ )
109+ assert .NilError (t , err )
110+ hash2 , err := ServiceSecretsHash (
111+ projectWithSecrets ("" , "" , "./testdata/config2.txt" ),
112+ serviceConfig ("myContext2" , "never" , 2 ),
113+ )
114+ assert .NilError (t , err )
115+ assert .Assert (t , hash1 != hash2 )
116+ }
117+
118+ func projectWithConfigs (configContent , configEnvironmentValue , configFile string ) * types.Project {
119+ envName := "myEnv"
120+
121+ if configEnvironmentValue == "" {
122+ envName = ""
123+ }
124+
81125 return & types.Project {
126+ Environment : types.Mapping {
127+ envName : configEnvironmentValue ,
128+ },
82129 Configs : types.Configs {
83- configName : types.ConfigObjConfig {
130+ "myConfigSource" : types.ConfigObjConfig {
84131 Content : configContent ,
85- Environment : configEnvironment ,
132+ Environment : envName ,
86133 File : configFile ,
87134 },
88135 },
89136 }
90137}
91138
139+ func projectWithSecrets (secretContent , secretEnvironmentValue , secretFile string ) * types.Project {
140+ envName := "myEnv"
141+
142+ if secretEnvironmentValue == "" {
143+ envName = ""
144+ }
145+
146+ return & types.Project {
147+ Environment : types.Mapping {
148+ envName : secretEnvironmentValue ,
149+ },
150+ Secrets : types.Secrets {
151+ "mySecretSource" : types.SecretConfig {
152+ Content : secretContent ,
153+ Environment : envName ,
154+ File : secretFile ,
155+ },
156+ },
157+ }
158+ }
159+
92160func serviceConfig (buildContext , pullPolicy string , replicas int ) types.ServiceConfig {
93161 return types.ServiceConfig {
94162 Build : & types.BuildConfig {
@@ -106,5 +174,10 @@ func serviceConfig(buildContext, pullPolicy string, replicas int) types.ServiceC
106174 Source : "myConfigSource" ,
107175 },
108176 },
177+ Secrets : []types.ServiceSecretConfig {
178+ {
179+ Source : "mySecretSource" ,
180+ },
181+ },
109182 }
110183}
0 commit comments