Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 44 additions & 9 deletions internal/index/digest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ func TestWithIndex(t *testing.T) {

g.Expect(d.digests).To(BeEmpty())
})

t.Run("handles nil index", func(t *testing.T) {
g := NewWithT(t)
d := &Digester{}
WithIndex(nil)(d)
g.Expect(d.index).To(BeNil())
})
}

func TestNewDigester(t *testing.T) {
Expand Down Expand Up @@ -107,6 +114,13 @@ func TestDigester_Add(t *testing.T) {

g.Expect(d.digests).To(BeEmpty())
})

t.Run("adds empty key and value", func(t *testing.T) {
g := NewWithT(t)
d := NewDigester()
d.Add("", "")
g.Expect(d.index).To(HaveKeyWithValue("", ""))
})
}

func TestDigester_Delete(t *testing.T) {
Expand Down Expand Up @@ -138,6 +152,14 @@ func TestDigester_Delete(t *testing.T) {
d.Delete("foo")
g.Expect(d.digests).To(BeEmpty())
})

t.Run("deletes non-existent key without error", func(t *testing.T) {
g := NewWithT(t)
d := NewDigester()
d.Delete("non-existent")
g.Expect(d.index).To(BeEmpty())
g.Expect(d.digests).To(BeEmpty())
})
}

func TestDigester_Get(t *testing.T) {
Expand All @@ -161,17 +183,26 @@ func TestDigester_Has(t *testing.T) {
}

func TestDigester_Index(t *testing.T) {
g := NewWithT(t)
t.Run("returns a copy of the index", func(t *testing.T) {
g := NewWithT(t)

i := map[string]string{
"foo": "bar",
"bar": "baz",
}
d := NewDigester(WithIndex(i))
i := map[string]string{
"foo": "bar",
"bar": "baz",
}
d := NewDigester(WithIndex(i))

iCopy := d.Index()
g.Expect(iCopy).To(Equal(i))
g.Expect(iCopy).ToNot(BeIdenticalTo(i))
iCopy := d.Index()
g.Expect(iCopy).To(Equal(i))
g.Expect(iCopy).ToNot(BeIdenticalTo(i))
})

t.Run("returns an empty copy for an empty index", func(t *testing.T) {
g := NewWithT(t)
d := NewDigester()
emptyIndex := d.Index()
g.Expect(emptyIndex).To(BeEmpty())
})
}

func TestDigester_Len(t *testing.T) {
Expand All @@ -183,6 +214,8 @@ func TestDigester_Len(t *testing.T) {
}))

g.Expect(d.Len()).To(Equal(2))

g.Expect(NewDigester().Len()).To(Equal(0))
}

func TestDigester_String(t *testing.T) {
Expand All @@ -196,6 +229,8 @@ func TestDigester_String(t *testing.T) {
g.Expect(d.String()).To(Equal(`bar baz
foo bar
`))

g.Expect(NewDigester().String()).To(Equal(""))
}

func TestDigester_WriteTo(t *testing.T) {
Expand Down