Skip to content

Instantly share code, notes, and snippets.

@kben19
Created August 15, 2021 17:10
Show Gist options
  • Save kben19/c667dfe24c7235ab460e622c7254a0de to your computer and use it in GitHub Desktop.
Save kben19/c667dfe24c7235ab460e622c7254a0de to your computer and use it in GitHub Desktop.
import "errors"
type WarehouseMock struct {}
func(warehouse *WarehouseMock) GetProduct(id int) (Product, error){
if id != 1 {
return Product{}, errors.New("test")
}
return Product{}, nil
}
func(warehouse *WarehouseMock) InsertProduct(product Product) error{
return nil
}
func TestRetail_GetMyProduct(t *testing.T) {
retail := New(&WarehouseMock{})
got, err := retail.GetMyProduct()
if err != nil {
t.Error("unit test failed, error expected nil")
}
empty := Product{}
if got != empty {
t.Error("unit test failed, product expected empty")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment