init
This commit is contained in:
76
src/test/ConfigReader.test.ts
Normal file
76
src/test/ConfigReader.test.ts
Normal file
@@ -0,0 +1,76 @@
|
||||
import{test} from 'vitest'
|
||||
import { ConfigReader } from '../models/ConfigReader';
|
||||
|
||||
const cfgTemplate = `
|
||||
<engine>
|
||||
<environment name="DEFAULT">
|
||||
<parameter name = "host" value = "http://host1.xxx/api"/>
|
||||
<parameter name="MessageBrokerHosts" value="[ "smsk02ap432u:9096" ]" />
|
||||
</environment>
|
||||
<environment name="env1">
|
||||
<parameter name="port" value="60001"/>
|
||||
</environment>
|
||||
<environment name="env2">
|
||||
<parameter name="port" value="60002"/>
|
||||
<parameter name="MessageBrokerHosts" value="["smsk02ap430u:9096" , "smsk02ap433u:9096" ]" />
|
||||
</environment>
|
||||
|
||||
<template>
|
||||
{
|
||||
"Host": "@host@",
|
||||
"Port": @port@,
|
||||
|
||||
"ApiPath":"@host@:@port@/v1/data",
|
||||
|
||||
"MessageBroker":{
|
||||
"hosts":@MessageBrokerHosts@
|
||||
},
|
||||
|
||||
"basePath":"./@env_name@/in",
|
||||
|
||||
"NoParam:"@no_param@"
|
||||
}
|
||||
</template>
|
||||
</engine>
|
||||
`
|
||||
|
||||
|
||||
test("read from a file", async ({expect})=>{
|
||||
let sut = new ConfigReader();
|
||||
let file = new File([cfgTemplate],'cfg.json.xml',{type:'application/xml'});
|
||||
|
||||
// define a missing jsdom text() function,
|
||||
// that presents in the real DOM
|
||||
Object.defineProperty(file, 'text', {
|
||||
value: () => Promise.resolve(cfgTemplate),
|
||||
writable: true
|
||||
});
|
||||
|
||||
let cfg = await sut.parseFromFile(file);
|
||||
|
||||
expect(cfg).not.toBeUndefined();
|
||||
});
|
||||
|
||||
test("load environments and params", ({expect})=>{
|
||||
let sut = new ConfigReader();
|
||||
|
||||
let cfg = sut.parseFromString(cfgTemplate);
|
||||
|
||||
expect(cfg?.envs).toHaveLength(3);
|
||||
expect(cfg?.envs.map(x=>x.name))
|
||||
.toEqual(expect.arrayContaining(["DEFAULT", "env1", "env2"]));
|
||||
expect(cfg?.envs.flatMap(x=>x.params))
|
||||
.toHaveLength(5);
|
||||
});
|
||||
|
||||
test("load template", ({expect})=>{
|
||||
let sut = new ConfigReader();
|
||||
|
||||
let cfg = sut.parseFromString(cfgTemplate);
|
||||
|
||||
expect(cfg?.template).toBeDefined();
|
||||
expect(cfg?.template.content.length).toBeGreaterThan(20);
|
||||
expect(cfg?.template.Params).toHaveLength(5)
|
||||
expect(cfg?.getTemplateAsJson()).not.toBeUndefined();
|
||||
expect(cfg?.validateParams()).does.has.length(1).and.contain("no_param");
|
||||
});
|
||||
Reference in New Issue
Block a user