-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #96 from grafana/health-check-separate-enabled
llms: separate health and enabled methods
- Loading branch information
Showing
4 changed files
with
87 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { enabled } from './openai'; | ||
import { LLM_PLUGIN_ROUTE } from './constants'; | ||
import { getBackendSrv } from '@grafana/runtime'; | ||
|
||
jest.mock('@grafana/runtime', () => ({ | ||
getBackendSrv: jest.fn(), | ||
})); | ||
|
||
describe('enabled', () => { | ||
it('should return false if not configured', async () => { | ||
(getBackendSrv as jest.Mock).mockImplementation(() => ({ | ||
get: jest.fn().mockReturnValue(Promise.resolve({ enabled: false })), | ||
})); | ||
|
||
// Call the enabled function | ||
const result = await enabled(); | ||
expect(result).toBe(false); | ||
}); | ||
|
||
it('should return true if configured', async () => { | ||
(getBackendSrv as jest.Mock).mockImplementation(() => ({ | ||
get: jest.fn().mockImplementation((url: string) => { | ||
if (url === `${LLM_PLUGIN_ROUTE}/settings`) { | ||
return Promise.resolve({ enabled: true }); | ||
} else if (url === `${LLM_PLUGIN_ROUTE}/health`) { | ||
return Promise.resolve({ details: { openAI: { configured: true, ok: true } } }); | ||
} | ||
// raise an error if we get here | ||
throw new Error('unexpected url'); | ||
}), | ||
})); | ||
|
||
// Call the enabled function | ||
const result = await enabled(); | ||
expect(result).toBe(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { enabled } from './vector'; | ||
import { LLM_PLUGIN_ROUTE } from './constants'; | ||
import { getBackendSrv } from '@grafana/runtime'; | ||
|
||
jest.mock('@grafana/runtime', () => ({ | ||
getBackendSrv: jest.fn(), | ||
})); | ||
|
||
describe('enabled', () => { | ||
it('should return false if not configured', async () => { | ||
(getBackendSrv as jest.Mock).mockImplementation(() => ({ | ||
get: jest.fn().mockReturnValue(Promise.resolve({ enabled: false })), | ||
})); | ||
|
||
// Call the enabled function | ||
const result = await enabled(); | ||
expect(result).toBe(false); | ||
}); | ||
|
||
it('should return true if configured', async () => { | ||
(getBackendSrv as jest.Mock).mockImplementation(() => ({ | ||
get: jest.fn().mockImplementation((url: string) => { | ||
if (url === `${LLM_PLUGIN_ROUTE}/settings`) { | ||
return Promise.resolve({ enabled: true }); | ||
} else if (url === `${LLM_PLUGIN_ROUTE}/health`) { | ||
return Promise.resolve({ details: { vector: { enabled: true, ok: true } } }); | ||
} | ||
// raise an error if we get here | ||
throw new Error('unexpected url'); | ||
}), | ||
})); | ||
|
||
// Call the enabled function | ||
const result = await enabled(); | ||
expect(result).toBe(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters