|
| 1 | +// Copyright The Perses Authors |
| 2 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | +// you may not use this file except in compliance with the License. |
| 4 | +// You may obtain a copy of the License at |
| 5 | +// |
| 6 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | +// |
| 8 | +// Unless required by applicable law or agreed to in writing, software |
| 9 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | +// See the License for the specific language governing permissions and |
| 12 | +// limitations under the License. |
| 13 | + |
| 14 | +import { getPluginModule } from '../getPluginModule'; |
| 15 | +import packageJson from '../../package.json'; |
| 16 | + |
| 17 | +interface PluginSpec { |
| 18 | + kind: string; |
| 19 | + spec: { |
| 20 | + name: string; |
| 21 | + display: { |
| 22 | + name: string; |
| 23 | + }; |
| 24 | + }; |
| 25 | +} |
| 26 | + |
| 27 | +describe('InfluxDB Plugin Integration', () => { |
| 28 | + describe('Plugin Module Resource', () => { |
| 29 | + it('should return valid PluginModuleResource', () => { |
| 30 | + const pluginModule = getPluginModule(); |
| 31 | + expect(pluginModule.kind).toBe('PluginModule'); |
| 32 | + }); |
| 33 | + |
| 34 | + it('should have correct metadata from package.json', () => { |
| 35 | + const pluginModule = getPluginModule(); |
| 36 | + expect(pluginModule.metadata.name).toBe(packageJson.name); |
| 37 | + expect(pluginModule.metadata.version).toBe(packageJson.version); |
| 38 | + }); |
| 39 | + |
| 40 | + it('should include all plugins from package.json perses config', () => { |
| 41 | + const pluginModule = getPluginModule(); |
| 42 | + const expectedPlugins = packageJson.perses.plugins; |
| 43 | + expect(pluginModule.spec.plugins).toEqual(expectedPlugins); |
| 44 | + }); |
| 45 | + |
| 46 | + it('should have correct plugin kinds', () => { |
| 47 | + const pluginModule = getPluginModule(); |
| 48 | + const pluginKinds = pluginModule.spec.plugins.map((p: PluginSpec) => p.kind); |
| 49 | + expect(pluginKinds).toContain('Datasource'); |
| 50 | + expect(pluginKinds).toContain('TimeSeriesQuery'); |
| 51 | + }); |
| 52 | + |
| 53 | + it('should have correct plugin names', () => { |
| 54 | + const pluginModule = getPluginModule(); |
| 55 | + const pluginNames = pluginModule.spec.plugins.map((p: PluginSpec) => p.spec.name); |
| 56 | + expect(pluginNames).toContain('InfluxDBDatasource'); |
| 57 | + expect(pluginNames).toContain('InfluxDBTimeSeriesQuery'); |
| 58 | + }); |
| 59 | + }); |
| 60 | + |
| 61 | + describe('Plugin Metadata', () => { |
| 62 | + it('should have display names for all plugins', () => { |
| 63 | + const pluginModule = getPluginModule(); |
| 64 | + pluginModule.spec.plugins.forEach((plugin: PluginSpec) => { |
| 65 | + expect(plugin.spec.display).toBeDefined(); |
| 66 | + expect(plugin.spec.display.name).toBeDefined(); |
| 67 | + expect(plugin.spec.display.name).toBeTruthy(); |
| 68 | + }); |
| 69 | + }); |
| 70 | + |
| 71 | + it('should have valid plugin specifications', () => { |
| 72 | + const pluginModule = getPluginModule(); |
| 73 | + pluginModule.spec.plugins.forEach((plugin: PluginSpec) => { |
| 74 | + expect(plugin.kind).toBeTruthy(); |
| 75 | + expect(plugin.spec).toBeDefined(); |
| 76 | + expect(plugin.spec.name).toBeDefined(); |
| 77 | + }); |
| 78 | + }); |
| 79 | + }); |
| 80 | + |
| 81 | + describe('Datasource Plugin Configuration', () => { |
| 82 | + it('should have InfluxDB Datasource configured', () => { |
| 83 | + const pluginModule = getPluginModule(); |
| 84 | + const datasourcePlugin = pluginModule.spec.plugins.find( |
| 85 | + (p: PluginSpec) => p.kind === 'Datasource' && p.spec.name === 'InfluxDBDatasource' |
| 86 | + ); |
| 87 | + expect(datasourcePlugin).toBeDefined(); |
| 88 | + }); |
| 89 | + |
| 90 | + it('should have correct Datasource display name', () => { |
| 91 | + const pluginModule = getPluginModule(); |
| 92 | + const datasourcePlugin = pluginModule.spec.plugins.find( |
| 93 | + (p: PluginSpec) => p.kind === 'Datasource' && p.spec.name === 'InfluxDBDatasource' |
| 94 | + ); |
| 95 | + expect(datasourcePlugin?.spec.display.name).toBe('InfluxDB Datasource'); |
| 96 | + }); |
| 97 | + }); |
| 98 | + |
| 99 | + describe('TimeSeriesQuery Plugin Configuration', () => { |
| 100 | + it('should have TimeSeriesQuery plugin configured', () => { |
| 101 | + const pluginModule = getPluginModule(); |
| 102 | + const queryPlugin = pluginModule.spec.plugins.find( |
| 103 | + (p: PluginSpec) => p.kind === 'TimeSeriesQuery' && p.spec.name === 'InfluxDBTimeSeriesQuery' |
| 104 | + ); |
| 105 | + expect(queryPlugin).toBeDefined(); |
| 106 | + }); |
| 107 | + |
| 108 | + it('should have correct TimeSeriesQuery display name', () => { |
| 109 | + const pluginModule = getPluginModule(); |
| 110 | + const queryPlugin = pluginModule.spec.plugins.find( |
| 111 | + (p: PluginSpec) => p.kind === 'TimeSeriesQuery' && p.spec.name === 'InfluxDBTimeSeriesQuery' |
| 112 | + ); |
| 113 | + expect(queryPlugin?.spec.display.name).toBe('InfluxDB Time Series Query'); |
| 114 | + }); |
| 115 | + }); |
| 116 | +}); |
0 commit comments