11package model
22
33import (
4+ "strings"
45 "testing"
56
67 "github.com/stretchr/testify/assert"
@@ -25,8 +26,8 @@ func TestExpandTestFilePatterns_MultipleFilesWithFlag(t *testing.T) {
2526 )
2627 require .NoError (t , err )
2728 assert .Len (t , files , 2 )
28- assert .True (t , containsPath (files , "example/model.fga.yaml" ))
29- assert .True (t , containsPath (files , "example/store_abac.fga.yaml" ))
29+ assert .True (t , anyContains (files , "example/model.fga.yaml" ))
30+ assert .True (t , anyContains (files , "example/store_abac.fga.yaml" ))
3031}
3132
3233func TestExpandTestFilePatterns_GlobPattern (t * testing.T ) {
@@ -35,8 +36,8 @@ func TestExpandTestFilePatterns_GlobPattern(t *testing.T) {
3536 files , err := expandTestFilePatterns ([]string {"../../example/*.fga.yaml" }, []string {})
3637 require .NoError (t , err )
3738 assert .GreaterOrEqual (t , len (files ), 2 , "should match at least model.fga.yaml and store_abac.fga.yaml" )
38- assert .True (t , containsPath (files , "example/model.fga.yaml" ))
39- assert .True (t , containsPath (files , "example/store_abac.fga.yaml" ))
39+ assert .True (t , anyContains (files , "example/model.fga.yaml" ))
40+ assert .True (t , anyContains (files , "example/store_abac.fga.yaml" ))
4041}
4142
4243func TestExpandTestFilePatterns_ShellExpandedFiles (t * testing.T ) {
@@ -50,8 +51,8 @@ func TestExpandTestFilePatterns_ShellExpandedFiles(t *testing.T) {
5051 )
5152 require .NoError (t , err )
5253 assert .Len (t , files , 2 )
53- assert .True (t , containsPath (files , "example/model.fga.yaml" ))
54- assert .True (t , containsPath (files , "example/store_abac.fga.yaml" ))
54+ assert .True (t , anyContains (files , "example/model.fga.yaml" ))
55+ assert .True (t , anyContains (files , "example/store_abac.fga.yaml" ))
5556}
5657
5758func TestExpandTestFilePatterns_MixedGlobAndLiteral (t * testing.T ) {
@@ -64,8 +65,8 @@ func TestExpandTestFilePatterns_MixedGlobAndLiteral(t *testing.T) {
6465 require .NoError (t , err )
6566 // Should include model.fga.yaml and store_abac.fga.yaml
6667 assert .GreaterOrEqual (t , len (files ), 2 , "should have at least 2 files" )
67- assert .True (t , containsPath (files , "example/model.fga.yaml" ))
68- assert .True (t , containsPath (files , "example/store_abac.fga.yaml" ))
68+ assert .True (t , anyContains (files , "example/model.fga.yaml" ))
69+ assert .True (t , anyContains (files , "example/store_abac.fga.yaml" ))
6970}
7071
7172func TestExpandTestFilePatterns_SubdirectoryGlob (t * testing.T ) {
@@ -74,7 +75,7 @@ func TestExpandTestFilePatterns_SubdirectoryGlob(t *testing.T) {
7475 files , err := expandTestFilePatterns ([]string {"../../example/subdir/*.fga.yaml" }, []string {})
7576 require .NoError (t , err )
7677 assert .Len (t , files , 1 )
77- assert .True (t , containsPath (files , "example/subdir/simple.fga.yaml" ))
78+ assert .True (t , anyContains (files , "example/subdir/simple.fga.yaml" ))
7879}
7980
8081func TestExpandTestFilePatterns_NonExistentFile (t * testing.T ) {
@@ -114,9 +115,9 @@ func TestExpandTestFilePatterns_ShellExpandedThreeFiles(t *testing.T) {
114115 )
115116 require .NoError (t , err )
116117 assert .Len (t , files , 3 )
117- assert .True (t , containsPath (files , "example/model.fga.yaml" ))
118- assert .True (t , containsPath (files , "example/store_abac.fga.yaml" ))
119- assert .True (t , containsPath (files , "example/subdir/simple.fga.yaml" ))
118+ assert .True (t , anyContains (files , "example/model.fga.yaml" ))
119+ assert .True (t , anyContains (files , "example/store_abac.fga.yaml" ))
120+ assert .True (t , anyContains (files , "example/subdir/simple.fga.yaml" ))
120121}
121122
122123func TestExpandTestFilePatterns_GlobPatternNotExpandedByShell (t * testing.T ) {
@@ -139,8 +140,8 @@ func TestExpandTestFilePatterns_CombineGlobAndShellExpanded(t *testing.T) {
139140 )
140141 require .NoError (t , err )
141142 assert .Len (t , files , 2 )
142- assert .True (t , containsPath (files , "example/model.fga.yaml" ))
143- assert .True (t , containsPath (files , "example/subdir/simple.fga.yaml" ))
143+ assert .True (t , anyContains (files , "example/model.fga.yaml" ))
144+ assert .True (t , anyContains (files , "example/subdir/simple.fga.yaml" ))
144145}
145146
146147func TestExpandTestFilePatterns_InvalidGlobPattern (t * testing.T ) {
@@ -153,25 +154,13 @@ func TestExpandTestFilePatterns_InvalidGlobPattern(t *testing.T) {
153154 assert .Contains (t , err .Error (), "invalid tests pattern" )
154155}
155156
156- // containsPath checks if any file in the slice contains the given path substring
157- func containsPath ( files []string , pathSubstring string ) bool {
158- for _ , file := range files {
159- if containsSubstring ( file , pathSubstring ) {
157+ // anyContains checks if any string in the slice contains the given substring.
158+ func anyContains ( slice []string , substr string ) bool {
159+ for _ , s := range slice {
160+ if strings . Contains ( s , substr ) {
160161 return true
161162 }
162163 }
163- return false
164- }
165-
166- func containsSubstring (s , substr string ) bool {
167- return len (s ) >= len (substr ) && (s [len (s )- len (substr ):] == substr || contains (s , substr ))
168- }
169164
170- func contains (s , substr string ) bool {
171- for i := 0 ; i <= len (s )- len (substr ); i ++ {
172- if s [i :i + len (substr )] == substr {
173- return true
174- }
175- }
176165 return false
177166}
0 commit comments