Skip to content

Go R1 Day 55

progress🔗

In Go, when you call a function or a method the arguments are copied. 1

  • Built some test cases for working with pointers and test methods.
  • Did this in Goland to become more familar with it and figured out how to use the nice tests explorer with a floating window to auto-test.
  • Built a filewatcher configuration watcher as alternative to tests panel, allowing automated run in terminal or output panel of go test ./....
  • Couldn't figure out how to run every test in project, as it's a multi-module repo (for tutorials). VSCode works fine with this with the multi-module support.

These pointers to structs even have their own name: struct pointers and they are automatically dereferenced. 1

This explains something that felt a little confusing as a new Gopher. Now I know why returning a value back as an int didn't require explicit dereferencing. 2

func (w *Wallet) Balance() int {
  return w.balance // <---- automatically deferenced
}

Not clear yet on if I need to set the is := New(t) in the context of each t.Run() or not.

t.Run("withdraw 2 amounts", func(t *testing.T) {
        wallet := pointers.Wallet{}
        wallet.Deposit(pointers.Bitcoin(20))
        err := wallet.Withdraw(pointers.Bitcoin(5))
        is.NoErr(err) // Withdraw should have no errors
        assertBalance(t, &wallet, pointers.Bitcoin(15))
    })