Skip to content

Commit

Permalink
add testcode
Browse files Browse the repository at this point in the history
  • Loading branch information
nsano-rururu committed Nov 13, 2023
1 parent 0a107c9 commit e2143e9
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
1 change: 1 addition & 0 deletions run_tests.sh
Expand Up @@ -27,6 +27,7 @@
./node_modules/.bin/vue-cli-service test:unit tests/unit/specs/alert/ConfigYamlGoogleChat.spec.js &&
./node_modules/.bin/vue-cli-service test:unit tests/unit/specs/alert/ConfigYamlGoogleChat002.spec.js &&
./node_modules/.bin/vue-cli-service test:unit tests/unit/specs/alert/ConfigYamlJira.spec.js &&
./node_modules/.bin/vue-cli-service test:unit tests/unit/specs/alert/ConfigYamlLark.spec.js &&
./node_modules/.bin/vue-cli-service test:unit tests/unit/specs/alert/ConfigYamlLineNotify.spec.js &&
./node_modules/.bin/vue-cli-service test:unit tests/unit/specs/alert/ConfigYamlHttpPost.spec.js &&
./node_modules/.bin/vue-cli-service test:unit tests/unit/specs/alert/ConfigYamlHttpPost002.spec.js &&
Expand Down
30 changes: 30 additions & 0 deletions tests/unit/mockData/alert/ruleDataLark.js
@@ -0,0 +1,30 @@
export const ruleYaml = `__praeco_query_builder: '{"query":{"logicalOperator":"all","children":[]}}'
alert:
- lark
alert_subject: this is a test subject
alert_subject_args: []
alert_text: this is a test body
alert_text_args: []
alert_text_type: alert_text_only
doc_type: syslog
filter:
- query:
query_string:
query: '@timestamp:*'
import: BaseRule.config
index: hannibal-*
is_enabled: false
name: test123
num_events: 10000
query_key: beat.hostname
realert:
minutes: 5
timeframe:
minutes: 5
timestamp_field: '@timestamp'
timestamp_type: iso
type: frequency
use_count_query: true
use_strftime_index: false
lark_bot_id: abcdefg
`;
51 changes: 51 additions & 0 deletions tests/unit/specs/alert/ConfigYamlLark.spec.js
@@ -0,0 +1,51 @@
import { expect } from 'chai';
import store from '@/store';
import { mockAxios } from '../../setup';
import { ruleYaml } from '../../mockData/alert/ruleDataLark.js';

mockAxios.onGet('/api/rules/test123').reply(200, { yaml: ruleYaml });

describe('Lark YAML parsing', () => {
it('renders the correct yaml', async () => {
await store.dispatch('config/load', { type: 'rules', path: 'test123' });

let yaml = store.getters['config/yaml']();

let expected = `__praeco_full_path: "test123"
__praeco_query_builder: "{\\"query\\":{\\"logicalOperator\\":\\"all\\",\\"children\\":[]}}"
alert:
- "lark"
alert_subject: "this is a test subject"
alert_text: "this is a test body"
alert_text_type: "alert_text_only"
doc_type: "syslog"
filter:
- query:
query_string:
query: "@timestamp:*"
generate_kibana_discover_url: false
import: "BaseRule.config"
index: "hannibal-*"
is_enabled: false
lark_bot_id: "abcdefg"
lark_msgtype: "text"
match_enhancements: []
name: "test123"
num_events: 10000
query_key:
- "beat.hostname"
realert:
minutes: 5
terms_size: 50
timeframe:
minutes: 5
timestamp_field: "@timestamp"
timestamp_type: "iso"
type: "frequency"
use_count_query: true
use_strftime_index: false
`;

return expect(yaml).to.equal(expected);
});
});

0 comments on commit e2143e9

Please sign in to comment.