Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create tests for core/formatter.go #121

Open
dominikbraun opened this issue Jun 12, 2021 · 10 comments
Open

Create tests for core/formatter.go #121

dominikbraun opened this issue Jun 12, 2021 · 10 comments

Comments

@dominikbraun
Copy link
Owner

There should be Table Driven Tests for core/formatter.go. They should be structured similar to the tests in core/timetrace_test.go.

@dominikbraun
Copy link
Owner Author

Note: Some tests for Formatter already are in core/timetrace_test.go and should be moved.

@KonstantinGasser
Copy link
Contributor

I started with writing some test cases for formatter.go and moved the one test case in timetrace_test.go to formatter_test.go. Now I am wondering if we should provide a mock-up for the FileSystem in order to actually test the timetrace.go - is there a convenient way to mock this FileSystem, do you have some experience with mockups you can share with me?

@dominikbraun
Copy link
Owner Author

Absolutely: I planned to migrate to afero for accessing the filesystem but didn't have the time yet. First, add a field of the type afero.Fs to the fs.Fs type and extend the New function appropriately. Then replace all calls to os with calls to that afero.Fs. Finally, pass afero.NewOsFs() to fs.New in the main program and afero.NewMemMapFs() in the tests.

@KonstantinGasser
Copy link
Contributor

That's a pretty cool library, thanks for the tip! I will work on that today/tomorrow.

@KonstantinGasser
Copy link
Contributor

KonstantinGasser commented Jun 21, 2021

I think I will provide the implementation of the afero fs in a separate PR - might be better to separate these changes from the tests

EDIT: thought the changes would be more - change to afero fs will be included with this PR

@KonstantinGasser
Copy link
Contributor

KonstantinGasser commented Jun 23, 2021

I have found a couple of places in record.go, project.go and timetrace.go where we also rely on the os or ioutil module. For the sake of segregation I will append the timetrace.Filesystem interface so all communication with the Filesystem will be done via this interface.

@KonstantinGasser
Copy link
Contributor

Hi @dominikbraun, sorry for taking so long, had a lot of things going on in university.. I just came back to this issue and writing tests for the fs. One problem I see is that we are using the os, ioutil package in quite some places (project.go, record.go and timetrace.go) causing me quite some headache. IMO to test the fs it would be good to clearly separate the project, record and timetrace logic from the underlying FS.
For example instead of directly writing a new project to file in the project.SaveProject function the Fs interface should provide such logic. Maybe you have a different idea to approach this, I however, feel that testing it how it is now might introduce more bugs since afero would need to be used in many layers of the code.

What I can image is to clearly define an interface to interact with the Fs and swap the fs logic in the project,recods and timetrace file to use this interface. Do you have any thoughts about this and can assist me?

@dominikbraun
Copy link
Owner Author

Hi @KonstantinGasser, yes, a stronger separation between the filesystem access and the business logic probably would make sense. On this occasion, we could also separate the Filesystem interface in more concrete interfaces: ProjectFilesystem, RecordFilesystem and so on. I think that doing so will make it easier to test the individual components.

@KonstantinGasser
Copy link
Contributor

Ok I will test out some implementations for that. I probably will also need to change the dependency injection then.
Since there will be a couple changes, I will create an incremental PR so it can be reviewed step by step.

@dominikbraun
Copy link
Owner Author

Yes, a rolling review would be nice here - and this probably will also affect some open PRs, hopefully the merge conflicts won't be too severe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants