Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitryax committed Apr 10, 2024
1 parent 2c70ca2 commit 622b83e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
13 changes: 12 additions & 1 deletion tests/testutils/telemetry/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,32 +120,39 @@ func attributesAreEqual(attrs, toCompare *map[string]any) bool {
return true
}
if toCompare == nil {
fmt.Println("DEBUG: Attributes toCompare is nil")
return false
}
if len(*attrs) != len(*toCompare) {
fmt.Println("DEBUG: Attributes len is different ")
return false
}

rAttrs := map[string]any{}
tcAttrs := map[string]any{}

for k, v := range *attrs {
fmt.Println("DEBUG: Attribute key " + k)
tcV, ok := (*toCompare)[k]
if !ok {
fmt.Println("DEBUG: Attributes key not found in toCompare")
return false
}
if vMap, isMap := v.(map[string]any); isMap {
tcVMap, tcIsMap := tcV.(map[string]any)
if !tcIsMap {
fmt.Println("DEBUG: Attributes is map but toCompare is not")
return false
}
if !attributesAreEqual(&vMap, &tcVMap) {
fmt.Println("DEBUG: Attributes submap not equal")
return false
}
continue
}
if isDirective, equal := directiveEquality(v, tcV); isDirective {
if !equal {
fmt.Println("DEBUG: Attributes Directive not equal")
return false
}
continue
Expand All @@ -154,7 +161,11 @@ func attributesAreEqual(attrs, toCompare *map[string]any) bool {
tcAttrs[k] = tcV
}

return reflect.DeepEqual(rAttrs, tcAttrs)
de := reflect.DeepEqual(rAttrs, tcAttrs)
if !de {
fmt.Println("DEBUG: Attributes not deepequal: ", rAttrs, tcAttrs)
}
return de
}

func directiveEquality(expected, actual any) (isDirective, equal bool) {
Expand Down
5 changes: 5 additions & 0 deletions tests/testutils/telemetry/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,22 +181,27 @@ func (log Log) RelaxedEquals(toCompare Log) bool {
func (log Log) equals(toCompare Log, strict bool) bool {
if isDirective, equal := directiveEquality(log.Body, toCompare.Body); isDirective {
if !equal {
fmt.Println("DEBUG: Body directive not equal")
return false
}
} else if log.Body != toCompare.Body && (strict || log.Body != nil) {
fmt.Printf("DEBUG: Body not equal: %s vs %s\n", log.Body, toCompare.Body)
return false
}

if log.SeverityText != toCompare.SeverityText && (strict || log.SeverityText != "") {
fmt.Println("DEBUG: SeverityText not equal")
return false
}

if log.Severity != nil {
if toCompare.Severity == nil || (*log.Severity != *toCompare.Severity) {
fmt.Println("DEBUG: Severity not equal")
return false
}
} else {
if strict && toCompare.Severity != nil {
fmt.Println("DEBUG: Severity toCompare not equal")
return false
}
}
Expand Down

0 comments on commit 622b83e

Please sign in to comment.