style(tests): use `ContainElements` where possible

This commit is contained in:
ThinkChaos 2023-11-23 19:50:13 -05:00
parent fe5c753eed
commit f371857150
8 changed files with 61 additions and 49 deletions

View File

@ -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 = "),
))
})
})

View File

@ -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"),
))
})
})

View File

@ -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"),
))
})
})
})

View File

@ -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..."),
))
})
})
@ -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))

View File

@ -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 ="),
))
})
})
})

View File

@ -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:"),
))
})
})
})
@ -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:"),
))
})
})
})

View File

@ -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) {
@ -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() {
@ -115,12 +113,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 1"),
ContainElement("blocky_cache_miss_count 1"),
))
Should(ContainElements(
"blocky_cache_entry_count 1",
"blocky_cache_hit_count 1",
"blocky_cache_miss_count 1",
))
})
})
})
@ -128,11 +125,10 @@ var _ = Describe("Metrics functional tests", func() {
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",
))
})
})
})

View File

@ -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:"),
))
})
})