People: Throw correct error in ReportCollision when embedding is empty #22

This commit is contained in:
theresa 2021-08-26 16:00:11 +02:00
parent 1761e139de
commit 29be2cca27
2 changed files with 11 additions and 1 deletions

View file

@ -148,7 +148,7 @@ func (m *Face) ReportCollision(embeddings Embeddings) (reported bool, err error)
if m.SubjectUID == "" {
// Ignore reports for anonymous faces.
return false, nil
} else if m.ID == "" || len(m.EmbeddingJSON) == 0 {
} else if m.ID == "" {
return false, fmt.Errorf("invalid face id")
} else if len(m.EmbeddingJSON) == 0 {
return false, fmt.Errorf("embedding must not be empty")

View file

@ -102,6 +102,16 @@ func TestFace_ReportCollision(t *testing.T) {
assert.Equal(t, "invalid face id", err.Error())
}
})
t.Run("embedding empty", func(t *testing.T) {
m := NewFace("123", SrcAuto, Embeddings{})
m.EmbeddingJSON = []byte("")
if reported, err := m.ReportCollision(MarkerFixtures.Pointer("1000003-4").Embeddings()); err == nil {
t.Fatal(err)
} else {
assert.False(t, reported)
assert.Equal(t, "embedding must not be empty", err.Error())
}
})
}
func TestFace_ReviseMatches(t *testing.T) {