github.com/golang/review@v0.0.0-20190122205339-266ee1edf5c3/git-codereview/config_test.go (about)

     1  // Copyright 2015 The Go Authors.  All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package main
     6  
     7  import (
     8  	"reflect"
     9  	"testing"
    10  )
    11  
    12  func TestParseConfig(t *testing.T) {
    13  	cases := []struct {
    14  		raw     string
    15  		want    map[string]string
    16  		wanterr bool
    17  	}{
    18  		{raw: "", want: map[string]string{}},
    19  		{raw: "issuerepo: golang/go", want: map[string]string{"issuerepo": "golang/go"}},
    20  		{raw: "# comment", want: map[string]string{}},
    21  		{raw: "# comment\n  k  :   v   \n# comment 2\n\n k2:v2\n", want: map[string]string{"k": "v", "k2": "v2"}},
    22  	}
    23  
    24  	for _, tt := range cases {
    25  		cfg, err := parseConfig(tt.raw)
    26  		if err != nil != tt.wanterr {
    27  			t.Errorf("parse(%q) error: %v", tt.raw, err)
    28  			continue
    29  		}
    30  		if !reflect.DeepEqual(cfg, tt.want) {
    31  			t.Errorf("parse(%q)=%v want %v", tt.raw, cfg, tt.want)
    32  		}
    33  	}
    34  }