techygrrrl / timerrr

⏳ A CLI-based timer app with a TUI written in Go
https://blog.techygrrrl.stream/cross-platform-tui-cli-go-lang
MIT License
8 stars 2 forks source link

tests assume the user is runner #7

Closed wissam closed 1 year ago

wissam commented 1 year ago

When you run tests , the user/home dirs are hardcoded as "runner"


    os_utils_linux_test.go:19: 🧵 Config dir: /home/wissam/.config
    os_utils_linux_test.go:22: 
                Error Trace:    /home/wissam/code/oss/timerrr/utils/os_utils_linux_test.go:22
                Error:          Not equal: 
                                expected: "/home/runner/.config"
                                actual  : "/home/wissam/.config"

                                Diff:
                                --- Expected
                                +++ Actual
                                @@ -1 +1 @@
                                -/home/runner/.config
                                +/home/wissam/.config
                Test:           TestUserConfigDirLinux
--- FAIL: TestUserConfigDirLinux (0.00s)```
techygrrrl commented 1 year ago

I'm not sure what the best workaround for this is without putting the exact same logic in the tests that the tests are supposed to be testing as that would make the tests useless. I'm open to suggestions if you have any.

My priority is that these pass on CI using the OS matrix strategy available on Github Actions, which is why I've hardcoded it to runner. This is similarly done on macOS and Windows.

For now as a workaround, you can do a find and replace locally for all _linux test files and change the tests locally to say wissam instead of runner and not commit the name change. As of now, these should be limited to the utils package. That should unblock you for now so you can contribute your changes upstream. You can use a Git tool like the TUI tig (this is what I use) or the GUI SourceTree or another Git tool that allows you to stage line-by-line to stage selective pieces of code, omitting these username changes. This will allow you to make the necessary changes locally so that you can see your tests pass but allow you to commit your new tests without committing the username changes. This is what I do locally when testing, as my name is also not runner. 😅

Arguably only the method ConfigFilePath() needs to be tested since the other test only calls os.UserConfigDir() and that doesn't need to be tested since it's standard library. The goal of the tests is to ensure we are writing to timerrr/timers.json in the user config directory for each operating system.

What do other Go projects do in cases like this? Do they leave this untested? Do they write to a path outside of the user's home directory instead?

wissam commented 1 year ago

Thanks! I will check both tig and sourcetree !

techygrrrl commented 1 year ago

Closed by https://github.com/techygrrrl/timerrr/pull/11 https://github.com/techygrrrl/timerrr/pull/14