@@ -1639,7 +1639,7 @@ func TestAssembleTerraformJobWithGitCredentialsSecretRef(t *testing.T) {
1639
1639
assert .Contains (t , spec .Volumes , gitAuthSecretVolume )
1640
1640
}
1641
1641
1642
- func TestAssembleTerraformJobWithTerraformRegistryConfigAndCredentialsSecretRef (t * testing.T ) {
1642
+ func TestAssembleTerraformJobWithTerraformRCAndCredentials (t * testing.T ) {
1643
1643
meta := & TFConfigurationMeta {
1644
1644
Name : "a" ,
1645
1645
ConfigurationCMName : "b" ,
@@ -1656,6 +1656,10 @@ func TestAssembleTerraformJobWithTerraformRegistryConfigAndCredentialsSecretRef(
1656
1656
Namespace : "default" ,
1657
1657
Name : "terraform-credentials" ,
1658
1658
},
1659
+ TerraformCredentialsHelperConfigMapReference : & corev1.SecretReference {
1660
+ Namespace : "default" ,
1661
+ Name : "terraform-credentials-helper" ,
1662
+ },
1659
1663
}
1660
1664
1661
1665
job := meta .assembleTerraformJob (TerraformApply )
@@ -1686,15 +1690,33 @@ func TestAssembleTerraformJobWithTerraformRegistryConfigAndCredentialsSecretRef(
1686
1690
MountPath : TerraformCredentialsConfigVolumeMountPath ,
1687
1691
}
1688
1692
1693
+ terraformCredentialsHelperConfigVolume := corev1.Volume {Name : TerraformCredentialsHelperConfigVolumeName }
1694
+ terraformCredentialsHelperConfigVolume .ConfigMap = & corev1.ConfigMapVolumeSource {
1695
+ LocalObjectReference : corev1.LocalObjectReference {
1696
+ Name : "terraform-credentials-helper" ,
1697
+ },
1698
+ DefaultMode : & terraformSecretDefaultMode ,
1699
+ }
1700
+
1701
+ terraformCredentialsHelperConfigVolumeMount := corev1.VolumeMount {
1702
+ Name : TerraformCredentialsHelperConfigVolumeName ,
1703
+ MountPath : TerraformCredentialsHelperConfigVolumeMountPath ,
1704
+ }
1705
+
1706
+ assert .Contains (t , spec .InitContainers [0 ].VolumeMounts , terraformCredentialsHelperConfigVolumeMount )
1707
+ assert .Contains (t , spec .Volumes , terraformCredentialsHelperConfigVolume )
1708
+
1689
1709
assert .Contains (t , spec .InitContainers [0 ].VolumeMounts , terraformRegistryConfigVolumeMount )
1690
1710
assert .Contains (t , spec .Volumes , terraformRegistryConfigMapVolume )
1691
1711
1692
1712
assert .Contains (t , spec .InitContainers [0 ].VolumeMounts , terraformCredentialsSecretVolumeMount )
1693
1713
assert .Contains (t , spec .Volumes , terraformCredentialsSecretVolume )
1694
1714
1715
+ assert .Contains (t , spec .InitContainers [0 ].VolumeMounts , terraformRegistryConfigVolumeMount )
1716
+ assert .Contains (t , spec .Volumes , terraformRegistryConfigMapVolume )
1695
1717
}
1696
1718
1697
- func TestAssembleTerraformJobWithTerraformRegistryConfigAndCredentialsHelperConfigMapRef (t * testing.T ) {
1719
+ func TestAssembleTerraformJobWithTerraformRCAndCredentialsHelper (t * testing.T ) {
1698
1720
meta := & TFConfigurationMeta {
1699
1721
Name : "a" ,
1700
1722
ConfigurationCMName : "b" ,
@@ -2757,12 +2779,11 @@ func TestCheckGitCredentialsSecretReference(t *testing.T) {
2757
2779
},
2758
2780
}
2759
2781
neededKeys := []string {GitCredsKnownHosts , corev1 .SSHAuthPrivateKey }
2760
- errMsg := "Failed to get git credentials secret"
2761
- keyErrMsg := "not in git credentials secret"
2782
+ errKey := "git credentials"
2762
2783
2763
2784
for _ , tc := range testcases {
2764
2785
t .Run (tc .name , func (t * testing.T ) {
2765
- sec , err := GetSecretOrConfigMap (ctx , tc .args .k8sClient , true , tc .args .GitCredentialsSecretReference , neededKeys , errMsg , keyErrMsg )
2786
+ sec , err := GetSecretOrConfigMap (ctx , tc .args .k8sClient , true , tc .args .GitCredentialsSecretReference , neededKeys , errKey )
2766
2787
if err != nil {
2767
2788
assert .EqualError (t , err , tc .want .errMsg )
2768
2789
}
@@ -2830,11 +2851,11 @@ func TestCheckTerraformCredentialsSecretReference(t *testing.T) {
2830
2851
k8sClient : k8sClient ,
2831
2852
TerraformCredentialsSecretReference : & corev1.SecretReference {
2832
2853
Namespace : "default" ,
2833
- Name : "terraform-credentials " ,
2854
+ Name : "secret-not-exists " ,
2834
2855
},
2835
2856
},
2836
2857
want : want {
2837
- errMsg : "Failed to get terraform credentials secret: secrets \" terraform-credentials \" not found" ,
2858
+ errMsg : "Failed to get terraform credentials secret: secrets \" secret-not-exists \" not found" ,
2838
2859
},
2839
2860
},
2840
2861
{
@@ -2866,12 +2887,11 @@ func TestCheckTerraformCredentialsSecretReference(t *testing.T) {
2866
2887
}
2867
2888
2868
2889
neededKeys := []string {TerraformCredentials }
2869
- errMsg := "Failed to get terraform credentials secret"
2870
- keyErrMsg := "not in terraform credentials secret"
2890
+ errKey := "terraform credentials"
2871
2891
2872
2892
for _ , tc := range testcases {
2873
2893
t .Run (tc .name , func (t * testing.T ) {
2874
- sec , err := GetSecretOrConfigMap (ctx , tc .args .k8sClient , true , tc .args .TerraformCredentialsSecretReference , neededKeys , errMsg , keyErrMsg )
2894
+ sec , err := GetSecretOrConfigMap (ctx , tc .args .k8sClient , true , tc .args .TerraformCredentialsSecretReference , neededKeys , errKey )
2875
2895
2876
2896
if err != nil {
2877
2897
assert .EqualError (t , err , tc .want .errMsg )
@@ -2937,11 +2957,11 @@ func TestCheckTerraformRCConfigMapReference(t *testing.T) {
2937
2957
k8sClient : k8sClient ,
2938
2958
TerraformRCConfigMapReference : & corev1.SecretReference {
2939
2959
Namespace : "default" ,
2940
- Name : "terraform-registry " ,
2960
+ Name : "configmap-not-exists " ,
2941
2961
},
2942
2962
},
2943
2963
want : want {
2944
- errMsg : "Failed to get the terraform registry config configmap: configmaps \" terraform-registry \" not found" ,
2964
+ errMsg : "Failed to get terraformrc configuration configmap: configmaps \" configmap-not-exists \" not found" ,
2945
2965
},
2946
2966
},
2947
2967
{
@@ -2954,7 +2974,7 @@ func TestCheckTerraformRCConfigMapReference(t *testing.T) {
2954
2974
},
2955
2975
},
2956
2976
want : want {
2957
- errMsg : fmt .Sprintf ("'%s' not in terraform registry configuration configmap" , TerraformRegistryConfig ),
2977
+ errMsg : fmt .Sprintf ("'%s' not in terraformrc configuration configmap" , TerraformRegistryConfig ),
2958
2978
},
2959
2979
},
2960
2980
{
@@ -2973,12 +2993,11 @@ func TestCheckTerraformRCConfigMapReference(t *testing.T) {
2973
2993
}
2974
2994
2975
2995
neededKeys := []string {TerraformRegistryConfig }
2976
- errMsg := "Failed to get the terraform registry config configmap"
2977
- keyErrMsg := "not in terraform registry configuration configmap"
2996
+ errKey := "terraformrc configuration"
2978
2997
2979
2998
for _ , tc := range testcases {
2980
2999
t .Run (tc .name , func (t * testing.T ) {
2981
- configMap , err := GetSecretOrConfigMap (ctx , tc .args .k8sClient , false , tc .args .TerraformRCConfigMapReference , neededKeys , errMsg , keyErrMsg )
3000
+ configMap , err := GetSecretOrConfigMap (ctx , tc .args .k8sClient , false , tc .args .TerraformRCConfigMapReference , neededKeys , errKey )
2982
3001
2983
3002
if err != nil {
2984
3003
assert .EqualError (t , err , tc .want .errMsg )
@@ -3034,7 +3053,7 @@ func TestTerraformCredentialsHelperConfigMap(t *testing.T) {
3034
3053
},
3035
3054
},
3036
3055
want : want {
3037
- errMsg : "Failed to get the terraform credentials helper configmap: configmaps \" terraform-registry\" not found" ,
3056
+ errMsg : "Failed to get terraform credentials helper configmap: configmaps \" terraform-registry\" not found" ,
3038
3057
},
3039
3058
},
3040
3059
{
@@ -3053,12 +3072,11 @@ func TestTerraformCredentialsHelperConfigMap(t *testing.T) {
3053
3072
}
3054
3073
3055
3074
neededKeys := []string {}
3056
- errMsg := "Failed to get the terraform credentials helper configmap"
3057
- keyErrMsg := ""
3075
+ errKey := "terraform credentials helper"
3058
3076
3059
3077
for _ , tc := range testcases {
3060
3078
t .Run (tc .name , func (t * testing.T ) {
3061
- configMap , err := GetSecretOrConfigMap (ctx , tc .args .k8sClient , false , tc .args .TerraformCredentialsHelperConfigMapReference , neededKeys , errMsg , keyErrMsg )
3079
+ configMap , err := GetSecretOrConfigMap (ctx , tc .args .k8sClient , false , tc .args .TerraformCredentialsHelperConfigMapReference , neededKeys , errKey )
3062
3080
3063
3081
if err != nil {
3064
3082
assert .EqualError (t , err , tc .want .errMsg )
@@ -3214,7 +3232,7 @@ func TestCheckValidateSecretAndConfigMap(t *testing.T) {
3214
3232
},
3215
3233
},
3216
3234
want : want {
3217
- errMsg : "Failed to get the terraform credentials helper configmap: configmaps \" terraform-registry\" not found" ,
3235
+ errMsg : "Failed to get terraform credentials helper configmap: configmaps \" terraform-registry\" not found" ,
3218
3236
},
3219
3237
},
3220
3238
{
@@ -3248,7 +3266,7 @@ func TestCheckValidateSecretAndConfigMap(t *testing.T) {
3248
3266
},
3249
3267
},
3250
3268
want : want {
3251
- errMsg : "Failed to get the terraform registry config configmap: configmaps \" terraform-registry\" not found" ,
3269
+ errMsg : "Failed to get terraformrc configuration configmap: configmaps \" terraform-registry\" not found" ,
3252
3270
},
3253
3271
},
3254
3272
}
0 commit comments