Skip to content

Commit d043b41

Browse files
committed
Add tests
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
1 parent 71261a0 commit d043b41

3 files changed

Lines changed: 72 additions & 0 deletions

File tree

rag/persistency_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,40 @@ var _ = Describe("PersistentKB", func() {
119119
Expect(count).To(Equal(0))
120120
})
121121
})
122+
123+
Describe("GetEntryContent", func() {
124+
var kb *PersistentKB
125+
var testFile string
126+
127+
BeforeEach(func() {
128+
var err error
129+
kb, err = NewPersistentCollectionKB(stateFile, assetDir, engine, 1000, openaiClient, "granite-embedding-107m-multilingual")
130+
Expect(err).ToNot(HaveOccurred())
131+
132+
testFile = filepath.Join(tempDir, "getcontent.txt")
133+
err = os.WriteFile(testFile, []byte("This is content for GetEntryContent test."), 0644)
134+
Expect(err).ToNot(HaveOccurred())
135+
})
136+
137+
It("should return entry not found for missing entry", func() {
138+
_, err := kb.GetEntryContent("nonexistent.txt")
139+
Expect(err).To(HaveOccurred())
140+
Expect(err.Error()).To(ContainSubstring("entry not found"))
141+
})
142+
143+
It("should return chunks for stored entry", func() {
144+
err := kb.Store(testFile, map[string]string{"type": "test"})
145+
Expect(err).ToNot(HaveOccurred())
146+
147+
results, err := kb.GetEntryContent("getcontent.txt")
148+
Expect(err).ToNot(HaveOccurred())
149+
Expect(results).ToNot(BeEmpty())
150+
151+
var fullContent string
152+
for _, r := range results {
153+
fullContent += r.Content
154+
}
155+
Expect(fullContent).To(ContainSubstring("This is content for GetEntryContent test"))
156+
})
157+
})
122158
})

test/e2e/e2e_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,26 @@ var _ = Describe("API", func() {
141141

142142
expectContent(TestCollection, "heist", "the Great Pigeon Heist", localRecall)
143143
})
144+
145+
It("should get entry content", func() {
146+
err := localRecall.CreateCollection(TestCollection)
147+
Expect(err).ToNot(HaveOccurred())
148+
149+
fileName := tempContent(story1, localRecall)
150+
151+
chunks, err := localRecall.GetEntryContent(TestCollection, fileName)
152+
if err != nil && err.Error() == "this collection backend does not support listing entry content" {
153+
Skip("Backend (e.g. LocalAI) does not support GetEntryContent")
154+
}
155+
Expect(err).ToNot(HaveOccurred())
156+
Expect(chunks).ToNot(BeEmpty())
157+
158+
var fullContent string
159+
for _, c := range chunks {
160+
fullContent += c.Content
161+
}
162+
Expect(fullContent).To(ContainSubstring("Bertie"))
163+
})
144164
})
145165

146166
func tempContent(content string, localRecall *client.Client) string {

test/e2e/persistency_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,22 @@ var _ = Describe("Persistency", func() {
113113
Expect(docs).To(HaveLen(1))
114114
Expect(docs[0]).To(Equal("test.txt"))
115115
})
116+
117+
It("should get entry content", func() {
118+
metadata := map[string]string{"type": "test"}
119+
err := kb.Store(testFile, metadata)
120+
Expect(err).To(BeNil())
121+
122+
results, err := kb.GetEntryContent("test.txt")
123+
Expect(err).To(BeNil())
124+
Expect(results).ToNot(BeEmpty())
125+
126+
var fullContent string
127+
for _, r := range results {
128+
fullContent += r.Content
129+
}
130+
Expect(fullContent).To(ContainSubstring("This is a test document"))
131+
})
116132
})
117133

118134
Context("External Sources", func() {

0 commit comments

Comments
 (0)