|
| 1 | +package builder |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + properties "github.com/arduino/go-properties-orderedmap" |
| 7 | + "github.com/stretchr/testify/require" |
| 8 | +) |
| 9 | + |
| 10 | +func TestRecipeFinder(t *testing.T) { |
| 11 | + t.Run("NumberedRecipes", func(t *testing.T) { |
| 12 | + buildProperties := properties.NewMap() |
| 13 | + buildProperties.Set("recipe.test", "test") |
| 14 | + buildProperties.Set("recipe.1.test", "test2") |
| 15 | + buildProperties.Set("recipe.2.test", "test3") |
| 16 | + recipes := findRecipes(buildProperties, "recipe", ".test") |
| 17 | + require.Equal(t, []string{"recipe.1.test", "recipe.2.test"}, recipes) |
| 18 | + }) |
| 19 | + t.Run("NumberedRecipesWithGaps", func(t *testing.T) { |
| 20 | + buildProperties := properties.NewMap() |
| 21 | + buildProperties.Set("recipe.test", "test") |
| 22 | + buildProperties.Set("recipe.2.test", "test3") |
| 23 | + buildProperties.Set("recipe.0.test", "test2") |
| 24 | + recipes := findRecipes(buildProperties, "recipe", ".test") |
| 25 | + require.Equal(t, []string{"recipe.0.test", "recipe.2.test"}, recipes) |
| 26 | + }) |
| 27 | + t.Run("NumberedRecipesWithGapsAndDifferentLenghtNumbers", func(t *testing.T) { |
| 28 | + buildProperties := properties.NewMap() |
| 29 | + buildProperties.Set("recipe.test", "test") |
| 30 | + buildProperties.Set("recipe.12.test", "test3") |
| 31 | + buildProperties.Set("recipe.2.test", "test2") |
| 32 | + recipes := findRecipes(buildProperties, "recipe", ".test") |
| 33 | + require.Equal(t, []string{"recipe.2.test", "recipe.12.test"}, recipes) |
| 34 | + }) |
| 35 | + t.Run("UnnumberedRecipies", func(t *testing.T) { |
| 36 | + buildProperties := properties.NewMap() |
| 37 | + buildProperties.Set("recipe.test", "test") |
| 38 | + buildProperties.Set("recipe.a.test", "test3") |
| 39 | + buildProperties.Set("recipe.b.test", "test2") |
| 40 | + recipes := findRecipes(buildProperties, "recipe", ".test") |
| 41 | + require.Equal(t, []string{"recipe.test"}, recipes) |
| 42 | + }) |
| 43 | +} |
0 commit comments