@@ -229,6 +229,97 @@ func TestAdminDeleteEndpoint(t *testing.T) {
229229}
230230
231231func TestAdminGetEndpoint (t * testing.T ) {
232+ mockSource := testutils.MockSource {MockSourceConfig : testutils.MockSourceConfig {Foo : "foo" , Password : "password" }}
233+ mockAuthService := testutils.MockAuthService {MockAuthServiceConfig : testutils.MockAuthServiceConfig {Foo : "foo" }}
234+ mockEmbeddingModel := testutils.MockEmbeddingModel {MockEmbeddingModelConfig : testutils.MockEmbeddingModelConfig {Foo : "foo" }}
235+ mockTool := testutils.MockTool {MockToolConfig : testutils.MockToolConfig {Foo : "foo" }}
236+ mockToolset := tools.Toolset {ToolsetConfig : tools.ToolsetConfig {ToolNames : []string {"test-tool" }}}
237+ mockPrompt := testutils.MockPrompt {MockPromptConfig : testutils.MockPromptConfig {Foo : "foo" }}
238+
239+ mockSources := map [string ]sources.Source {"test-source" : mockSource }
240+ mockAuthServices := map [string ]auth.AuthService {"test-auth-service" : mockAuthService }
241+ mockEmbeddingModels := map [string ]embeddingmodels.EmbeddingModel {"test-embedding-model" : mockEmbeddingModel }
242+ mockTools := map [string ]tools.Tool {"test-tool" : mockTool }
243+ mockToolsets := map [string ]tools.Toolset {"test-toolset" : mockToolset }
244+ mockPrompts := map [string ]prompts.Prompt {"test-prompt" : mockPrompt }
245+
246+ r , shutdown := setUpServer (t , "admin" , mockSources , mockAuthServices , mockEmbeddingModels , mockTools , mockToolsets , mockPrompts , map [string ]prompts.Promptset {})
247+ defer shutdown ()
248+ ts := runServer (r , false )
249+ defer ts .Close ()
250+
251+ tests := []struct {
252+ name string
253+ kind string
254+ want []string
255+ expectedStatusCode int
256+ }{
257+ {
258+ name : "Get Source - Success" ,
259+ kind : "source" ,
260+ want : []string {"test-source" },
261+ expectedStatusCode : http .StatusOK ,
262+ },
263+ {
264+ name : "Get Auth Service - Success" ,
265+ kind : "authService" ,
266+ want : []string {"test-auth-service" },
267+ expectedStatusCode : http .StatusOK ,
268+ },
269+ {
270+ name : "Get Embedding Model - Success" ,
271+ kind : "embeddingModel" ,
272+ want : []string {"test-embedding-model" },
273+ expectedStatusCode : http .StatusOK ,
274+ },
275+ {
276+ name : "Get Tool - Success" ,
277+ kind : "tool" ,
278+ want : []string {"test-tool" },
279+ expectedStatusCode : http .StatusOK ,
280+ },
281+ {
282+ name : "Get Toolset - Success" ,
283+ kind : "toolset" ,
284+ want : []string {"test-toolset" },
285+ expectedStatusCode : http .StatusOK ,
286+ },
287+ {
288+ name : "Get Prompt - Success" ,
289+ kind : "prompt" ,
290+ want : []string {"test-prompt" },
291+ expectedStatusCode : http .StatusOK ,
292+ },
293+ {
294+ name : "Get with Invalid Kind - Bad Request" ,
295+ kind : "invalidKind" ,
296+ expectedStatusCode : http .StatusBadRequest ,
297+ },
298+ }
299+
300+ for _ , tt := range tests {
301+ t .Run (tt .name , func (t * testing.T ) {
302+ resp , body , err := runRequest (ts , http .MethodGet , fmt .Sprintf ("/%s" , tt .kind ), nil , nil )
303+ if err != nil {
304+ t .Fatalf ("unexpected error during request: %s" , err )
305+ }
306+ if resp .StatusCode != tt .expectedStatusCode {
307+ t .Fatalf ("response status code is not %d, got %d, %s" , tt .expectedStatusCode , resp .StatusCode , string (body ))
308+ }
309+ if tt .expectedStatusCode == http .StatusOK {
310+ var got []string
311+ if err := json .Unmarshal (body , & got ); err != nil {
312+ t .Fatalf ("error unmarshaling response body" )
313+ }
314+ if ! reflect .DeepEqual (got , tt .want ) {
315+ t .Fatalf ("unexpected output: got %+v, want %+v" , got , tt .want )
316+ }
317+ }
318+ })
319+ }
320+ }
321+
322+ func TestAdminGetByNameEndpoint (t * testing.T ) {
232323 mockSource := testutils.MockSource {MockSourceConfig : testutils.MockSourceConfig {Foo : "foo" , Password : "password" }}
233324 mockSourceConfigMasked := testutils.MockSourceConfig {Foo : "foo" , Password : "***" }
234325 mockAuthService := testutils.MockAuthService {MockAuthServiceConfig : testutils.MockAuthServiceConfig {Foo : "foo" }}
0 commit comments