mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-07-08 20:06:32 +00:00
fix: omit port from upload request when not set
Previously, if the `port` was not set in IDE2, the compile request object has been created with an empty port object (`{}`). From now on, if the port is not specified, IDE2 will create a compile request with the default `null` `port` value. Closes #2089 Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
This commit is contained in:
parent
0fbd1fbe85
commit
db0049d635
@ -411,17 +411,21 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService {
|
||||
}
|
||||
}
|
||||
|
||||
private createPort(port: Port | undefined): RpcPort {
|
||||
private createPort(port: Port | undefined): RpcPort | undefined {
|
||||
if (!port) {
|
||||
return undefined;
|
||||
}
|
||||
const rpcPort = new RpcPort();
|
||||
if (port) {
|
||||
rpcPort.setAddress(port.address);
|
||||
rpcPort.setLabel(port.addressLabel);
|
||||
rpcPort.setProtocol(port.protocol);
|
||||
rpcPort.setProtocolLabel(port.protocolLabel);
|
||||
if (port.properties) {
|
||||
for (const [key, value] of Object.entries(port.properties)) {
|
||||
rpcPort.getPropertiesMap().set(key, value);
|
||||
}
|
||||
rpcPort.setAddress(port.address);
|
||||
rpcPort.setLabel(port.addressLabel);
|
||||
rpcPort.setProtocol(port.protocol);
|
||||
rpcPort.setProtocolLabel(port.protocolLabel);
|
||||
if (port.hardwareId !== undefined) {
|
||||
rpcPort.setHardwareId(port.hardwareId);
|
||||
}
|
||||
if (port.properties) {
|
||||
for (const [key, value] of Object.entries(port.properties)) {
|
||||
rpcPort.getPropertiesMap().set(key, value);
|
||||
}
|
||||
}
|
||||
return rpcPort;
|
||||
|
@ -0,0 +1,41 @@
|
||||
import { expect } from 'chai';
|
||||
import { Port } from '../../node/cli-protocol/cc/arduino/cli/commands/v1/port_pb';
|
||||
import { CoreServiceImpl } from '../../node/core-service-impl';
|
||||
|
||||
describe('core-service-impl', () => {
|
||||
describe('createPort', () => {
|
||||
it("should map the 'undefined' port object to an 'undefined' gRPC port value", () => {
|
||||
const actual = new CoreServiceImpl()['createPort'](undefined);
|
||||
expect(actual).to.be.undefined;
|
||||
});
|
||||
|
||||
it('should map a port object to the appropriate gRPC port object', () => {
|
||||
const properties = {
|
||||
alma: 'false',
|
||||
korte: '36',
|
||||
};
|
||||
const port = {
|
||||
address: 'address',
|
||||
addressLabel: 'address label',
|
||||
hardwareId: '1730323',
|
||||
protocol: 'serial',
|
||||
protocolLabel: 'serial port',
|
||||
properties,
|
||||
} as const;
|
||||
const actual = new CoreServiceImpl()['createPort'](port);
|
||||
expect(actual).to.be.not.undefined;
|
||||
const expected = new Port()
|
||||
.setAddress(port.address)
|
||||
.setHardwareId(port.hardwareId)
|
||||
.setLabel(port.addressLabel)
|
||||
.setProtocol(port.protocol)
|
||||
.setProtocolLabel(port.protocolLabel);
|
||||
Object.entries(properties).forEach(([key, value]) =>
|
||||
expected.getPropertiesMap().set(key, value)
|
||||
);
|
||||
expect((<Port>actual).toObject(false)).to.be.deep.equal(
|
||||
expected.toObject(false)
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user