Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix provider-unaware integration tests for the local provider #1117

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,28 @@
"BOOSTER_ENV": "local"
}
},
{
"type": "node",
"request": "launch",
"name": "Local Provider-Unaware Functional Integration Tests",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"args": [
"--colors",
"--forbid-only",
"--config",
"${workspaceFolder}/packages/framework-integration-tests/integration/provider-unaware/functionality/.mocharc.yml",
"${workspaceFolder}/packages/framework-integration-tests/integration/provider-unaware/functionality/**/*.integration.ts"
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"protocol": "inspector",
"cwd": "${workspaceFolder}/packages/framework-integration-tests",
"runtimeArgs": ["--preserve-symlinks"],
"env": {
"TESTED_PROVIDER": "LOCAL",
"BOOSTER_ENV": "local"
}
},
{
"type": "node",
"request": "launch",
Expand Down
9 changes: 9 additions & 0 deletions packages/application-tester/keys/public.key
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA33TqqLR3eeUmDtHS89qF
3p4MP7Wfqt2Zjj3lZjLjjCGDvwr9cJNlNDiuKboODgUiT4ZdPWbOiMAfDcDzlOxA
04DDnEFGAf+kDQiNSe2ZtqC7bnIc8+KSG/qOGQIVaay4Ucr6ovDkykO5Hxn7OU7s
Jp9TP9H0JH8zMQA6YzijYH9LsupTerrY3U6zyihVEDXXOv08vBHk50BMFJbE9iwF
wnxCsU5+UZUZYw87Uu0n4LPFS9BT8tUIvAfnRXIEWCha3KbFWmdZQZlyrFw0buUE
f0YN3/Q0auBkdbDR/ES2PbgKTJdkjc/rEeM0TxvOUf7HuUNOhrtAVEN1D5uuxE1W
SwIDAQAB
-----END PUBLIC KEY-----
3 changes: 2 additions & 1 deletion packages/application-tester/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
"cross-fetch": "3.1.5",
"jsonwebtoken": "8.5.1",
"subscriptions-transport-ws": "0.9.18",
"ws": "7.4.5"
"ws": "7.4.5",
"@boostercloud/framework-types": "0.29.3"
},
"devDependencies": {
"chai": "4.2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/application-tester/src/application-tester.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GraphQLHelper } from './graphql-helper'
import { Counters, ProviderTestHelper, Queries } from './provider-test-helper'
import { Counters, ProviderTestHelper, Queries } from '@boostercloud/framework-types'
import { TokenHelper } from './token-helper'

export class ApplicationTester {
Expand Down
2 changes: 1 addition & 1 deletion packages/application-tester/src/graphql-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ApolloLink, split } from 'apollo-link'
import * as WebSocket from 'ws'
import { SubscriptionClient } from 'subscriptions-transport-ws'
import { ApolloClientOptions } from 'apollo-client/ApolloClient'
import { ProviderTestHelper } from './provider-test-helper'
import { ProviderTestHelper } from '@boostercloud/framework-types'

type AuthToken = string | (() => string)

Expand Down
1 change: 0 additions & 1 deletion packages/application-tester/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from './application-tester'
export * from './provider-test-helper'
export * from './graphql-helper'
export * from './token-helper'
3 changes: 2 additions & 1 deletion packages/application-tester/src/token-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export class TokenHelper {
constructor() {
this.privateKey = fs.readFileSync(path.join(__dirname, '..', 'keys', 'private.key'))
}

public forUser(email: string, role: string, expiresIn?: number, notBefore?: number): string {
const keyid = 'booster'
const issuer = 'booster'
Expand All @@ -29,7 +30,7 @@ export class TokenHelper {
return jwt.sign(
{
id: email,
'booster:role': role,
'booster:role': [role],
email,
},
this.privateKey,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ProviderTestHelper } from '@boostercloud/application-tester'
import { ProviderTestHelper } from '@boostercloud/framework-types'
import { AWSTestHelper } from '@boostercloud/framework-provider-aws-infrastructure'
import { AzureTestHelper } from '@boostercloud/framework-provider-azure-infrastructure'
import { LocalTestHelper } from '@boostercloud/framework-provider-local-infrastructure'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ recursive: true
reporter: 'spec'
timeout: 600000
file:
- './integration/provider-specific/local/setup.ts'
- './integration/provider-specific/local/functionality/setup.ts'
full-trace: true
bail: true
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { confirmUser, confirmUserURL, createUser, signOutURL, signUpURL } from './utils'
import { confirmUser, confirmUserURL, createUser, signOutURL, signUpURL, signInURL } from './utils'
import { expect } from 'chai'
import fetch from 'cross-fetch'
import { internet, random } from 'faker'
import { signInURL } from './utils'

// FIXME: When JWT auth is merged
xdescribe('With the auth API', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { changeCartItem, graphQLClient } from './utils'
import { random } from 'faker'
import { expect } from 'chai'
import * as DataStore from 'nedb'
import { sandboxPath } from './constants'
import util = require('util')
import { sandboxPath } from '../constants'
import * as util from 'util'
import * as path from 'path'
import { waitForIt } from '../../helper/sleep'
import { waitForIt } from '../../../helper/sleep'

describe('commands', () => {
let events: DataStore<unknown>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { changeCartItem, graphQLClient } from './utils'
import { random } from 'faker'
import { expect } from 'chai'
import * as DataStore from 'nedb'
import { sandboxPath } from './constants'
import { sandboxPath } from '../constants'
import * as path from 'path'
import { waitForIt } from '../../helper/sleep'
import { waitForIt } from '../../../helper/sleep'

describe('read-models', () => {
let readModels: DataStore<unknown>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { expect } from 'chai'
import { readPIDFor } from '../../../helper/file-helper'
import { sandboxPath } from '../constants'

before(async () => {
const pid: number = readPIDFor(sandboxPath)
expect(pid).not.to.be.undefined
})
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fetch from 'cross-fetch'
import { ApolloClient } from 'apollo-client'
import { InMemoryCache, NormalizedCacheObject } from 'apollo-cache-inmemory'
import { HttpLink } from 'apollo-link-http'
import { LOCAL_PROVIDER_HOST } from './constants'
import { LOCAL_PROVIDER_HOST } from '../constants'
import gql from 'graphql-tag'

// --- Auth helpers ---
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ before(async () => {
const sandboxPath = sandboxPathFor(sandboxName)
const pid: number = readPIDFor(sandboxPath)
console.log(`stopping local server with pid ${pid}...`)
process.kill(pid)
try {
process.kill(pid)
} catch (e) {
console.log('No server to stop. Skipping...')
}
console.log('removing sandbox project...')
removeFolders([sandboxPath])
})
8 changes: 5 additions & 3 deletions packages/framework-integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@
"subscriptions-transport-ws": "0.9.18",
"ttypescript": "1.5.13",
"ws": "7.4.5",
"yaml": "1.10.2"
"yaml": "1.10.2",
"chai": "4.2.0",
"nedb": "^1.8.0"
},
"engines": {
"node": ">=14.0.0"
Expand All @@ -76,9 +78,9 @@
"integration/k8s": "npm run integration/k8s-deploy && npm run integration/k8s-nuke",
"integration/k8s-deploy": "BOOSTER_ENV=kubernetes mocha --forbid-only --exit --config \"integration/provider-specific/kubernetes/deployment/.mocharc.yml\" \"integration/provider-specific/kubernetes/deployment/**/*.integration.ts\"",
"integration/k8s-nuke": "BOOSTER_ENV=kubernetes mocha --forbid-only --exit --config \"integration/provider-specific/kubernetes/nuke/.mocharc.yml\" \"integration/provider-specific/kubernetes/nuke/**/*.integration.ts\"",
"integration/local": "BOOSTER_ENV=local mocha --forbid-only --exit --config \"integration/provider-specific/local/.mocharc.yml\" \"integration/provider-specific/local/**/*.integration.ts\"",
"integration/local-ongoing": "npm run integration/local-start && npm run integration/local-stop",
"integration/local": "npm run integration/local-start && npm run integration/local-provider-specific && npm run integration/local-stop",
"integration/local-start": "BOOSTER_ENV=local mocha --forbid-only --exit --config \"integration/provider-specific/local/start/.mocharc.yml\" \"integration/provider-specific/local/start/*.integration.ts\"",
"integration/local-provider-specific": "BOOSTER_ENV=local mocha --forbid-only --exit --config \"integration/provider-specific/local/functionality/.mocharc.yml\" \"integration/provider-specific/local/functionality/**/*.integration.ts\"",
"integration/local-func": "TESTED_PROVIDER=LOCAL BOOSTER_ENV=local mocha --forbid-only --exit --config \"integration/provider-unaware/functionality/.mocharc.yml\" \"integration/provider-unaware/functionality/**/*.integration.ts\"",
"integration/local-end-to-end": "TESTED_PROVIDER=LOCAL BOOSTER_ENV=local mocha --forbid-only --exit --config \"integration/provider-unaware/end-to-end/.mocharc.yml\" \"integration/provider-unaware/end-to-end/**/*.integration.ts\"",
"integration/local-stop": "BOOSTER_ENV=local mocha --forbid-only --exit --config \"integration/provider-specific/local/stop/.mocharc.yml\" \"integration/provider-specific/local/stop/*.integration.ts\"",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Stack } from 'aws-sdk/clients/cloudformation'
import { CloudFormation, config } from 'aws-sdk'
import { AWSCounters } from './aws-counters'
import { AWSQueries } from './aws-queries'
import { ProviderTestHelper } from '@boostercloud/framework-types'

interface ApplicationOutputs {
graphqlURL: string
Expand All @@ -10,7 +11,7 @@ interface ApplicationOutputs {

const cloudFormation = new CloudFormation()

export class AWSTestHelper {
export class AWSTestHelper implements ProviderTestHelper {
private constructor(
readonly outputs: ApplicationOutputs,
readonly counters: AWSCounters,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import { getResourceGroup, getCosmosConnectionStrings } from '../infrastructure/
import { ResourceGroup } from '../infrastructure/types/resource-group'
import { AzureCounters } from './azure-counters'
import { AzureQueries } from './azure-queries'
import { ProviderTestHelper } from '@boostercloud/framework-types'

interface ApplicationOutputs {
graphqlURL: string
websocketURL: string
}

export class AzureTestHelper {
export class AzureTestHelper implements ProviderTestHelper {
private constructor(
readonly outputs: ApplicationOutputs,
readonly counters: AzureCounters,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ProviderTestHelper } from '@boostercloud/framework-types'
import { LocalQueries } from './local-queries'
import { LocalCounters } from './local-counters'

Expand All @@ -6,7 +7,7 @@ interface ApplicationOutputs {
websocketURL: string
}

export class LocalTestHelper {
export class LocalTestHelper implements ProviderTestHelper {
private constructor(
readonly outputs: ApplicationOutputs,
readonly counters: LocalCounters,
Expand All @@ -30,12 +31,10 @@ export class LocalTestHelper {
}

private static async graphqlURL(): Promise<string> {
const url = 'http://localhost:3000/graphql'
return url
return 'http://localhost:3000/graphql'
}

private static async websocketURL(): Promise<string> {
const url = 'SOME-URL'
return url
return 'http://localhost:3000/graphql'
}
}
1 change: 1 addition & 0 deletions packages/framework-types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ export * from './graphql-websocket-messages'
export * from './schedule'
export * from './errors/index'
export * from './rockets'
export * from './provider-test-helper'