Skip to content

Commit

Permalink
fix: Only extract labels from anonymous structs
Browse files Browse the repository at this point in the history
  • Loading branch information
rlch committed Jul 18, 2024
1 parent 655fd41 commit 64d5f87
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 0 additions & 2 deletions internal/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ func extractNeo4JName(instance any, fields ...string) ([]string, error) {
f := v.Field(i)
if f.Anonymous && f.Type.Kind() == reflect.Struct {
queue = append(queue, f.Type)
}
if f.Type.Kind() == reflect.Struct {
extractTagFromMatch(&f)
}
}
Expand Down
9 changes: 9 additions & 0 deletions internal/tags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ type personWithNonStructLabels struct {
Name string `neo4j:"Name"`
}

type personWithAnonymousStructLabels struct {
swedishPerson
S swedishPerson `neo4j:"Concrete"`
}

func TestExtractNodeLabel(t *testing.T) {
t.Run("nil when node nil", func(t *testing.T) {
assert.Nil(t, ExtractNodeLabels(nil))
Expand All @@ -61,6 +66,10 @@ func TestExtractNodeLabel(t *testing.T) {
assert.Equal(t, []string{"Person", "Swedish"}, ExtractNodeLabels(personWithNonStructLabels{}))
})

t.Run("only extract the labels from anonymous structs", func(t *testing.T) {
assert.Equal(t, []string{"Person", "Swedish"}, ExtractNodeLabels(personWithAnonymousStructLabels{}))
})

t.Run("extracts from abstract types", func(t *testing.T) {
var o organism = &baseOrganism{}
assert.Equal(t, []string{"Organism"}, ExtractNodeLabels(o))
Expand Down

0 comments on commit 64d5f87

Please sign in to comment.