What could not kill you would make you stronger. I survived the week…

Tony Vu
3 min readNov 27, 2020

--

Writing this blog would have been my easiest thing to do this week. It has been a busy week for me with deadlines. Fortunately, I have completed all required tasks and still have time on Friday to do more. Let’s go straight to what this week is about for Open Source Development.

In last week and this week, we were tasked to add unit testing and continuous integration to our link checker project. I have had quite a few testing experiences in the past, so I felt pretty calm going into this. The only problem is I need to do some digging to learn about unit testing with Golang.

I used the built-in testing GO package, a package used for testing GO project. It is an easy to use package and I have not had any problem implementing my tests. My first attempt went smoothly when I was trying to implement unit testing for one of my parser functions. Go has never failed to impress me in term of how intuitive it is as a coding language. Even though testing package does not offer some feature that Jest has but it is enough to complete the task. An example can be found below.

My second set of tests was a bit more challenging as it involved HTTP request. I needed to test whether my CheckLink function works correctly with status code 200 and 404. Like any other testing framework, when we want to test something involving HTTP request calls, we would simulate the calls to a mock server and I did just that for my tests. Initially it was challenging because of how my CheckLink was written, but I finally found a solution by creating a mock server. You can take a look at the example code belows.

I even created a function to custom make the mock server, so I can simulate any status code (i.e: 200 or 404).

The next task was to include a Github Actions CI to Github so when someone pushes or creates a pull request, it will automatically run to check if the new code passes the tests and if the program is successfully built . This tasks was very straight forward as Github provides basic standard workflow that you can use for each language. Also, I have added the optional linter to the workflow to make it even better.

The last part of the assignment was to add tests into another student’s repo. I decided to work with Phil’s repo again after a while since release 0.1. I have added tests for his RemoveDuplicate function. I hope he is happy with it.

And that was the end of lab 8 (+ 9) to close up a tiring but effective week of mine. Now I will rest up and be ready for more tasks starting Friday. I still need to contribute something for release 0.4. Hopefully, I will come up with something good! That’s it from me and thank you for reading up!

Tony Vu.

--

--

No responses yet