@@ -17,6 +17,7 @@ limitations under the License.
1717package controllers
1818
1919import (
20+ "reflect"
2021 "testing"
2122 "time"
2223
@@ -254,6 +255,11 @@ func TestGetDesiredClusterState(t *testing.T) {
254255 MountPath : "/etc/gcp_service_account/" ,
255256 },
256257 },
258+ LogConfig : map [string ]string {
259+ "extra-file.txt" : "hello!" ,
260+ "log4j-console.properties" : "foo" ,
261+ "logback-console.xml" : "bar" ,
262+ },
257263 },
258264 Status : v1beta1.FlinkClusterStatus {
259265 NextRevision : "flinkjobcluster-sample-85dc8f749-1" ,
@@ -888,8 +894,9 @@ taskmanager.rpc.port: 6122
888894 },
889895 Data : map [string ]string {
890896 "flink-conf.yaml" : flinkConfYaml ,
891- "log4j-console.properties" : getLogConf ()["log4j-console.properties" ],
892- "logback-console.xml" : getLogConf ()["logback-console.xml" ],
897+ "extra-file.txt" : "hello!" ,
898+ "log4j-console.properties" : "foo" ,
899+ "logback-console.xml" : "bar" ,
893900 "submit-job.sh" : submitJobScript ,
894901 },
895902 }
@@ -969,3 +976,73 @@ func TestCalFlinkHeapSize(t *testing.T) {
969976 flinkHeapSize = calFlinkHeapSize (cluster )
970977 assert .Assert (t , len (flinkHeapSize ) == 0 )
971978}
979+
980+ func Test_getLogConf (t * testing.T ) {
981+ type args struct {
982+ spec v1beta1.FlinkClusterSpec
983+ }
984+ tests := []struct {
985+ name string
986+ args args
987+ want map [string ]string
988+ }{
989+ {
990+ name : "nil map uses defaults" ,
991+ args : args {v1beta1.FlinkClusterSpec {LogConfig : nil }},
992+ want : map [string ]string {
993+ "log4j-console.properties" : DefaultLog4jConfig ,
994+ "logback-console.xml" : DefaultLogbackConfig ,
995+ },
996+ },
997+ {
998+ name : "map missing log4j-console.properties uses default" ,
999+ args : args {v1beta1.FlinkClusterSpec {LogConfig : map [string ]string {
1000+ "logback-console.xml" : "xyz" ,
1001+ }}},
1002+ want : map [string ]string {
1003+ "log4j-console.properties" : DefaultLog4jConfig ,
1004+ "logback-console.xml" : "xyz" ,
1005+ },
1006+ },
1007+ {
1008+ name : "map missing logback-console.xml uses default" ,
1009+ args : args {v1beta1.FlinkClusterSpec {LogConfig : map [string ]string {
1010+ "log4j-console.properties" : "xyz" ,
1011+ }}},
1012+ want : map [string ]string {
1013+ "log4j-console.properties" : "xyz" ,
1014+ "logback-console.xml" : DefaultLogbackConfig ,
1015+ },
1016+ },
1017+ {
1018+ name : "map with both keys overrides defaults" ,
1019+ args : args {v1beta1.FlinkClusterSpec {LogConfig : map [string ]string {
1020+ "log4j-console.properties" : "hello" ,
1021+ "logback-console.xml" : "world" ,
1022+ }}},
1023+ want : map [string ]string {
1024+ "log4j-console.properties" : "hello" ,
1025+ "logback-console.xml" : "world" ,
1026+ },
1027+ },
1028+ {
1029+ name : "extra keys preserved" ,
1030+ args : args {v1beta1.FlinkClusterSpec {LogConfig : map [string ]string {
1031+ "log4j-console.properties" : "abc" ,
1032+ "file.txt" : "def" ,
1033+ }}},
1034+ want : map [string ]string {
1035+ "log4j-console.properties" : "abc" ,
1036+ "logback-console.xml" : DefaultLogbackConfig ,
1037+ "file.txt" : "def" ,
1038+ },
1039+ },
1040+ }
1041+ for _ , tt := range tests {
1042+ t .Run (tt .name , func (t * testing.T ) {
1043+ if got := getLogConf (tt .args .spec ); ! reflect .DeepEqual (got , tt .want ) {
1044+ t .Errorf ("getLogConf() = %v, want %v" , got , tt .want )
1045+ }
1046+ })
1047+ }
1048+ }
0 commit comments