mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-11-10 02:48:33 +00:00
test: gRPC core client init integration test
- Copied the env-variable server from Theia and made it possible to customize it for the tests. Each test has its own `data` folder. - Relaxed the primary package and library index error detection. This should make the init error detection locale independent. - Kill the daemon process subtree when stopping the daemon. Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
This commit is contained in:
@@ -1,15 +1,112 @@
|
||||
import { join } from 'path';
|
||||
import { homedir } from 'os';
|
||||
import { injectable } from '@theia/core/shared/inversify';
|
||||
import { FileUri } from '@theia/core/lib/node/file-uri';
|
||||
import {
|
||||
EnvVariable,
|
||||
EnvVariablesServer as TheiaEnvVariablesServer,
|
||||
} from '@theia/core/lib/common/env-variables/env-variables-protocol';
|
||||
import { isWindows } from '@theia/core/lib/common/os';
|
||||
import URI from '@theia/core/lib/common/uri';
|
||||
import { BackendApplicationConfigProvider } from '@theia/core/lib/node/backend-application-config-provider';
|
||||
import { EnvVariablesServerImpl as TheiaEnvVariablesServerImpl } from '@theia/core/lib/node/env-variables/env-variables-server';
|
||||
import { FileUri } from '@theia/core/lib/node/file-uri';
|
||||
import {
|
||||
inject,
|
||||
injectable,
|
||||
postConstruct,
|
||||
} from '@theia/core/shared/inversify';
|
||||
import { list as listDrives } from 'drivelist';
|
||||
import { homedir } from 'os';
|
||||
import { join } from 'path';
|
||||
|
||||
@injectable()
|
||||
export class EnvVariablesServer extends TheiaEnvVariablesServerImpl {
|
||||
protected override readonly configDirUri = Promise.resolve(
|
||||
FileUri.create(
|
||||
join(homedir(), BackendApplicationConfigProvider.get().configDirName)
|
||||
).toString()
|
||||
);
|
||||
export class ConfigDirUriProvider {
|
||||
private uri: URI | undefined;
|
||||
|
||||
configDirUri(): URI {
|
||||
if (!this.uri) {
|
||||
this.uri = FileUri.create(
|
||||
join(homedir(), BackendApplicationConfigProvider.get().configDirName)
|
||||
);
|
||||
}
|
||||
return this.uri;
|
||||
}
|
||||
}
|
||||
|
||||
// Copy-pasted from https://github.com/eclipse-theia/theia/blob/v1.31.1/packages/core/src/node/env-variables/env-variables-server.ts
|
||||
// to simplify the binding of the config directory location for tests.
|
||||
@injectable()
|
||||
export class EnvVariablesServer implements TheiaEnvVariablesServer {
|
||||
@inject(ConfigDirUriProvider)
|
||||
private readonly configDirUriProvider: ConfigDirUriProvider;
|
||||
|
||||
private readonly envs: { [key: string]: EnvVariable } = {};
|
||||
private readonly homeDirUri = FileUri.create(homedir()).toString();
|
||||
|
||||
constructor() {
|
||||
const prEnv = process.env;
|
||||
Object.keys(prEnv).forEach((key: string) => {
|
||||
let keyName = key;
|
||||
if (isWindows) {
|
||||
keyName = key.toLowerCase();
|
||||
}
|
||||
this.envs[keyName] = { name: keyName, value: prEnv[key] };
|
||||
});
|
||||
}
|
||||
|
||||
@postConstruct()
|
||||
protected init(): void {
|
||||
console.log(
|
||||
`Configuration directory URI: '${this.configDirUriProvider
|
||||
.configDirUri()
|
||||
.toString()}'`
|
||||
);
|
||||
}
|
||||
|
||||
async getExecPath(): Promise<string> {
|
||||
return process.execPath;
|
||||
}
|
||||
|
||||
async getVariables(): Promise<EnvVariable[]> {
|
||||
return Object.keys(this.envs).map((key) => this.envs[key]);
|
||||
}
|
||||
|
||||
async getValue(key: string): Promise<EnvVariable | undefined> {
|
||||
if (isWindows) {
|
||||
key = key.toLowerCase();
|
||||
}
|
||||
return this.envs[key];
|
||||
}
|
||||
|
||||
async getConfigDirUri(): Promise<string> {
|
||||
return this.configDirUriProvider.configDirUri().toString();
|
||||
}
|
||||
|
||||
async getHomeDirUri(): Promise<string> {
|
||||
return this.homeDirUri;
|
||||
}
|
||||
|
||||
async getDrives(): Promise<string[]> {
|
||||
const uris: string[] = [];
|
||||
const drives = await listDrives();
|
||||
for (const drive of drives) {
|
||||
for (const mountpoint of drive.mountpoints) {
|
||||
if (this.filterHiddenPartitions(mountpoint.path)) {
|
||||
uris.push(FileUri.create(mountpoint.path).toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
return uris;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters hidden and system partitions.
|
||||
*/
|
||||
private filterHiddenPartitions(path: string): boolean {
|
||||
// OS X: This is your sleep-image. When your Mac goes to sleep it writes the contents of its memory to the hard disk. (https://bit.ly/2R6cztl)
|
||||
if (path === '/private/var/vm') {
|
||||
return false;
|
||||
}
|
||||
// Ubuntu: This system partition is simply the boot partition created when the computers mother board runs UEFI rather than BIOS. (https://bit.ly/2N5duHr)
|
||||
if (path === '/boot/efi') {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user