-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathcall_test.go
More file actions
60 lines (54 loc) · 2.01 KB
/
Copy pathcall_test.go
File metadata and controls
60 lines (54 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// 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 advice_test
import (
"testing"
"github.com/DataDog/orchestrion/internal/injector/aspect/advice"
"github.com/DataDog/orchestrion/internal/injector/aspect/advice/code"
"github.com/DataDog/orchestrion/internal/injector/aspect/context"
"github.com/DataDog/orchestrion/internal/injector/typed"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestAppendArgs(t *testing.T) {
t.Run("AddedImports", func(t *testing.T) {
type testCase struct {
argType typed.TypeName
args []*code.Template
expectedImports []string
}
testCases := map[string]testCase{
"imports-none": {
argType: typed.Any,
args: []*code.Template{code.MustTemplate("true", nil, context.GoLangVersion{})},
},
"imports-from-arg-type": {
argType: typed.MustTypeName("*net/http.Request"),
args: []*code.Template{code.MustTemplate("true", nil, context.GoLangVersion{})},
expectedImports: []string{"net/http"},
},
"imports-from-templates": {
argType: typed.Any,
args: []*code.Template{
code.MustTemplate("imp.Value", map[string]string{"imp": "github.com/namespace/foo"}, context.GoLangVersion{}),
code.MustTemplate("imp.Value", map[string]string{"imp": "github.com/namespace/bar"}, context.GoLangVersion{}),
},
expectedImports: []string{
"github.com/namespace/foo",
"github.com/namespace/bar",
},
},
}
for name, tc := range testCases {
t.Run(name, func(t *testing.T) {
imports := advice.AppendArgs(tc.argType, tc.args...).AddedImports()
for _, imp := range tc.expectedImports {
assert.Contains(t, imports, imp)
}
require.Len(t, imports, len(tc.expectedImports), "expected %d imports, got %d", len(tc.expectedImports), len(imports))
})
}
})
}