|
| 1 | +package framework |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/stretchr/testify/assert" |
| 5 | + "github.com/stretchr/testify/require" |
| 6 | + "testing" |
| 7 | +) |
| 8 | + |
| 9 | +func TestFind(t *testing.T) { |
| 10 | + childTest := &Test{ |
| 11 | + Name: "child test", |
| 12 | + Tests: []*Test{{ |
| 13 | + Name: "child child test", |
| 14 | + }}, |
| 15 | + } |
| 16 | + anotherChildTest := &Test{ |
| 17 | + Name: "another child test", |
| 18 | + Tests: []*Test{{ |
| 19 | + Name: "another child child test", |
| 20 | + }}, |
| 21 | + } |
| 22 | + |
| 23 | + suite := &Test{ |
| 24 | + Name: "root test", |
| 25 | + Tests: []*Test{ |
| 26 | + childTest, |
| 27 | + anotherChildTest, |
| 28 | + {Name: "same name"}, |
| 29 | + {Name: "same name"}, |
| 30 | + }, |
| 31 | + } |
| 32 | + |
| 33 | + testCases := map[string]struct { |
| 34 | + query []string |
| 35 | + expectNotFound bool |
| 36 | + }{ |
| 37 | + "with only root node": {query: []string{"root test"}}, |
| 38 | + "with child test": {query: []string{"root test", "child test"}}, |
| 39 | + "with nested child": {query: []string{"root test", "child test", "child child test"}}, |
| 40 | + "with not existing nested": {query: []string{"root test", "child test", "child child test", "does not exist"}, expectNotFound: true}, |
| 41 | + "with not existing root": {query: []string{"root does not exist"}, expectNotFound: true}, |
| 42 | + "with another child": {query: []string{"root test", "another child test"}}, |
| 43 | + "with another nested child": {query: []string{"root test", "another child test", "another child child test"}}, |
| 44 | + "with same name finds both": {query: []string{"root test", "same name"}}, |
| 45 | + "with not existent root should not be found": {query: []string{"non-existent root test", "child test"}, expectNotFound: true}, |
| 46 | + } |
| 47 | + |
| 48 | + for _, tt := range testCases { |
| 49 | + results := suite.find(tt.query) |
| 50 | + if tt.expectNotFound { |
| 51 | + assert.Empty(t, results) |
| 52 | + } else { |
| 53 | + require.NotEmpty(t, results) |
| 54 | + for _, result := range results { |
| 55 | + assert.Equal(t, tt.query[len(tt.query)-1], result.Name) |
| 56 | + } |
| 57 | + } |
| 58 | + } |
| 59 | +} |
0 commit comments