Skip to content

Commit

Permalink
Extends falsy test to evaluate a non empty object to an error if found
Browse files Browse the repository at this point in the history
  • Loading branch information
rica-graca committed Jul 2, 2023
1 parent 013d47d commit 7354a9e
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions functions/core/falsy_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package core

import (
"testing"

"github.com/daveshanley/vacuum/model"
"github.com/pb33f/libopenapi/utils"
"github.com/stretchr/testify/assert"
"testing"
)

func TestFalsy_RunRule_Fail(t *testing.T) {
Expand All @@ -16,12 +17,15 @@ tags:
- name: "non-falsy tag 2"
description: 1
- name: "non-falsy tag 3"
description: "hello"`
description: "hello"
- name: "non-falsy tag 4"
description:
hello: goodbye`

path := "$.tags[*]"

nodes, _ := utils.FindNodes([]byte(sampleYaml), path)
assert.Len(t, nodes, 3)
assert.Len(t, nodes, 4)

rule := buildCoreTestRule(path, model.SeverityError, "falsy", "description", nil)
ctx := buildCoreTestContext(model.CastToRuleAction(rule.Then), nil)
Expand All @@ -31,7 +35,7 @@ tags:
tru := Falsy{}
res := tru.RunRule(nodes, ctx)

assert.Len(t, res, 3)
assert.Len(t, res, 4)
}

func TestFalsy_RunRule_Fail_NoNodes(t *testing.T) {
Expand Down Expand Up @@ -72,12 +76,14 @@ tags:
- name: "falsy tag 3"
description: ""
- name: "falsy Tag 4"
description: "0"`
description: "0"
- name: "falsy Tag 5"
description:`

path := "$.tags[*]"

nodes, _ := utils.FindNodes([]byte(sampleYaml), path)
assert.Len(t, nodes, 4)
assert.Len(t, nodes, 5)

rule := buildCoreTestRule(path, model.SeverityError, "Falsy", "description", nil)
ctx := buildCoreTestContext(model.CastToRuleAction(rule.Then), nil)
Expand Down

0 comments on commit 7354a9e

Please sign in to comment.