Skip to content

Commit

Permalink
fix(injector: join): missing struct members to fingerprint
Browse files Browse the repository at this point in the history
Signed-off-by: Eliott Bouhana <[email protected]>
  • Loading branch information
eliottness committed Nov 18, 2024
1 parent edbd6cd commit 5fb209e
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion internal/fingerprint/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type (
}
)

func Map[K comparable, V any, H Hashable](m map[K]V, fn func(K, V) (string, H)) Hashable {
func Map[K comparable, V any, H Hashable](m map[K]V, fn func(K, V) (string, H)) mapped[H] {
res := make(mapped[H], 0, len(m))

for key, val := range m {
Expand Down
1 change: 1 addition & 0 deletions internal/injector/aspect/advice/code/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ func (t *Template) Hash(h *fingerprint.Hasher) error {
"template",
fingerprint.Map(t.Imports, func(k string, v string) (string, fingerprint.String) { return k, fingerprint.String(v) }),

Check warning on line 227 in internal/injector/aspect/advice/code/template.go

View check run for this annotation

Codecov / codecov/patch

internal/injector/aspect/advice/code/template.go#L224-L227

Added lines #L224 - L227 were not covered by tests
fingerprint.String(t.Source),
t.Lang,
)
}

Expand Down
7 changes: 7 additions & 0 deletions internal/injector/aspect/context/golang.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"go/version"

"github.com/DataDog/orchestrion/internal/fingerprint"
"gopkg.in/yaml.v3"
)

Expand Down Expand Up @@ -53,6 +54,12 @@ func Compare(left GoLangVersion, right GoLangVersion) int {
return version.Compare(version.Lang(left.label), version.Lang(right.label))
}

var _ fingerprint.Hashable = (*GoLangVersion)(nil)

func (g GoLangVersion) Hash(h *fingerprint.Hasher) error {
return h.Named("GoLangVersion", fingerprint.String(g.label))

Check warning on line 60 in internal/injector/aspect/context/golang.go

View check run for this annotation

Codecov / codecov/patch

internal/injector/aspect/context/golang.go#L59-L60

Added lines #L59 - L60 were not covered by tests
}

var _ yaml.Unmarshaler = (*GoLangVersion)(nil)

func (g *GoLangVersion) UnmarshalYAML(node *yaml.Node) error {
Expand Down
7 changes: 1 addition & 6 deletions internal/injector/aspect/join/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package join

import (
"bytes"
"errors"
"fmt"
"regexp"

Expand Down Expand Up @@ -155,9 +154,5 @@ func (n TypeName) AsCode() jen.Code {
}

func (n TypeName) Hash(h *fingerprint.Hasher) error {
return errors.Join(
h.Named("path", fingerprint.String(n.path)),
h.Named("name", fingerprint.String(n.name)),
h.Named("pointer", fingerprint.Bool(n.pointer)),
)
return h.Named("type-name", fingerprint.String(n.name), fingerprint.String(n.path), fingerprint.Bool(n.pointer))

Check warning on line 157 in internal/injector/aspect/join/join.go

View check run for this annotation

Codecov / codecov/patch

internal/injector/aspect/join/join.go#L156-L157

Added lines #L156 - L157 were not covered by tests
}
6 changes: 5 additions & 1 deletion internal/injector/aspect/join/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (s *structLiteral) AsCode() jen.Code {
}

func (s *structLiteral) Hash(h *fingerprint.Hasher) error {
return h.Named("struct-literal", s.TypeName, fingerprint.String(s.Field), fingerprint.Int(s.Match))
return h.Named("struct-literal", s.TypeName, fingerprint.String(s.Field), s.Match)

Check warning on line 167 in internal/injector/aspect/join/struct.go

View check run for this annotation

Codecov / codecov/patch

internal/injector/aspect/join/struct.go#L166-L167

Added lines #L166 - L167 were not covered by tests
}

func init() {
Expand Down Expand Up @@ -259,3 +259,7 @@ func (s StructLiteralMatch) asCode() jen.Code {
}
return jen.Qual(pkgPath, constName)
}

func (s StructLiteralMatch) Hash(h *fingerprint.Hasher) error {
return h.Named("struct-literal-match", fingerprint.Int(s))

Check warning on line 264 in internal/injector/aspect/join/struct.go

View check run for this annotation

Codecov / codecov/patch

internal/injector/aspect/join/struct.go#L263-L264

Added lines #L263 - L264 were not covered by tests
}

0 comments on commit 5fb209e

Please sign in to comment.