Skip to content

Commit

Permalink
Add unit test to the function that determines which regions are appli…
Browse files Browse the repository at this point in the history
…cable.

Signed-off-by: Vasil Sirakov <sirakov97@gmail.com>
  • Loading branch information
VasilSirakov committed Sep 25, 2024
1 parent 4396bbb commit f530e7b
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions providers/aws/resources/aws_ec2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,35 @@ func TestShouldExcludeInstance(t *testing.T) {
require.False(t, shouldExcludeInstance(instance, filters))
})
}

func TestDetermineApplicableRegions(t *testing.T) {
t.Run("allow regions override initial region list", func(t *testing.T) {
initialRegions := []string{"a", "b"}
allowedRegions := []string{"b", "c"}
excludedRegions := []string{}

expected := []string{"b", "c"}
actual := determineApplicableRegions(initialRegions, allowedRegions, excludedRegions)
require.ElementsMatch(t, expected, actual)
})

t.Run("excluded regions work correctly", func(t *testing.T) {
initialRegions := []string{"a", "b"}
allowedRegions := []string{}
excludedRegions := []string{"b"}

expected := []string{"a"}
actual := determineApplicableRegions(initialRegions, allowedRegions, excludedRegions)
require.ElementsMatch(t, expected, actual)
})

t.Run("excluded regions not present in the initial slice are ignored", func(t *testing.T) {
initialRegions := []string{"a", "b"}
allowedRegions := []string{}
excludedRegions := []string{"b", "c", "d", "e"}

expected := []string{"a"}
actual := determineApplicableRegions(initialRegions, allowedRegions, excludedRegions)
require.ElementsMatch(t, expected, actual)
})
}

0 comments on commit f530e7b

Please sign in to comment.