github.com/jlmeeker/kismatic@v1.10.1-0.20180612190640-57f9005a1f1a/pkg/inspector/rule/file_contents_test.go (about)

     1  package rule
     2  
     3  import "testing"
     4  
     5  func TestFileContentMatchesRuleValidation(t *testing.T) {
     6  	f := FileContentMatches{}
     7  	if errs := f.Validate(); len(errs) != 2 {
     8  		t.Errorf("expected 2 error, but got %d", len(errs))
     9  	}
    10  	f.File = "foo"
    11  	if errs := f.Validate(); len(errs) != 1 {
    12  		t.Errorf("expected 1 error, but got %d", len(errs))
    13  	}
    14  	f.ContentRegex = "\\i"
    15  	if errs := f.Validate(); len(errs) != 1 {
    16  		t.Errorf("expected 1 error, but got %d", len(errs))
    17  	}
    18  	f.ContentRegex = "foo"
    19  	if errs := f.Validate(); len(errs) != 0 {
    20  		t.Errorf("expected 0 error, but got %d", len(errs))
    21  	}
    22  }