Skip to content

Commit

Permalink
Adding test for the linter (#580)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaspoignant authored Mar 20, 2023
1 parent 44f1fb6 commit da34a07
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
35 changes: 35 additions & 0 deletions cmd/lint/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package main

import (
"github.com/stretchr/testify/assert"
"os"
"os/exec"
"strings"
"testing"
)

func Test_Invalid_input_file(t *testing.T) {
inputFile := "testdata/invalid-rule.yaml"
inputFormat := "yaml"
testName := "Test_Invalid_input_file"

if os.Getenv("SHOULD_CRASH") == "true" {
runAppMain(inputFile, inputFormat)
return
}
// nolint: gosec
cmd := exec.Command(os.Args[0], "-test.run="+testName)
cmd.Env = append(os.Environ(), "SHOULD_CRASH=true")
err := cmd.Run()

e, ok := err.(*exec.ExitError)
assert.True(t, ok && !e.Success())
}

func runAppMain(fileName string, format string) {
args := strings.Split(os.Getenv("SHOULD_CRASH"), " ")
os.Args = append([]string{os.Args[0]}, args...)
os.Args = append(os.Args, "--input-file="+fileName)
os.Args = append(os.Args, "--input-format="+format)
main()
}
10 changes: 10 additions & 0 deletions cmd/lint/testdata/valid.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
test-flag:
variations:
true_var: true
false_var: false
targeting:
- query: key eq "random-key"
variation: false_var
defaultRule:
variation: false_var
trackEvents: false

0 comments on commit da34a07

Please sign in to comment.