Skip to content

Commit

Permalink
tests(redis): improvements from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
pivotal-marcela-campo committed Mar 30, 2023
1 parent 2bccc5c commit 065c132
Showing 1 changed file with 66 additions and 75 deletions.
141 changes: 66 additions & 75 deletions terraform-tests/redis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,21 +273,40 @@ var _ = Describe("Redis", Label("redis-terraform"), Ordered, func() {
})

Context("slow_log is enabled", func() {
BeforeAll(func() {
var kmsKeyId string
var retentionInDays int

BeforeEach(func() {
kmsKeyId = ""
retentionInDays = 0
})

JustBeforeEach(func() {
plan = ShowPlan(terraformProvisionDir, buildVars(defaultVars, map[string]any{
"logs_slow_log_loggroup_kms_key_id": "",
"logs_slow_log_loggroup_retention_in_days": 0,
"logs_slow_log_loggroup_kms_key_id": kmsKeyId,
"logs_slow_log_loggroup_retention_in_days": retentionInDays,
"logs_slow_log_enabled": true,
}))
})

It("should create a log group for slow log", func() {
expectedResources := []string{"aws_cloudwatch_log_group"}
It("should configure a log group for slow log with default values", func() {
slowLogResource := "aws_cloudwatch_log_group"

By("creating a new loggroup resouce")
expectedResources := []string{slowLogResource}
expectedResources = append(expectedResources, getExpectedResources()...)
Expect(ResourceChangesTypes(plan)).To(ConsistOf(expectedResources))
})

It("should assign that log group to the replication group", func() {
By("configuring the log group with the default values")
Expect(AfterValuesForType(plan, slowLogResource)).To(MatchKeys(IgnoreExtras, Keys{
"name": Equal("/aws/elasticache/cluster/csb-redis-test/slow-log"),
"retention_in_days": BeNumerically("==", 0),
"kms_key_id": BeNil(),
"skip_destroy": BeFalse(),
"tags": HaveKeyWithValue("key1", "some-redis-value"),
}))

By("assignining that log group to the replication group")
Expect(AfterValuesForType(plan, resource)).To(MatchKeys(IgnoreExtras, Keys{
"log_delivery_configuration": ConsistOf(MatchAllKeys(Keys{
"destination": Equal("/aws/elasticache/cluster/csb-redis-test/slow-log"),
Expand All @@ -296,67 +315,63 @@ var _ = Describe("Redis", Label("redis-terraform"), Ordered, func() {
"log_type": Equal("slow-log"),
})),
}))

})

Context("slow_log loggroup configuration", func() {
kmsKeyId := ""
retentionInDays := 0
JustBeforeEach(func() {
plan = ShowPlan(terraformProvisionDir, buildVars(defaultVars, map[string]any{
"logs_slow_log_loggroup_kms_key_id": kmsKeyId,
"logs_slow_log_loggroup_retention_in_days": retentionInDays,
"logs_slow_log_enabled": true,
}))
Context("slow_log loggroup custom configuration", func() {
BeforeEach(func() {
kmsKeyId = "test-kms-key"
retentionInDays = 180
})

It("should configure the log group with default values", func() {
It("should configure the passed values", func() {
slowLogResource := "aws_cloudwatch_log_group"
Expect(AfterValuesForType(plan, slowLogResource)).To(MatchKeys(IgnoreExtras, Keys{
"name": Equal("/aws/elasticache/cluster/csb-redis-test/slow-log"),
"retention_in_days": BeNumerically("==", retentionInDays),
"kms_key_id": BeNil(),
"kms_key_id": Equal(kmsKeyId),
"skip_destroy": BeFalse(),
"tags": HaveKeyWithValue("key1", "some-redis-value"),
}))
})

Context("providing explicit values", func() {
BeforeEach(func() {
kmsKeyId = "test-kms-key"
retentionInDays = 180
})

It("should configure the passed values", func() {
slowLogResource := "aws_cloudwatch_log_group"
Expect(AfterValuesForType(plan, slowLogResource)).To(MatchKeys(IgnoreExtras, Keys{
"name": Equal("/aws/elasticache/cluster/csb-redis-test/slow-log"),
"retention_in_days": BeNumerically("==", retentionInDays),
"kms_key_id": Equal(kmsKeyId),
"skip_destroy": BeFalse(),
"tags": HaveKeyWithValue("key1", "some-redis-value"),
}))
})
})
})

})

Context("engine_log is enabled", func() {
BeforeAll(func() {
var kmsKeyId string
var retentionInDays int

BeforeEach(func() {
kmsKeyId = ""
retentionInDays = 0
})

JustBeforeEach(func() {
plan = ShowPlan(terraformProvisionDir, buildVars(defaultVars, map[string]any{
"logs_engine_log_loggroup_kms_key_id": "",
"logs_engine_log_loggroup_retention_in_days": 0,
"logs_engine_log_loggroup_kms_key_id": kmsKeyId,
"logs_engine_log_loggroup_retention_in_days": retentionInDays,
"logs_engine_log_enabled": true,
}))
})

It("should create a log group for engine log", func() {
expectedResources := []string{"aws_cloudwatch_log_group"}
It("should configure a log group for engine log with default values", func() {
engineLogResource := "aws_cloudwatch_log_group"

By("creating a new loggroup resouce")
expectedResources := []string{engineLogResource}
expectedResources = append(expectedResources, getExpectedResources()...)
Expect(ResourceChangesTypes(plan)).To(ConsistOf(expectedResources))
})

It("should assign that log group to the replication group", func() {
By("configuring the log group with the default values")
Expect(AfterValuesForType(plan, engineLogResource)).To(MatchKeys(IgnoreExtras, Keys{
"name": Equal("/aws/elasticache/cluster/csb-redis-test/engine-log"),
"retention_in_days": BeNumerically("==", 0),
"kms_key_id": BeNil(),
"skip_destroy": BeFalse(),
"tags": HaveKeyWithValue("key1", "some-redis-value"),
}))

By("assignining that log group to the replication group")
Expect(AfterValuesForType(plan, resource)).To(MatchKeys(IgnoreExtras, Keys{
"log_delivery_configuration": ConsistOf(MatchAllKeys(Keys{
"destination": Equal("/aws/elasticache/cluster/csb-redis-test/engine-log"),
Expand All @@ -367,47 +382,23 @@ var _ = Describe("Redis", Label("redis-terraform"), Ordered, func() {
}))
})

Context("engine_log loggroup configuration", func() {
kmsKeyId := ""
retentionInDays := 0
JustBeforeEach(func() {
plan = ShowPlan(terraformProvisionDir, buildVars(defaultVars, map[string]any{
"logs_engine_log_loggroup_kms_key_id": kmsKeyId,
"logs_engine_log_loggroup_retention_in_days": retentionInDays,
"logs_engine_log_enabled": true,
}))
Context("engine loggroup custom coonfiguration", func() {
BeforeEach(func() {
kmsKeyId = "test-kms-key-2"
retentionInDays = 5
})

It("should configure the log group with default values", func() {
It("should configure the specified values", func() {
engineLogResource := "aws_cloudwatch_log_group"
Expect(AfterValuesForType(plan, engineLogResource)).To(MatchKeys(IgnoreExtras, Keys{
"name": Equal("/aws/elasticache/cluster/csb-redis-test/engine-log"),
"retention_in_days": BeNumerically("==", retentionInDays),
"kms_key_id": BeNil(),
"retention_in_days": BeNumerically("==", 5),
"kms_key_id": Equal("test-kms-key-2"),
"skip_destroy": BeFalse(),
"tags": HaveKeyWithValue("key1", "some-redis-value"),
}))
})

Context("providing explicit values", func() {
BeforeEach(func() {
kmsKeyId = "test-kms-key"
retentionInDays = 180
})

It("should configure the passed values", func() {
engineLogResource := "aws_cloudwatch_log_group"
Expect(AfterValuesForType(plan, engineLogResource)).To(MatchKeys(IgnoreExtras, Keys{
"name": Equal("/aws/elasticache/cluster/csb-redis-test/engine-log"),
"retention_in_days": BeNumerically("==", retentionInDays),
"kms_key_id": Equal(kmsKeyId),
"skip_destroy": BeFalse(),
"tags": HaveKeyWithValue("key1", "some-redis-value"),
}))
})
})
})

})
})

Expand Down

0 comments on commit 065c132

Please sign in to comment.