style(tests): `ShouldNot(Succeed())` -> `Should(HaveOccurred())`

This commit is contained in:
ThinkChaos 2023-11-23 19:41:43 -05:00
parent 321680250a
commit a330174949
12 changed files with 60 additions and 60 deletions

View File

@ -165,7 +165,7 @@ var _ = Describe("Config", func() {
When("Test file does not exist", func() {
It("should fail", func() {
_, err := LoadConfig(tmpDir.JoinPath("config-does-not-exist.yaml"), true)
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
})
})
When("Multiple config files are used", func() {
@ -199,7 +199,7 @@ var _ = Describe("Config", func() {
When("Config folder does not exist", func() {
It("should fail", func() {
_, err := LoadConfig(tmpDir.JoinPath("does-not-exist-config/"), true)
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
})
})
When("config file is malformed", func() {
@ -766,7 +766,7 @@ bootstrapDns:
}
_, err := WithDefaults[T]()
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
})
})
})

View File

@ -34,7 +34,7 @@ var _ = Describe("errorFilter", func() {
Expect(parser.Position()).Should(Equal("call 1"))
_, err = parser.Next(context.Background())
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
Expect(err).Should(MatchError(ErrTooManyErrors))
Expect(parser.Position()).Should(Equal("call 2"))
})
@ -53,7 +53,7 @@ var _ = Describe("errorFilter", func() {
Expect(parser.Position()).Should(Equal("call 3"))
_, err = parser.Next(context.Background())
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
Expect(err).Should(MatchError(ErrTooManyErrors))
Expect(parser.Position()).Should(Equal("call 4"))
})
@ -76,7 +76,7 @@ var _ = Describe("errorFilter", func() {
Expect(parser.Position()).Should(Equal("call 5"))
_, err = parser.Next(context.Background())
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
Expect(err).Should(MatchError(io.EOF))
Expect(IsNonResumableErr(err)).Should(BeTrue())
Expect(parser.Position()).Should(Equal("call 7"))
@ -106,7 +106,7 @@ var _ = Describe("errorFilter", func() {
Expect(parser.Position()).Should(Equal("call 2"))
_, err = parser.Next(context.Background())
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
Expect(err).Should(MatchError(io.EOF))
Expect(IsNonResumableErr(err)).Should(BeTrue())

View File

@ -77,7 +77,7 @@ var _ = Describe("Hosts", func() {
Expect(sut.Position()).Should(Equal("line 9"))
_, err = sut.Next(context.Background())
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
Expect(err).Should(MatchError(io.EOF))
Expect(IsNonResumableErr(err)).Should(BeTrue())
Expect(sut.Position()).Should(Equal("line 10"))
@ -98,7 +98,7 @@ var _ = Describe("Hosts", func() {
sut := Hosts(strings.NewReader(line))
_, err := sut.Next(context.Background())
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
Expect(IsNonResumableErr(err)).ShouldNot(BeTrue())
Expect(sut.Position()).Should(Equal("line 1"))
}
@ -138,7 +138,7 @@ var _ = Describe("Hosts", func() {
err := entry.forEachHost(func(host string) error {
return expectedErr
})
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
Expect(err).Should(MatchError(expectedErr))
})
})
@ -193,7 +193,7 @@ var _ = Describe("HostsFile", func() {
Expect(sut.Position()).Should(Equal("line 5"))
_, err = sut.Next(context.Background())
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
Expect(err).Should(MatchError(io.EOF))
Expect(IsNonResumableErr(err)).Should(BeTrue())
Expect(sut.Position()).Should(Equal("line 6"))
@ -215,7 +215,7 @@ var _ = Describe("HostsFile", func() {
Expect(sut.Position()).Should(Equal("line 1"))
_, err = sut.Next(context.Background())
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
Expect(err).Should(MatchError(io.EOF))
Expect(IsNonResumableErr(err)).Should(BeTrue())
Expect(sut.Position()).Should(Equal("line 2"))
@ -237,7 +237,7 @@ var _ = Describe("HostsFile", func() {
sut := HostsFile(strings.NewReader(line))
_, err := sut.Next(context.Background())
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
Expect(IsNonResumableErr(err)).ShouldNot(BeTrue())
Expect(sut.Position()).Should(Equal("line 1"))
}
@ -271,7 +271,7 @@ var _ = Describe("HostsFile", func() {
err := entry.forEachHost(func(host string) error {
return expectedErr
})
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
Expect(err).Should(MatchError(expectedErr))
})
})
@ -291,7 +291,7 @@ var _ = Describe("HostsFile", func() {
return expectedErr
})
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
Expect(err).Should(MatchError(expectedErr))
})
})
@ -376,7 +376,7 @@ var _ = Describe("HostList", func() {
Expect(sut.Position()).Should(Equal("line 10"))
_, err = sut.Next(context.Background())
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
Expect(err).Should(MatchError(io.EOF))
Expect(IsNonResumableErr(err)).Should(BeTrue())
Expect(sut.Position()).Should(Equal("line 11"))
@ -396,7 +396,7 @@ var _ = Describe("HostList", func() {
sut := HostList(strings.NewReader(line))
_, err := sut.Next(context.Background())
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
Expect(IsNonResumableErr(err)).ShouldNot(BeTrue())
Expect(sut.Position()).Should(Equal("line 1"))
}
@ -430,7 +430,7 @@ var _ = Describe("HostList", func() {
err := entry.forEachHost(func(host string) error {
return expectedErr
})
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
Expect(err).Should(MatchError(expectedErr))
})
})

View File

@ -56,7 +56,7 @@ var _ = Describe("Lines", func() {
Expect(sut.Position()).Should(Equal("line 3"))
_, err = sut.Next(context.Background())
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
Expect(err).Should(MatchError(io.EOF))
Expect(IsNonResumableErr(err)).Should(BeTrue())
Expect(sut.Position()).Should(Equal("line 4"))
@ -75,7 +75,7 @@ var _ = Describe("Lines", func() {
It("skips them", func() {
_, err := sut.Next(context.Background())
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
Expect(err).Should(MatchError(io.EOF))
Expect(IsNonResumableErr(err)).Should(BeTrue())
Expect(sut.Position()).Should(Equal("line 5"))
@ -135,7 +135,7 @@ var _ = Describe("Lines", func() {
It("fails", func() {
_, err := sut.Next(context.Background())
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
Expect(sut.Position()).Should(Equal("line 1"))
})
})
@ -160,7 +160,7 @@ var _ = Describe("Lines", func() {
cancel()
_, err = sut.Next(ctx)
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
Expect(IsNonResumableErr(err)).Should(BeTrue())
Expect(sut.Position()).Should(Equal("line 2"))
})

View File

@ -35,7 +35,7 @@ var _ = Describe("ForEach", func() {
err := ForEach(context.Background(), lines, func(line string) error {
return expectedErr
})
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
Expect(err).Should(MatchError(expectedErr))
Expect(err.Error()).Should(HavePrefix("line 1: "))
})
@ -50,7 +50,7 @@ var _ = Describe("ForEach", func() {
return nil
})
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
Expect(err.Error()).Should(HavePrefix("line 1: "))
})
@ -66,7 +66,7 @@ var _ = Describe("ForEach", func() {
return nil
})
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
Expect(err).Should(MatchError(context.Canceled))
Expect(err.Error()).Should(HavePrefix("line 1: "))
})
@ -80,7 +80,7 @@ var _ = Describe("ForEach", func() {
return nil
})
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
Expect(err).Should(MatchError(context.Canceled))
Expect(err.Error()).Should(HavePrefix("line 0: "))
})
@ -99,14 +99,14 @@ var _ = Describe("ErrWithPosition", func() {
Expect(err).Should(Succeed())
err = ErrWithPosition(lines, inner)
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
Expect(err.Error()).Should(Equal("line 1: inner"))
_, err = lines.Next(context.Background())
Expect(err).Should(Succeed())
err = ErrWithPosition(lines, inner)
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
Expect(err.Error()).Should(Equal("line 2: inner"))
})
})

View File

@ -73,7 +73,7 @@ var _ = Describe("Bootstrap", Label("bootstrap"), func() {
}
_, err := sut.resolveUpstream(ctx, nil, "example.com")
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
Expect(usedSystemResolver).Should(Receive(BeTrue()))
})
@ -105,7 +105,7 @@ var _ = Describe("Bootstrap", Label("bootstrap"), func() {
}
_, err := NewBootstrap(ctx, &cfg)
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
})
})
})
@ -147,7 +147,7 @@ var _ = Describe("Bootstrap", Label("bootstrap"), func() {
}
_, err := NewBootstrap(ctx, &cfg)
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
Expect(err.Error()).Should(ContainSubstring("must use IP instead of hostname"))
})
})
@ -191,7 +191,7 @@ var _ = Describe("Bootstrap", Label("bootstrap"), func() {
}
_, err := NewBootstrap(ctx, &cfg)
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
Expect(err.Error()).Should(ContainSubstring("no IPs configured"))
})
})
@ -285,7 +285,7 @@ var _ = Describe("Bootstrap", Label("bootstrap"), func() {
ips, err := sut.resolve(ctx, "localhost", []dns.Type{A})
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
Expect(err.Error()).Should(ContainSubstring(resolveErr.Error()))
Expect(ips).Should(BeEmpty())
})
@ -299,7 +299,7 @@ var _ = Describe("Bootstrap", Label("bootstrap"), func() {
ips, err := sut.resolve(ctx, "unknownhost.invalid", []dns.Type{A})
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
Expect(err.Error()).Should(ContainSubstring("no such host"))
Expect(ips).Should(BeEmpty())
})
@ -374,7 +374,7 @@ var _ = Describe("Bootstrap", Label("bootstrap"), func() {
// implicit expectation of 0 bootstrapUpstream.Resolve calls
_, err = t.DialContext(ctx, "ip", "!bad-addr!")
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
})
It("returns upstream errors", func() {
@ -386,7 +386,7 @@ var _ = Describe("Bootstrap", Label("bootstrap"), func() {
_, err = t.DialContext(ctx, "ip", "abc:123")
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
Expect(err.Error()).Should(ContainSubstring(resolveErr.Error()))
})
@ -399,7 +399,7 @@ var _ = Describe("Bootstrap", Label("bootstrap"), func() {
_, err = t.DialContext(ctx, "ip", "abc:123")
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
Expect(err.Error()).Should(ContainSubstring("no such host"))
})
})

View File

@ -377,7 +377,7 @@ var _ = Describe("ClientResolver", Label("clientNamesResolver"), func() {
Upstream: config.Upstream{Host: "example.com"},
}, upstreamsCfg, b)
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
Expect(r).Should(BeNil())
})
})

View File

@ -213,7 +213,7 @@ var _ = Describe("ConditionalUpstreamResolver", Label("conditionalResolver"), fu
}
r, err := NewConditionalUpstreamResolver(ctx, sutConfig, upstreamsCfg, b)
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
Expect(r).Should(BeNil())
})
})

View File

@ -323,7 +323,7 @@ var _ = Describe("ParallelBestResolver", Label("parallelBestResolver"), func() {
group := config.NewUpstreamGroup("test", upstreamsCfg, []config.Upstream{{Host: "example.com"}})
r, err := NewParallelBestResolver(ctx, group, b)
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
Expect(r).Should(BeNil())
})
})

View File

@ -61,7 +61,7 @@ var _ = Describe("Resolver", func() {
ch := Chain(&CustomDNSResolver{}, &BlockingResolver{})
_, err := GetFromChainWithType[*FilteringResolver](ch)
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
})
})

View File

@ -592,7 +592,7 @@ var _ = Describe("Running DNS server", func() {
_, err = NewServer(ctx, &cfg)
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
})
})
})

View File

@ -17,37 +17,37 @@ var _ = Describe("ParseIPFromArpaAddr", func() {
It("requires the arpa domain", func() {
_, err := ParseIPFromArpaAddr("4.3.2.1.in-addr.arpa.fail.")
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
_, err = ParseIPFromArpaAddr("4.3.2.1.in-addr.fail.arpa.")
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
_, err = ParseIPFromArpaAddr("4.3.2.1.fail.in-addr.arpa.")
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
})
It("requires all ip parts to be decimal numbers", func() {
_, err := ParseIPFromArpaAddr("a.3.2.1.in-addr.arpa.")
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
})
It("requires all parts to be present", func() {
_, err := ParseIPFromArpaAddr("3.2.1.in-addr.arpa.")
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
})
It("requires all parts to be non empty", func() {
_, err := ParseIPFromArpaAddr(".3.2.1.in-addr.arpa.")
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
_, err = ParseIPFromArpaAddr("4..2.1.in-addr.arpa.")
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
_, err = ParseIPFromArpaAddr("4.3..1.in-addr.arpa.")
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
_, err = ParseIPFromArpaAddr("4.3.2..in-addr.arpa.")
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
})
})
@ -60,39 +60,39 @@ var _ = Describe("ParseIPFromArpaAddr", func() {
It("requires the arpa domain", func() {
_, err := ParseIPFromArpaAddr("1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.1.0.0.0.0.0.f.7.2.0.0.2.ip6.arpa.fail.")
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
_, err = ParseIPFromArpaAddr("1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.1.0.0.0.0.0.f.7.2.0.0.2.ip6.fail.arpa.")
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
_, err = ParseIPFromArpaAddr("1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.1.0.0.0.0.0.f.7.2.0.0.2.fail.ip6.arpa.")
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
})
It("requires all LSB parts to be hex numbers", func() {
_, err := ParseIPFromArpaAddr("g.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.1.0.0.0.0.0.f.7.2.0.0.2.ip6.arpa.")
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
})
It("requires all MSB parts to be hex numbers", func() {
_, err := ParseIPFromArpaAddr("1.g.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.1.0.0.0.0.0.f.7.2.0.0.2.ip6.arpa.")
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
})
It("requires all parts to be present", func() {
_, err := ParseIPFromArpaAddr("1.0.0.0.0.0.0.0.0.0.0.0.0.g.0.0.0.0.1.0.0.0.0.0.f.7.2.0.0.2.ip6.arpa.")
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
})
It("requires all parts to non empty", func() {
_, err := ParseIPFromArpaAddr(".0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.1.0.0.0.0.0.f.7.2.0.0.2.ip6.arpa.")
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
_, err = ParseIPFromArpaAddr("0.0.0.0.0.0.0.0.0.0.0.0.0.0.0..0.0.0.0.1.0.0.0.0.0.f.7.2.0.0.2.ip6.arpa.")
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
_, err = ParseIPFromArpaAddr("0.0.0.0.0.0.0.0.0.0.0.0.0.0.0..0.0.0.0.1.0.0.0.0.0.f.7.2.0.0..ip6.arpa.")
Expect(err).ShouldNot(Succeed())
Expect(err).Should(HaveOccurred())
})
})
})