Skip to content

Commit 07770ae

Browse files
ccojocarCosmin Cojocar
authored andcommitted
Add a test for composite literals when trying to resolve an AST tree node
Signed-off-by: Cosmin Cojocar <[email protected]>
1 parent f413f14 commit 07770ae

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

resolve_test.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,24 @@ var _ = Describe("Resolve ast node to concrete value", func() {
112112
Expect(value).ShouldNot(BeNil())
113113
Expect(gosec.TryResolve(value, ctx)).Should(BeTrue())
114114
})
115-
})
116115

116+
It("should successfully resolve composite literal", func() {
117+
var value *ast.CompositeLit
118+
pkg := testutils.NewTestPackage()
119+
defer pkg.Close()
120+
pkg.AddFile("foo.go", `package main; func main(){ y := []string{"value1", "value2"}; println(y) }`)
121+
ctx := pkg.CreateContext("foo.go")
122+
v := testutils.NewMockVisitor()
123+
v.Callback = func(n ast.Node, ctx *gosec.Context) bool {
124+
if node, ok := n.(*ast.CompositeLit); ok {
125+
value = node
126+
}
127+
return true
128+
}
129+
v.Context = ctx
130+
ast.Walk(v, ctx.Root)
131+
Expect(value).ShouldNot(BeNil())
132+
Expect(gosec.TryResolve(value, ctx)).Should(BeTrue())
133+
})
134+
})
117135
})

0 commit comments

Comments
 (0)