@@ -24,6 +24,7 @@ import (
2424 "testing"
2525 "time"
2626
27+ "github.com/go-logr/logr/funcr"
2728 "go.uber.org/goleak"
2829)
2930
@@ -248,6 +249,53 @@ func TestParseGitConfigs(t *testing.T) {
248249 }
249250}
250251
252+ func TestParseGitConfigList (t * testing.T ) {
253+ cases := []struct {
254+ name string
255+ input string
256+ expect funcr.PseudoStruct
257+ }{{
258+ name : "empty" ,
259+ input : "" ,
260+ expect : funcr.PseudoStruct {},
261+ }, {
262+ name : "one-pair" ,
263+ input : "k\n v\x00 " ,
264+ expect : funcr.PseudoStruct {"k" , "v" },
265+ }, {
266+ name : "no-trailing-nul" ,
267+ input : "k\n v" ,
268+ expect : funcr.PseudoStruct {"k" , "v" },
269+ }, {
270+ name : "empty-value" ,
271+ input : "k\n \x00 " ,
272+ expect : funcr.PseudoStruct {"k" , "" },
273+ }, {
274+ name : "multi-line-value" ,
275+ input : "k\n line1\n line2\x00 " ,
276+ expect : funcr.PseudoStruct {"k" , "line1\n line2" },
277+ }, {
278+ // `git config list -z` prints a key with no value (e.g. a bare `key`
279+ // line, which git treats as boolean true) without a newline.
280+ name : "no-value" ,
281+ input : "k\x00 " ,
282+ expect : funcr.PseudoStruct {"k" , nil },
283+ }, {
284+ name : "multiple" ,
285+ input : "core.bare\n false\x00 demo.bare\x00 demo.empty\n \x00 demo.multi\n line1\n line2\x00 " ,
286+ expect : funcr.PseudoStruct {"core.bare" , "false" , "demo.bare" , nil , "demo.empty" , "" , "demo.multi" , "line1\n line2" },
287+ }}
288+
289+ for _ , tc := range cases {
290+ t .Run (tc .name , func (t * testing.T ) {
291+ kvs := parseGitConfigList (tc .input )
292+ if ! reflect .DeepEqual (kvs , tc .expect ) {
293+ t .Errorf ("bad result:\n \t expected: %#v\n \t got: %#v" , tc .expect , kvs )
294+ }
295+ })
296+ }
297+ }
298+
251299func TestDirIsEmpty (t * testing.T ) {
252300 root := absPath (t .TempDir ())
253301
0 commit comments