@@ -53,3 +53,64 @@ func Test_filterShortFlags(t *testing.T) {
5353 })
5454 }
5555}
56+
57+ func Test_addFlagKeys (t * testing.T ) {
58+ // Note: these specs assume minFlagKeyLen is 3
59+ tests := []struct {
60+ name string
61+ flagKeys map [string ][]string
62+ flags []string
63+ projKey string
64+ want map [string ][]string
65+ }{
66+ {
67+ name : "With a project that contains no flags" ,
68+ flags : []string {},
69+ projKey : "test_project_1" ,
70+ flagKeys : map [string ][]string {},
71+ want : map [string ][]string {},
72+ },
73+ {
74+ name : "With a project that contains no flags and already existing keys" ,
75+ flags : []string {},
76+ projKey : "test_project_1" ,
77+ flagKeys : map [string ][]string {"test_project_2" : {"test_key" }},
78+ want : map [string ][]string {"test_project_2" : {"test_key" }},
79+ },
80+ {
81+ name : "With a project that contains a flag and already existing keys" ,
82+ flags : []string {"test_project_key" },
83+ projKey : "test_project_1" ,
84+ flagKeys : map [string ][]string {"test_project_2" : {"test_key" }},
85+ want : map [string ][]string {"test_project_2" : {"test_key" }, "test_project_1" : {"test_project_key" }},
86+ },
87+ {
88+ name : "With a project that contains multiple flags and already existing keys" ,
89+ flags : []string {"test_project_key" , "test_project_key_2" },
90+ projKey : "test_project_1" ,
91+ flagKeys : map [string ][]string {"test_project_2" : {"test_key" }},
92+ want : map [string ][]string {"test_project_2" : {"test_key" }, "test_project_1" : {"test_project_key" , "test_project_key_2" }},
93+ },
94+ {
95+ name : "With a project that contains a short and log flags" ,
96+ flags : []string {"test_project_key" , "t" },
97+ projKey : "test_project_1" ,
98+ flagKeys : map [string ][]string {"test_project_2" : {"test_key" }},
99+ want : map [string ][]string {"test_project_2" : {"test_key" }, "test_project_1" : {"test_project_key" }},
100+ },
101+ {
102+ name : "With a project that contains a short flag" ,
103+ flags : []string {"k" },
104+ projKey : "test_project_1" ,
105+ flagKeys : map [string ][]string {"test_project_2" : {"test_key" }},
106+ want : map [string ][]string {"test_project_2" : {"test_key" }},
107+ },
108+ }
109+
110+ for _ , tt := range tests {
111+ t .Run (tt .name , func (t * testing.T ) {
112+ addFlagKeys (tt .flagKeys , tt .flags , tt .projKey )
113+ require .Equal (t , tt .want , tt .flagKeys )
114+ })
115+ }
116+ }
0 commit comments