Skip to content

Commit

Permalink
feat: add generated types and more machine apis
Browse files Browse the repository at this point in the history
  • Loading branch information
sweatybridge committed Sep 7, 2023
1 parent f761aa7 commit b02a901
Show file tree
Hide file tree
Showing 15 changed files with 1,198 additions and 405 deletions.
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,17 @@ async function deployApp() {
- `fly.Machine.updateMachine()`
- `fly.Machine.startMachine()`
- `fly.Machine.stopMachine()`
- `fly.Machine.restartMachine()`
- `fly.Machine.deleteMachine()`
- `fly.Machine.restartMachine()`
- `fly.Machine.signalMachine()`
- `fly.Machine.waitMachine()`
- `fly.Machine.cordonMachine()`
- `fly.Machine.uncordonMachine()`
- `fly.Machine.listEvents()`
- `fly.Machine.listVersions()`
- `fly.Machine.listProcesses()`
- `fly.Machine.getLease()`
- `fly.Machine.acquireLease()`

**Networks**

Expand All @@ -61,6 +70,15 @@ async function deployApp() {
- `fly.Volume.createVolume()`
- `fly.Volume.deleteVolume()`
- `fly.Volume.extendVolume()`
- `fly.Volume.listSnapshots()`

**TODO**

- [ ] `fly.Machine.execMachine()`
- [ ] `fly.Machine.releaseLease()`
- [ ] `fly.Machine.getMetadata()`
- [ ] `fly.Machine.updateMetadata()`
- [ ] `fly.Machine.deleteMetadata()`

## License

Expand Down
110 changes: 44 additions & 66 deletions __tests__/app.test.ts
Original file line number Diff line number Diff line change
@@ -1,83 +1,61 @@
import nock from 'nock'
import { describe, it } from '@jest/globals'
import { FLY_API_GRAPHQL } from '../src/client'
import { FLY_API_HOSTNAME } from '../src/client'
import { createClient } from '../src/main'
import { AppResponse, AppStatus } from '../src/lib/app'

const fly = createClient('test-token')
const fly = createClient(process.env.FLY_API_TOKEN || 'test-token')

describe('app', () => {
const organizationId = 'personal'
const app: AppResponse = {
name: 'fly-app',
status: AppStatus.deployed,
organization: {
name: 'fly-org',
slug: 'personal',
},
}

it('creates app', async () => {
nock(FLY_API_GRAPHQL)
.post('/graphql')
it('lists apps', async () => {
const org_slug = app.organization.slug
nock(FLY_API_HOSTNAME)
.get('/v1/apps')
.query({ org_slug })
.reply(200, {
data: {
createApp: {
app: {
id: 'ctwntjgykzxhfncfwrfo',
name: 'ctwntjgykzxhfncfwrfo',
organization: { slug: 'supabase-dev' },
config: {
definition: {
kill_timeout: 5,
kill_signal: 'SIGINT',
processes: [],
experimental: { auto_rollback: true },
services: [
{
processes: ['app'],
protocol: 'tcp',
internal_port: 8080,
concurrency: {
soft_limit: 20,
hard_limit: 25,
type: 'connections',
},
ports: [
{ port: 80, handlers: ['http'], force_https: true },
{ port: 443, handlers: ['tls', 'http'] },
],
tcp_checks: [
{
interval: '15s',
timeout: '2s',
grace_period: '1s',
restart_limit: 0,
},
],
http_checks: [],
script_checks: [],
},
],
env: {},
},
},
regions: [{ name: 'Hong Kong, Hong Kong', code: 'hkg' }],
},
total_apps: 1,
apps: [
{
name: app.name,
machine_count: 1,
network: 'default',
},
},
],
})
const data = await fly.App.createApp({
name: 'ctwntjgykzxhfncfwrfo',
organizationId,
})
const data = await fly.App.listApps(org_slug)
console.dir(data, { depth: 10 })
})

it('get app', async () => {
const app_name = app.name
nock(FLY_API_HOSTNAME).get(`/v1/apps/${app_name}`).reply(200, app)
const data = await fly.App.getApp(app_name)
console.dir(data, { depth: 10 })
})

it('creates app', async () => {
const body = {
org_slug: app.organization.slug,
app_name: app.name,
}
nock(FLY_API_HOSTNAME).post('/v1/apps', body).reply(201)
const data = await fly.App.createApp(body)
console.dir(data, { depth: 10 })
})

it('deletes app', async () => {
nock(FLY_API_GRAPHQL)
.post('/graphql')
.reply(200, {
data: {
deleteApp: {
organization: {
id: organizationId,
},
},
},
})
const data = await fly.App.deleteApp('ctwntjgykzxhfncfwrfo')
const app_name = app.name
nock(FLY_API_HOSTNAME).delete(`/v1/apps/${app_name}`).reply(202)
const data = await fly.App.deleteApp(app_name)
console.dir(data, { depth: 10 })
})
})
Loading

0 comments on commit b02a901

Please sign in to comment.