bruno/packages/bruno-lang/v2/tests/envToJson.spec.js

317 lines
5.4 KiB
JavaScript
Raw Normal View History

const parser = require('../src/envToJson');
2023-02-05 14:36:48 +01:00
describe('env parser', () => {
it('should parse empty vars', () => {
2023-02-05 14:36:48 +01:00
const input = `
vars {
}`;
const output = parser(input);
const expected = {
variables: []
2023-02-05 14:36:48 +01:00
};
expect(output).toEqual(expected);
});
it('should parse single var line', () => {
2023-02-05 14:36:48 +01:00
const input = `
vars {
url: http://localhost:3000
}`;
const output = parser(input);
const expected = {
variables: [
{
name: 'url',
value: 'http://localhost:3000',
enabled: true,
secret: false
}
]
2023-02-05 14:36:48 +01:00
};
expect(output).toEqual(expected);
});
it('should parse multiple var lines', () => {
2023-02-05 14:36:48 +01:00
const input = `
vars {
url: http://localhost:3000
port: 3000
~token: secret
}`;
const output = parser(input);
const expected = {
variables: [
{
name: 'url',
value: 'http://localhost:3000',
enabled: true,
secret: false
},
{
name: 'port',
value: '3000',
enabled: true,
secret: false
},
{
name: 'token',
value: 'secret',
enabled: false,
secret: false
}
]
2023-02-05 14:36:48 +01:00
};
expect(output).toEqual(expected);
});
it('should gracefully handle empty lines and spaces', () => {
2023-02-05 14:36:48 +01:00
const input = `
vars {
url: http://localhost:3000
port: 3000
}
`;
const output = parser(input);
const expected = {
variables: [
{
name: 'url',
value: 'http://localhost:3000',
enabled: true,
secret: false
},
{
name: 'port',
value: '3000',
enabled: true,
secret: false
}
]
2023-02-05 14:36:48 +01:00
};
expect(output).toEqual(expected);
});
it('should parse vars with empty values', () => {
const input = `
vars {
url:
phone:
api-key:
}
`;
const output = parser(input);
const expected = {
variables: [
{
name: 'url',
value: '',
enabled: true,
secret: false
},
{
name: 'phone',
value: '',
enabled: true,
secret: false
},
{
name: 'api-key',
value: '',
enabled: true,
secret: false
}
]
};
expect(output).toEqual(expected);
});
it('should parse empty secret vars', () => {
const input = `
vars {
url: http://localhost:3000
}
vars:secret [
]
`;
const output = parser(input);
const expected = {
variables: [
{
name: 'url',
value: 'http://localhost:3000',
enabled: true,
secret: false
}
]
};
expect(output).toEqual(expected);
});
it('should parse secret vars', () => {
const input = `
vars {
url: http://localhost:3000
}
vars:secret [
token
]
`;
const output = parser(input);
const expected = {
variables: [
{
name: 'url',
value: 'http://localhost:3000',
enabled: true,
secret: false
},
{
name: 'token',
value: null,
enabled: true,
secret: true
}
]
};
expect(output).toEqual(expected);
});
it('should parse multiline secret vars', () => {
const input = `
vars {
url: http://localhost:3000
}
vars:secret [
access_token,
access_secret,
~access_password
]
`;
const output = parser(input);
const expected = {
variables: [
{
name: 'url',
value: 'http://localhost:3000',
enabled: true,
secret: false
},
{
name: 'access_token',
value: null,
enabled: true,
secret: true
},
{
name: 'access_secret',
value: null,
enabled: true,
secret: true
},
{
name: 'access_password',
value: null,
enabled: false,
secret: true
}
]
};
expect(output).toEqual(expected);
});
it('should parse inline secret vars', () => {
const input = `
vars {
url: http://localhost:3000
}
vars:secret [access_key]
`;
const output = parser(input);
const expected = {
variables: [
{
name: 'url',
value: 'http://localhost:3000',
enabled: true,
secret: false
},
{
name: 'access_key',
value: null,
enabled: true,
secret: true
}
]
};
expect(output).toEqual(expected);
});
it('should parse inline multiple secret vars', () => {
const input = `
vars {
url: http://localhost:3000
}
vars:secret [access_key,access_secret, access_password ]
`;
const output = parser(input);
const expected = {
variables: [
{
name: 'url',
value: 'http://localhost:3000',
enabled: true,
secret: false
},
{
name: 'access_key',
value: null,
enabled: true,
secret: true
},
{
name: 'access_secret',
value: null,
enabled: true,
secret: true
},
{
name: 'access_password',
value: null,
enabled: true,
secret: true
}
]
};
expect(output).toEqual(expected);
});
2023-02-05 14:36:48 +01:00
});