Skip to content

Commit

Permalink
uncomment some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
simar7 committed Nov 21, 2023
1 parent bb3fb22 commit 3a95a09
Showing 1 changed file with 43 additions and 33 deletions.
76 changes: 43 additions & 33 deletions test/rules_test.go
Original file line number Diff line number Diff line change
@@ -1,36 +1,46 @@
package test

// TODO: bring this test back
//func TestAVDIDs(t *testing.T) {
// existing := make(map[string]struct{})
// for _, rule := range rules.GetRegistered(framework.ALL) {
// t.Run(rule.LongID(), func(t *testing.T) {
// if rule.GetRule().AVDID == "" {
// t.Errorf("Rule has no AVD ID: %#v", rule)
// return
// }
// if _, ok := existing[rule.GetRule().AVDID]; ok {
// t.Errorf("Rule detected with duplicate AVD ID: %s", rule.GetRule().AVDID)
// }
// })
// existing[rule.GetRule().AVDID] = struct{}{}
// }
//}
import (
"fmt"
"os"
"path/filepath"
"strings"
"testing"

// TODO: bring this test back
//func TestRulesAgainstExampleCode(t *testing.T) {
// for _, rule := range rules.GetRegistered(framework.ALL) {
// testName := fmt.Sprintf("%s/%s", rule.GetRule().AVDID, rule.LongID())
// t.Run(testName, func(t *testing.T) {
// rule := rule
// t.Parallel()
//
// t.Run("avd docs", func(t *testing.T) {
// provider := strings.ToLower(rule.GetRule().Provider.ConstName())
// service := strings.ToLower(strings.ReplaceAll(rule.GetRule().Service, "-", ""))
// _, err := os.Stat(filepath.Join("..", "avd_docs", provider, service, rule.GetRule().AVDID, "docs.md"))
// require.NoError(t, err)
// })
// })
// }
//}
"github.com/aquasecurity/defsec/pkg/framework"
"github.com/aquasecurity/defsec/pkg/rules"
"github.com/stretchr/testify/require"
)

func TestAVDIDs(t *testing.T) {
existing := make(map[string]struct{})
for _, rule := range rules.GetRegistered(framework.ALL) {
t.Run(rule.LongID(), func(t *testing.T) {
if rule.GetRule().AVDID == "" {
t.Errorf("Rule has no AVD ID: %#v", rule)
return
}
if _, ok := existing[rule.GetRule().AVDID]; ok {
t.Errorf("Rule detected with duplicate AVD ID: %s", rule.GetRule().AVDID)
}
})
existing[rule.GetRule().AVDID] = struct{}{}
}
}

func TestRulesAgainstExampleCode(t *testing.T) {
for _, rule := range rules.GetRegistered(framework.ALL) {
testName := fmt.Sprintf("%s/%s", rule.GetRule().AVDID, rule.LongID())
t.Run(testName, func(t *testing.T) {
rule := rule
t.Parallel()

t.Run("avd docs", func(t *testing.T) {
provider := strings.ToLower(rule.GetRule().Provider.ConstName())
service := strings.ToLower(strings.ReplaceAll(rule.GetRule().Service, "-", ""))
_, err := os.Stat(filepath.Join("..", "avd_docs", provider, service, rule.GetRule().AVDID, "docs.md"))
require.NoError(t, err)
})
})
}
}

0 comments on commit 3a95a09

Please sign in to comment.