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

Function TestAssignVariable

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

Source from the content-addressed store, hash-verified

458}
459
460func TestAssignVariable(t *testing.T) {
461 var tests = []struct {
462 name string
463 source string
464 matchSpec MatchSpec
465 expected bool
466 }{
467 {
468 name: "check assignVariable handling in pass case",
469 source: `
470resource "aws_s3_bucket" "test-bucket" {
471 bucket = "test-bucket"
472
473 lifecycle_rule {
474 id = "test-bucket-rule-1"
475 }
476}
477`,
478 matchSpec: testAssignVariableMatchSpec,
479 expected: true,
480 },
481 {
482 name: "check assignVariable handling in fail case",
483 source: `
484resource "aws_s3_bucket" "test-bucket" {
485 bucket = "test-bucket"
486
487 lifecycle_rule {
488 id = "not-bucket-name-rule-1"
489 }
490}
491`,
492 matchSpec: testAssignVariableMatchSpec,
493 expected: false,
494 },
495 }
496
497 for _, test := range tests {
498 t.Run(test.name, func(t *testing.T) {
499 block := parseFromSource(t, test.source)[0].GetBlocks()[0]
500 result := evalMatchSpec(block, &test.matchSpec, NewEmptyCustomContext())
501 assert.Equal(t, test.expected, result, "processing variable assignments incorrectly.")
502 })
503 }
504}
505
506func TestRegexMatches(t *testing.T) {
507 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