-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(instrument): rework test files (#383)
Use `instrument_test` package for tests of the public API. This ensures all test packaging styles are in use in this package; which is a good thing for some package-loading tests.
- Loading branch information
1 parent
3d60a25
commit 9fabf32
Showing
5 changed files
with
92 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed | ||
// under the Apache License Version 2.0. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
// Copyright 2023-present Datadog, Inc. | ||
|
||
package instrument | ||
|
||
func getOpName(metadata ...any) string { | ||
rank := map[string]int{ | ||
"verb": 1, | ||
"function-name": 2, | ||
} | ||
|
||
var ( | ||
opname string | ||
oprank = 10_000 // just a higher number than any key in the rank map. | ||
) | ||
for i := 0; i < len(metadata); i += 2 { | ||
if i+1 >= len(metadata) { | ||
break | ||
} | ||
if k, ok := metadata[i].(string); ok { | ||
if r, ok := rank[k]; ok && r < oprank { | ||
if on, ok := metadata[i+1].(string); ok { | ||
opname = on | ||
oprank = r | ||
continue | ||
} | ||
} | ||
} | ||
} | ||
return opname | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed | ||
// under the Apache License Version 2.0. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
// Copyright 2023-present Datadog, Inc. | ||
|
||
package instrument | ||
|
||
import "testing" | ||
|
||
func TestGetOpName(t *testing.T) { | ||
for _, tt := range []struct { | ||
metadata []any | ||
opname string | ||
}{ | ||
{ | ||
metadata: []any{"foo", "bar", "verb", "just-verb"}, | ||
opname: "just-verb", | ||
}, | ||
{ | ||
metadata: []any{"foo", "bar", "function-name", "just-function-name"}, | ||
opname: "just-function-name", | ||
}, | ||
{ | ||
metadata: []any{"foo", "bar", "verb", "verb-function-name", "function-name", "THIS IS WRONG"}, | ||
opname: "verb-function-name", | ||
}, | ||
{ | ||
// Checking different order | ||
metadata: []any{"foo", "bar", "function-name", "THIS IS WRONG", "verb", "verb-function-name"}, | ||
opname: "verb-function-name", | ||
}, | ||
} { | ||
t.Run(tt.opname, func(t *testing.T) { | ||
n := getOpName(tt.metadata...) | ||
if n != tt.opname { | ||
t.Errorf("Expected %s, but got %s\n", tt.opname, n) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed | ||
// under the Apache License Version 2.0. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
// Copyright 2023-present Datadog, Inc. | ||
|
||
//go:build tools | ||
|
||
package instrument | ||
|
||
// Ensures that `orchestrion.tool.go` files importing this package include all | ||
// the necessary transitive dependencies for all possible integrations, and | ||
// correctly discover the aspects to inject. | ||
import _ "github.com/DataDog/orchestrion/internal/injector/builtin" |