gns3-web-ui/src/app/services/vmware.service.spec.ts
2019-02-11 05:46:37 -08:00

110 lines
3.8 KiB
TypeScript

import { TestBed, inject } from '@angular/core/testing';
import { HttpClient } from '@angular/common/http';
import { HttpTestingController, HttpClientTestingModule } from '@angular/common/http/testing';
import { HttpServer } from './http-server.service';
import { Server } from '../models/server';
import { getTestServer } from './testing';
import { AppTestingModule } from '../testing/app-testing/app-testing.module';
import { VmwareService } from './vmware.service';
import { VmwareTemplate } from '../models/templates/vmware-template';
describe('VmwareService', () => {
let httpClient: HttpClient;
let httpTestingController: HttpTestingController;
let httpServer: HttpServer;
let server: Server;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpClientTestingModule, AppTestingModule],
providers: [HttpServer, VmwareService]
});
httpClient = TestBed.get(HttpClient);
httpTestingController = TestBed.get(HttpTestingController);
httpServer = TestBed.get(HttpServer);
server = getTestServer();
});
afterEach(() => {
httpTestingController.verify();
});
it('should be created', inject([VmwareService], (service: VmwareService) => {
expect(service).toBeTruthy();
}));
it('should update vmware template', inject([VmwareService], (service: VmwareService) => {
const template: VmwareTemplate = {
adapter_type: 'e1000',
adapters: 1,
builtin: false,
category: 'guest',
compute_id: 'local',
console_auto_start: false,
console_type: 'none',
custom_adapters: [],
default_name_format: '{name}-{0}',
first_port_name: '',
headless: false,
linked_clone: false,
name: '',
on_close: 'power-off',
port_name_format: 'Ethernet{0}',
port_segment_size: 0,
symbol: ':/symbols/vmware_guest.svg',
template_id: '1',
template_type: 'vmware',
usage: '',
use_any_adapter: false,
vmx_path: ''
};
service.saveTemplate(server, template).subscribe();
const req = httpTestingController.expectOne('http://127.0.0.1:3080/v2/templates/1');
expect(req.request.method).toEqual('PUT');
expect(req.request.body).toEqual(template);
}));
it('should add vmware template', inject([VmwareService], (service: VmwareService) => {
const template: VmwareTemplate = {
adapter_type: 'e1000',
adapters: 1,
builtin: false,
category: 'guest',
compute_id: 'local',
console_auto_start: false,
console_type: 'none',
custom_adapters: [],
default_name_format: '{name}-{0}',
first_port_name: '',
headless: false,
linked_clone: false,
name: '',
on_close: 'power-off',
port_name_format: 'Ethernet{0}',
port_segment_size: 0,
symbol: ':/symbols/vmware_guest.svg',
template_id: '1',
template_type: 'vmware',
usage: '',
use_any_adapter: false,
vmx_path: ''
};
service.addTemplate(server, template).subscribe();
const req = httpTestingController.expectOne('http://127.0.0.1:3080/v2/templates');
expect(req.request.method).toEqual('POST');
expect(req.request.body).toEqual(template);
}));
it('should get available virtual machines', inject([VmwareService], (service: VmwareService) => {
service.getVirtualMachines(server).subscribe();
const req = httpTestingController.expectOne('http://127.0.0.1:3080/v2/compute/vmware/vms');
expect(req.request.method).toEqual('GET');
}));
});