MCPcopy
hub / github.com/aquasecurity/tfsec / TestNestedMatchFunction

Function TestNestedMatchFunction

internal/pkg/custom/processing_test.go:332–381  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

330}
331
332func TestNestedMatchFunction(t *testing.T) {
333 var tests = []struct {
334 name string
335 source string
336 predicateMatchSpec MatchSpec
337 expected bool
338 }{
339 {
340 name: "check nested match function with only inner true evaluation",
341 source: `
342resource "aws_ami" "example" {
343 virtualization_type = "hvm"
344 image_location = "image-XXXX"
345 kernel_id = "XXXXXXXXXX"
346}
347`,
348 predicateMatchSpec: testNestedMatchSpec,
349 expected: false,
350 },
351 {
352 name: "check nested match function with no true evaluation",
353 source: `
354resource "aws_ami" "example" {
355 virtualization_type = "hvm"
356}
357`,
358 predicateMatchSpec: testNestedMatchSpec,
359 expected: false,
360 },
361 {
362 name: "check nested match function with all true evaluation",
363 source: `
364resource "aws_ami" "example" {
365 virtualization_type = "paravirtual"
366 image_location = "image-XXXX"
367 kernel_id = "XXXXXXXXXX"
368}
369`,
370 predicateMatchSpec: testNestedMatchSpec,
371 expected: true,
372 },
373 }
374 for _, test := range tests {
375 t.Run(test.name, func(t *testing.T) {
376 block := parseFromSource(t, test.source)[0].GetBlocks()[0]
377 result := evalMatchSpec(block, &test.predicateMatchSpec, NewEmptyCustomContext())
378 assert.Equal(t, test.expected, result, "Nested match functions evaluating incorrectly.")
379 })
380 }
381}
382
383func TestNotFunction(t *testing.T) {
384 var tests = []struct {

Callers

nothing calls this directly

Calls 3

parseFromSourceFunction · 0.85
evalMatchSpecFunction · 0.85
NewEmptyCustomContextFunction · 0.85

Tested by

no test coverage detected