blob: aab37c7220febabea4f6e89d361845d7b5d5fbe1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
import { XmlParser } from './XmlParser';
import { ParserFactory } from './ParserFactory';
import { FileExtension } from '../TemplateType';
import { JinjaXMLParser } from './JinjaXML';
fdescribe('ImportsTabComponent', () => {
const parserFactory = new ParserFactory();
beforeEach(() => {
});
it('Test xml Parser', () => {
const fileContent = `<vlb-business-vnf-onap-plugin xmlns="urn:opendaylight:params:xml:ns:yang:vlb-business-vnf-onap-plugin">
<vdns-instances>
<vdns-instance>
<ip-addr>$vdns_int_private_ip_0</ip-addr>
<oam-ip-addr>$vdns_onap_private_ip_0</oam-ip-addr>
<enabled>false</enabled>
<tag>dddd</tag>
</vdns-instance>
</vdns-instances>
</vlb-business-vnf-onap-plugin>`;
const parser = parserFactory.getParser(fileContent, FileExtension.XML);
const res = parser.getVariables(fileContent);
console.log(res);
expect(res.length).toEqual(2);
expect(res[0]).toEqual('vdns_int_private_ip_0');
expect(res[1]).toEqual('vdns_onap_private_ip_0');
});
it('Test J2 XML Parser', () => {
const fileContent = `<?xml version="1.0" encoding="UTF-8"?>
<configuration xmlns:junos="http://xml.juniper.net/junos/17.4R1/junos">
<system xmlns="http://yang.juniper.net/junos-qfx/conf/system">
<host-name operation="delete" />
<host-name operation="create">[hostname]</host-name>
</system>
</configuration>`;
const parser = parserFactory.getParser(fileContent, FileExtension.Jinja);
const res = parser.getVariables(fileContent);
console.log(typeof (res));
console.log(res);
expect(res.length).toEqual(1);
expect(res[0]).toEqual('hostname');
});
it('Test J2 YML Parser', () => {
const fileContent = `apiVersion: v1
kind: Service
metadata:
name: {{ .Values.vpg_name_0 }}-ssh
labels:
vnf-name: {{ .Values.vnf_name }}
vf-module-name: {{ .Values.vpg_name_0 }}
release: {{ .Release.Name }}
chart: {{ .Chart.Name }}
spec:
type: NodePort
ports:
port: 22
nodePort: \${vpg-management-port}
selector:
vf-module-name: {{ .Values.vpg_name_0 }}
release: {{ .Release.Name }}
chart: {{ .Chart.Name }}`;
const parser = parserFactory.getParser(fileContent, FileExtension.Jinja);
const res = parser.getVariables(fileContent);
console.log(res);
expect(res.length).toEqual(2);
expect(res[0]).toEqual('vpg_name_0');
expect(res[1]).toEqual('vnf_name');
});
it('Test ASCII Parser', () => {
const fileContent = `
config system interface
edit "internal"
set vdom "root"
set ip $(subnet1_fgt_ip) 255.255.255.0 #1
set allowaccess ping https ssh http fgfm capwap
set type hard-switch
set stp enable
set role lan
next
end
config system dhcp server
edit 1
set dns-service default
set default-gateway $(subnet1_fgt_ip) #2
set netmask 255.255.255.0
set interface "internal"
config ip-range
edit 1
set start-ip $(subnet1_fgt_ip)4,150 #3
set end-ip $(subnet1_fgt_ip)4,200 #4
next
end
next
end
Options
`;
const parser = parserFactory.getParser(fileContent, FileExtension.Jinja);
const res = parser.getVariables(fileContent);
console.log(res);
expect(res.length).toEqual(1);
expect(res[0]).toEqual('subnet1_fgt_ip');
});
});
|