I'm working on unit tests on a Go project, and I'm new to Go. So to start I wanted to test something easy. And I started with this function:
func (this *Service) InList(idPerson string, personsId []string) bool {
for _, personsId := range personsId {
if id == idPerson {
return true
}
}
return false
}
Service is a struct defined on top of the class.
This is the test I wrote:
func TestValidatePersonID(t *testing.T) {
personID := "12345"
personIDs := []string{"12345", "123456t", "1234567a"}
ok := *Service.InList(personID, personIDs)
if !ok {
t.Errorf("Id %v not found", personID)
}
}
If i try to Call Service without * I get the error:
invalid method expresion (needs pointer reciever)
If i try to call the function (*Service).inList, it says I'm missing an argument. I'm new to Go if anyone could point to me what I'm doing wrong and how Could I get a pointer receiver of that Service in my test?. I would appreciatte it.