TestLoad asserts that sheets on valid cheatpaths can be loaded successfully
(t *testing.T)
| 10 | |
| 11 | // TestLoad asserts that sheets on valid cheatpaths can be loaded successfully |
| 12 | func TestLoad(t *testing.T) { |
| 13 | |
| 14 | // mock cheatpaths |
| 15 | cheatpaths := []cheatpath.Path{ |
| 16 | { |
| 17 | Name: "community", |
| 18 | Path: path.Join(mocks.Path("cheatsheets"), "community"), |
| 19 | ReadOnly: true, |
| 20 | }, |
| 21 | { |
| 22 | Name: "personal", |
| 23 | Path: path.Join(mocks.Path("cheatsheets"), "personal"), |
| 24 | ReadOnly: false, |
| 25 | }, |
| 26 | } |
| 27 | |
| 28 | // load cheatsheets |
| 29 | cheatpathSheets, err := Load(cheatpaths) |
| 30 | if err != nil { |
| 31 | t.Errorf("failed to load cheatsheets: %v", err) |
| 32 | } |
| 33 | |
| 34 | // assert that the correct number of sheets loaded |
| 35 | // (sheet load details are tested in `sheet_test.go`) |
| 36 | totalSheets := 0 |
| 37 | for _, sheets := range cheatpathSheets { |
| 38 | totalSheets += len(sheets) |
| 39 | } |
| 40 | |
| 41 | // we expect 4 total sheets (2 from community, 2 from personal) |
| 42 | // hidden files and files with extensions are excluded |
| 43 | want := 4 |
| 44 | if totalSheets != want { |
| 45 | t.Errorf( |
| 46 | "failed to load correct number of cheatsheets: want: %d, got: %d", |
| 47 | want, |
| 48 | totalSheets, |
| 49 | ) |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | // TestLoadBadPath asserts that an error is returned if a cheatpath is invalid |
| 54 | func TestLoadBadPath(t *testing.T) { |