Created
August 15, 2021 17:10
-
-
Save kben19/c667dfe24c7235ab460e622c7254a0de to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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