|
| 1 | +package codeowners_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "reflect" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/fmenezes/codeowners" |
| 8 | +) |
| 9 | + |
| 10 | +func TestParseLine(t *testing.T) { |
| 11 | + testCases := []struct { |
| 12 | + input string |
| 13 | + wantPattern string |
| 14 | + wantOwners []string |
| 15 | + }{ |
| 16 | + { |
| 17 | + input: "* test@example.org", |
| 18 | + wantPattern: "*", |
| 19 | + wantOwners: []string{"test@example.org"}, |
| 20 | + }, |
| 21 | + { |
| 22 | + input: "filepattern test@example.org @owner @company/team", |
| 23 | + wantPattern: "filepattern", |
| 24 | + wantOwners: []string{"test@example.org", "@owner", "@company/team"}, |
| 25 | + }, |
| 26 | + { |
| 27 | + input: "file\\ with\\ spaces @owner", |
| 28 | + wantPattern: "file\\ with\\ spaces", |
| 29 | + wantOwners: []string{"@owner"}, |
| 30 | + }, |
| 31 | + { |
| 32 | + input: " filepattern ", |
| 33 | + wantPattern: "filepattern", |
| 34 | + wantOwners: nil, |
| 35 | + }, |
| 36 | + { |
| 37 | + input: "filepattern @owner # comments", |
| 38 | + wantPattern: "filepattern", |
| 39 | + wantOwners: []string{"@owner"}, |
| 40 | + }, |
| 41 | + { |
| 42 | + input: "", |
| 43 | + wantPattern: "", |
| 44 | + wantOwners: nil, |
| 45 | + }, |
| 46 | + { |
| 47 | + input: "# only comments on the line", |
| 48 | + wantPattern: "", |
| 49 | + wantOwners: nil, |
| 50 | + }, |
| 51 | + } |
| 52 | + |
| 53 | + for _, testCase := range testCases { |
| 54 | + gotPattern, gotOwners := codeowners.ParseLine(testCase.input) |
| 55 | + if gotPattern != testCase.wantPattern || !reflect.DeepEqual(gotOwners, testCase.wantOwners) { |
| 56 | + t.Errorf("Input: %s, Want: %s, %v, Got: %s, %v", testCase.input, testCase.wantPattern, testCase.wantOwners, gotPattern, gotOwners) |
| 57 | + } |
| 58 | + } |
| 59 | +} |
0 commit comments