This week, I ported three more jobs of the C++ to Go migration: the confirmation email with each participant’s registration slip, the note that records it on their order, and the CSV exports. I also pushed my work for the first time and built a practice setup, so I can show my supervisor, Dr. Shawn, that Go and C++ give the same results on real test data.

Sending the Confirmation Email

Dr. Shawn’s Go version already had doEntry, the function that turns each new entry into an email with a QR code and a slip PDF. When I compared it with the C++ code, I found three differences. The subject line showed the entry ID instead of the order number, the reply address recently added to the C++ email was missing, and the mail server details were written into the code instead of being read from each competition’s settings. I fixed all three. Most of the changes went into entryMessage, which builds the email and decides who receives it.

Writing Back to the Order

After the email, the C++ version writes a private note on the WooCommerce order. The note says “Email:” with the email’s ID if it was sent, or the error if it failed, so the order shows whether the email went out. I ported this as sendOrderNote, which adds the note through WooCommerce’s REST API. I tested it with Go’s httptest package, which runs a small fake shop inside the test, and the tests proved that each note reaches the right order and that the shop’s secret key never shows up in an error message.

Fixing the Exports

The exports let staff download a CSV file of a competition’s entries. When I compared the Go export code with the C++ version, one difference stood out. Every entry ID starts with a short code made from the competition’s SKU, but Go dropped the code’s leading zero, so a competition whose code starts with zero would get an empty export. I fixed it to keep the zero, and a new test confirms that the export now finds that competition’s entries.

Then I ported crs_export, a C++ command-line tool for the same export, as an -export option of the main Go program. In Go, a second program can’t reuse the main program’s code, so both ways of exporting now share one copy of the code. By Thursday, all 32 tests passed.

Getting Ready for a Real Test

Before pushing my work, I rebased my nine commits onto Dr. Shawn’s updated Go branch, which means moving them on top of his newest commits, and all the tests still passed.

Last week’s plan was to open my first pull request, but I held it back. Unit tests run on a fake database, so they can’t prove the whole flow behaves like C++. Now every pull request gets a practice run first, with the Go result next to the C++ result. Using Docker, I set up a local CouchDB, a container with wkhtmltopdf, and Mailpit, a mail catcher that keeps every email on my laptop, so no test email can reach a real person. Then I copied the test site’s database into it, and the Go service connected to it and stopped cleanly.

Next Week’s Plan

Next week, I will finish the practice run and open my first pull request with the results. Then I will port bulk orders, where one order carries a spreadsheet of many participants.

Categories: Experiential

0 Comments

Leave a Reply

Avatar placeholder

This site uses Akismet to reduce spam. Learn how your comment data is processed.