Skip to content

Commit

Permalink
style(tests): use ContainElements where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
ThinkChaos committed Dec 1, 2023
1 parent fe5c753 commit f371857
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 49 deletions.
6 changes: 4 additions & 2 deletions config/custom_dns_test.go
Expand Up @@ -58,8 +58,10 @@ var _ = Describe("CustomDNSConfig", func() {
cfg.LogConfig(logger)

Expect(hook.Calls).ShouldNot(BeEmpty())
Expect(hook.Messages).Should(ContainElement(ContainSubstring("custom.domain = ")))
Expect(hook.Messages).Should(ContainElement(ContainSubstring("multiple.ips = ")))
Expect(hook.Messages).Should(ContainElements(
ContainSubstring("custom.domain = "),
ContainSubstring("multiple.ips = "),
))
})
})

Expand Down
10 changes: 5 additions & 5 deletions config/ecs_test.go
Expand Up @@ -76,11 +76,11 @@ var _ = Describe("ECS", func() {
c.LogConfig(logger)

Expect(hook.Calls).Should(HaveLen(4))
Expect(hook.Messages).Should(SatisfyAll(
ContainElement(ContainSubstring("Use as client")),
ContainElement(ContainSubstring("Forward")),
ContainElement(ContainSubstring("IPv4 netmask")),
ContainElement(ContainSubstring("IPv6 netmask")),
Expect(hook.Messages).Should(ContainElements(
ContainSubstring("Use as client"),
ContainSubstring("Forward"),
ContainSubstring("IPv4 netmask"),
ContainSubstring("IPv6 netmask"),
))
})
})
Expand Down
8 changes: 5 additions & 3 deletions config/filtering_test.go
Expand Up @@ -47,9 +47,11 @@ var _ = Describe("FilteringConfig", func() {
cfg.LogConfig(logger)

Expect(hook.Calls).Should(HaveLen(3))
Expect(hook.Messages).Should(ContainElement(ContainSubstring("query types:")))
Expect(hook.Messages).Should(ContainElement(ContainSubstring(" - AAAA")))
Expect(hook.Messages).Should(ContainElement(ContainSubstring(" - MX")))
Expect(hook.Messages).Should(ContainElements(
ContainSubstring("query types:"),
ContainSubstring(" - AAAA"),
ContainSubstring(" - MX"),
))
})
})
})
12 changes: 8 additions & 4 deletions config/hosts_file_test.go
Expand Up @@ -53,8 +53,10 @@ var _ = Describe("HostsFileConfig", func() {
cfg.LogConfig(logger)

Expect(hook.Calls).ShouldNot(BeEmpty())
Expect(hook.Messages).Should(ContainElement(ContainSubstring("- file:///a/file/path")))
Expect(hook.Messages).Should(ContainElement(ContainSubstring("- 127.0.0.1 lo...")))
Expect(hook.Messages).Should(ContainElements(
ContainSubstring("- file:///a/file/path"),
ContainSubstring("- 127.0.0.1 lo..."),
))
})
})

Expand All @@ -70,8 +72,10 @@ var _ = Describe("HostsFileConfig", func() {
Expect(migrated).Should(BeTrue())

Expect(hook.Calls).ShouldNot(BeEmpty())
Expect(hook.Messages).Should(ContainElement(ContainSubstring("hostsFile.loading.refreshPeriod")))
Expect(hook.Messages).Should(ContainElement(ContainSubstring("hostsFile.sources")))
Expect(hook.Messages).Should(ContainElements(
ContainSubstring("hostsFile.loading.refreshPeriod"),
ContainSubstring("hostsFile.sources"),
))

Expect(cfg.Sources).Should(Equal([]BytesSource{*cfg.Deprecated.Filepath}))
Expect(cfg.Loading.RefreshPeriod).Should(Equal(*cfg.Deprecated.RefreshPeriod))
Expand Down
6 changes: 4 additions & 2 deletions config/rewriter_test.go
Expand Up @@ -48,8 +48,10 @@ var _ = Describe("RewriterConfig", func() {
cfg.LogConfig(logger)

Expect(hook.Calls).ShouldNot(BeEmpty())
Expect(hook.Messages).Should(ContainElement(ContainSubstring("rules:")))
Expect(hook.Messages).Should(ContainElement(ContainSubstring("original2 =")))
Expect(hook.Messages).Should(ContainElements(
ContainSubstring("rules:"),
ContainSubstring("original2 ="),
))
})
})
})
18 changes: 11 additions & 7 deletions config/upstreams_test.go
Expand Up @@ -54,9 +54,11 @@ var _ = Describe("ParallelBestConfig", func() {
cfg.LogConfig(logger)

Expect(hook.Calls).ShouldNot(BeEmpty())
Expect(hook.Messages).Should(ContainElement(ContainSubstring("timeout:")))
Expect(hook.Messages).Should(ContainElement(ContainSubstring("groups:")))
Expect(hook.Messages).Should(ContainElement(ContainSubstring(":host2:")))
Expect(hook.Messages).Should(ContainElements(
ContainSubstring("timeout:"),
ContainSubstring("groups:"),
ContainSubstring(":host2:"),
))
})
})
})
Expand Down Expand Up @@ -102,10 +104,12 @@ var _ = Describe("ParallelBestConfig", func() {
cfg.LogConfig(logger)

Expect(hook.Calls).ShouldNot(BeEmpty())
Expect(hook.Messages).Should(ContainElement(ContainSubstring("group: test")))
Expect(hook.Messages).Should(ContainElement(ContainSubstring("upstreams:")))
Expect(hook.Messages).Should(ContainElement(ContainSubstring(":host1:")))
Expect(hook.Messages).Should(ContainElement(ContainSubstring(":host2:")))
Expect(hook.Messages).Should(ContainElements(
ContainSubstring("group: test"),
ContainSubstring("upstreams:"),
ContainSubstring(":host1:"),
ContainSubstring(":host2:"),
))
})
})
})
Expand Down
42 changes: 19 additions & 23 deletions e2e/metrics_test.go
Expand Up @@ -78,12 +78,11 @@ var _ = Describe("Metrics functional tests", func() {
When("Some query results are cached", func() {
BeforeEach(func(ctx context.Context) {
Eventually(fetchBlockyMetrics).WithArguments(ctx, metricsURL).
Should(
SatisfyAll(
ContainElement("blocky_cache_entry_count 0"),
ContainElement("blocky_cache_hit_count 0"),
ContainElement("blocky_cache_miss_count 0"),
))
Should(ContainElements(
"blocky_cache_entry_count 0",
"blocky_cache_hit_count 0",
"blocky_cache_miss_count 0",
))
})

It("Should increment cache counts", func(ctx context.Context) {
Expand All @@ -98,12 +97,11 @@ var _ = Describe("Metrics functional tests", func() {
))

Eventually(fetchBlockyMetrics).WithArguments(ctx, metricsURL).
Should(
SatisfyAll(
ContainElement("blocky_cache_entry_count 1"),
ContainElement("blocky_cache_hit_count 0"),
ContainElement("blocky_cache_miss_count 1"),
))
Should(ContainElements(
"blocky_cache_entry_count 1",
"blocky_cache_hit_count 0",
"blocky_cache_miss_count 1",
))
})

By("Same query again, should increment the cache hit count", func() {
Expand All @@ -115,24 +113,22 @@ var _ = Describe("Metrics functional tests", func() {
))

Eventually(fetchBlockyMetrics).WithArguments(ctx, metricsURL).
Should(
SatisfyAll(
ContainElement("blocky_cache_entry_count 1"),
ContainElement("blocky_cache_hit_count 1"),
ContainElement("blocky_cache_miss_count 1"),
))
Should(ContainElements(
"blocky_cache_entry_count 1",
"blocky_cache_hit_count 1",
"blocky_cache_miss_count 1",
))
})
})
})

When("Lists are loaded", func() {
It("Should expose list cache sizes per group as metrics", func(ctx context.Context) {
Eventually(fetchBlockyMetrics).WithArguments(ctx, metricsURL).
Should(
SatisfyAll(
ContainElement("blocky_blacklist_cache{group=\"group1\"} 1"),
ContainElement("blocky_blacklist_cache{group=\"group2\"} 3"),
))
Should(ContainElements(
"blocky_blacklist_cache{group=\"group1\"} 1",
"blocky_blacklist_cache{group=\"group2\"} 3",
))
})
})
})
Expand Down
8 changes: 5 additions & 3 deletions lists/list_cache_test.go
Expand Up @@ -423,9 +423,11 @@ var _ = Describe("ListCache", func() {

sut.LogConfig(logger)
Expect(hook.Calls).ShouldNot(BeEmpty())
Expect(hook.Messages).Should(ContainElement(ContainSubstring("gr1:")))
Expect(hook.Messages).Should(ContainElement(ContainSubstring("gr2:")))
Expect(hook.Messages).Should(ContainElement(ContainSubstring("TOTAL:")))
Expect(hook.Messages).Should(ContainElements(
ContainSubstring("gr1:"),
ContainSubstring("gr2:"),
ContainSubstring("TOTAL:"),
))
})
})

Expand Down

0 comments on commit f371857

Please sign in to comment.