hetznercloud/test/test.ts
2024-02-17 21:55:25 +01:00

29 lines
959 B
TypeScript

import { expect, expectAsync, tap } from '@push.rocks/tapbundle';
import * as hetznercloud from '../ts/index.js';
import * as qenv from '@push.rocks/qenv';
const testQenv = new qenv.Qenv('./', './.nogit/');
let testAccount: hetznercloud.HetznerAccount;
tap.test('should create a valid hetzer account', async () => {
testAccount = new hetznercloud.HetznerAccount(await testQenv.getEnvVarOnDemand('HETZNER_API_TOKEN'));
expect(testAccount).toBeInstanceOf(hetznercloud.HetznerAccount);
});
tap.test('should be able to list all servers', async () => {
const servers = await testAccount.getServers();
expect(servers).toBeArray();
console.log(JSON.stringify(servers, null, 2));
})
tap.test('should be able to create a server', async () => {
const newServer = await testAccount.createServer({
name: 'testserver',
location: 'nbg1'
});
expect(newServer).toBeInstanceOf(hetznercloud.HetznerServer);
console.log(newServer);
})
tap.start()