(t *testing.T)
| 27 | ) |
| 28 | |
| 29 | func TestTargetParser(t *testing.T) { |
| 30 | defaultFormat := "default" |
| 31 | defaultPath := "default.out" |
| 32 | defaultOptions := Options{ |
| 33 | ShowSuccesses: false, |
| 34 | ShowWarnings: true, |
| 35 | } |
| 36 | |
| 37 | cases := []struct { |
| 38 | name string |
| 39 | expectedFormat string |
| 40 | expectedPath string |
| 41 | expectedOptions Options |
| 42 | targetName string |
| 43 | }{ |
| 44 | {name: "all defaults", expectedFormat: defaultFormat, expectedOptions: defaultOptions}, |
| 45 | {name: "format", expectedFormat: "spam", expectedOptions: defaultOptions, targetName: "spam"}, |
| 46 | {name: "format no file", expectedFormat: "spam", expectedOptions: defaultOptions, targetName: "spam="}, |
| 47 | {name: "format and file", expectedFormat: "spam", expectedOptions: defaultOptions, targetName: "spam=spam.out", expectedPath: "spam.out"}, |
| 48 | {name: "format and option", expectedFormat: "spam", expectedOptions: Options{ShowSuccesses: true, ShowWarnings: true}, targetName: "spam?show-successes=true"}, |
| 49 | {name: "format no file with option", expectedFormat: "spam", expectedOptions: Options{ShowSuccesses: true, ShowWarnings: true}, targetName: "spam=?show-successes=true"}, |
| 50 | {name: "format with file and option", expectedFormat: "spam", expectedOptions: Options{ShowSuccesses: true, ShowWarnings: true}, targetName: "spam=spam.out?show-successes=true", expectedPath: "spam.out"}, |
| 51 | {name: "format with show-warnings option", expectedFormat: "spam", expectedOptions: Options{ShowSuccesses: false, ShowWarnings: false}, targetName: "spam?show-warnings=false"}, |
| 52 | {name: "format with both options", expectedFormat: "spam", expectedOptions: Options{ShowSuccesses: true, ShowWarnings: false}, targetName: "spam?show-successes=true&show-warnings=false"}, |
| 53 | {name: "format with both options reversed", expectedFormat: "spam", expectedOptions: Options{ShowSuccesses: false, ShowWarnings: true}, targetName: "spam?show-warnings=true&show-successes=false"}, |
| 54 | } |
| 55 | |
| 56 | for _, c := range cases { |
| 57 | t.Run(c.name, func(t *testing.T) { |
| 58 | fs := afero.NewMemMapFs() |
| 59 | defaultWriter := fileWriter{path: defaultPath, fs: fs} |
| 60 | parser := NewTargetParser(defaultFormat, defaultOptions, defaultWriter, fs) |
| 61 | target, err := parser.Parse(c.targetName) |
| 62 | require.NoError(t, err) |
| 63 | |
| 64 | assert.Equal(t, c.expectedFormat, target.Format) |
| 65 | if c.expectedPath == "" { |
| 66 | assert.Equal(t, defaultWriter, target.writer) |
| 67 | } else { |
| 68 | assert.Equal(t, c.expectedPath, target.writer.(*fileWriter).path) |
| 69 | } |
| 70 | |
| 71 | assert.Equal(t, c.expectedOptions, target.Options) |
| 72 | }) |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | func TestSimpleFileWriter(t *testing.T) { |
| 77 | fs := afero.NewMemMapFs() |
nothing calls this directly
no test coverage detected