Skip to content
Snippets Groups Projects

main: Mock file system and add getFile tests

Closed Imported Administrator requested to merge feature/test-get-file into master
1 unresolved thread

This uses afero to proxy all file system accesses and then injects an in-memory file system in order to test the getFile function.

I'm not very familiar with Go so there might be a better way to do this. Afero turned up in my Google search for "mock file system in go". It is (mostly) compatible with the system package interfaces which made it relatively easy to replace the various calls.

This could also be used to write unit tests against other parts of the program but I limited it to getFile for now as POC.

Merge request reports

Closed by AdministratorAdministrator 6 months ago (Oct 6, 2024 8:10pm UTC)

Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
19 19 "strings"
20 20 "time"
21 21
22 "github.com/spf13/afero"
23
22 24 "gitlab.com/postmarketOS/postmarketos-mkinitfs/pkgs/archive"
23 25 "gitlab.com/postmarketOS/postmarketos-mkinitfs/pkgs/deviceinfo"
24 26 "gitlab.com/postmarketOS/postmarketos-mkinitfs/pkgs/misc"
25 27 )
26 28
29 var appFs afero.Fs
30
31 func initFs(fs afero.Fs) {
  • Author Owner

    This was the only way I could make the appFs variable writable from main_test.go. Not sure if I've been doing something wrong but for some reason the test code cannot write to the package-global variable directly.

    By Johannes Marbach on 2021-12-30T13:36:33

  • Author Owner

    it probably needs to be exported (capitalized, in Go)

    By clayton craft on 2022-01-07T19:44:14

  • Please register or sign in to reply
  • Administrator added 1 commit · Imported

    added 1 commit

    • 91529b73 - main: Mock file system and add getFile tests

    Compare with previous version

    By Johannes Marbach on 2021-12-30T13:40:56

  • Administrator changed milestone to %v2.0 · Imported

    changed milestone to %v2.0

  • Administrator removed milestone %v2.0 · Imported

    removed milestone %v2.0

  • Administrator mentioned in issue #40 · Imported

    mentioned in issue #40

    By clayton craft on 2024-03-11T17:21:58

  • added status::mr-stale label

  • Author Owner

    Sorry to bother you @cherrypicker,

    but we've detected that this merge request hasn't seen any recent activity. If you need help or want to discuss your approach with developers you can ping @postmarketOS. You can also ask on matrix in #devel:postmarketos.org or #postmarketos-devel on OFTC. If no further activity occurs in this MR, postmarketOS developers may close it in the future.

    Thanks for your contribution.

    By * postmarketOS Bot on 2024-06-17T16:44:52

  • Please register or sign in to reply
    Loading