Skip to content

Commit

Permalink
#139: Convert extensionForTesting to JavaScript to speedup tests (#140
Browse files Browse the repository at this point in the history
)
  • Loading branch information
kaklakariada authored Sep 12, 2023
1 parent a8daa86 commit a9701f9
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 51 deletions.
4 changes: 4 additions & 0 deletions doc/changes/changes_0.5.2.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ This release updates the upload process for the extension registry to verify tha

* #129: Added verification for extension URLs before uploading to registry

## Refactoring

* #139: Converted `extensionForTesting` to JavaScript to speedup tests

## Dependency Updates

### Extension Integration Tests Library
Expand Down
2 changes: 1 addition & 1 deletion pkg/extensionController/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ var errorTests = []errorTest{
{testName: "generic", throwCommand: "throw Error(`mock error from js`);", expectedStatus: -1},
{testName: "internal server error", throwCommand: "throw new InternalServerError(`mock error from js`);", expectedStatus: -1},
{testName: "bad request", throwCommand: "throw new BadRequestError(`mock error from js`);", expectedStatus: 400},
{testName: "null pointer", throwCommand: `(<any>{}).a.b; throw Error("mock");`, expectedStatus: -1, expectedMessage: "TypeError: Cannot read property 'b' of undefined"},
{testName: "null pointer", throwCommand: `({}).a.b; throw Error("mock");`, expectedStatus: -1, expectedMessage: "TypeError: Cannot read property 'b' of undefined"},
}

func (suite *ControllerUTestSuite) TestGetAllInstallationsFails() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,43 +1,41 @@
import {
BadRequestError, Context, ExaMetadata, ExasolExtension,
Installation,
Instance, InternalServerError, Parameter, ParameterValues,
UpgradeResult,
BadRequestError,
InternalServerError,
registerExtension
} from "@exasol/extension-manager-interface";

function createExtension(): ExasolExtension {
function createExtension() {
return {
name: "MyDemoExtension",
description: "An extension for testing.",
category: "Demo category",
installableVersions: [{ name: "0.1.0", latest: true, deprecated: false }],
bucketFsUploads: $UPLOADS$,
install(context: Context, version: string) {
install(context, version) {
$INSTALL_EXTENSION$
},
addInstance(context: Context, version: string, params: ParameterValues): Instance {
addInstance(context, version, params) {
$ADD_INSTANCE$
},
findInstallations(context: Context, metadata: ExaMetadata): Installation[] {
findInstallations(context, metadata) {
$FIND_INSTALLATIONS$
},
findInstances(context: Context, version: string): Instance[] {
findInstances(context, version) {
$FIND_INSTANCES$
},
uninstall(context: Context, version: string): void {
uninstall(context, version) {
$UNINSTALL_EXTENSION$
},
upgrade(context: Context): UpgradeResult {
upgrade(context) {
$UPGRADE_EXTENSION$
},
deleteInstance(context: Context, extensionVersion: string, instanceId: string): void {
deleteInstance(context, extensionVersion, instanceId) {
$DELETE_INSTANCE$
},
getInstanceParameters(context: Context, version: string): Parameter[] {
getInstanceParameters(context, version) {
$GET_INSTANCE_PARAMETER_DEFINITIONS$
},
readInstanceParameterValues(context: Context, extensionVersion: string, instanceId: string): ParameterValues {
readInstanceParameterValues(context, extensionVersion, instanceId) {
return undefined;
}
}
Expand Down
21 changes: 10 additions & 11 deletions pkg/integrationTesting/extensionForTesting/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
{
"scripts": {
"build": "tsc --build && esbuild dist/extensionForTesting.js --bundle --outfile=dist.js --target=es6",
"clean": "tsc --build --clean"
},
"dependencies": {
"@exasol/extension-manager-interface": "0.3.0"
},
"devDependencies": {
"esbuild": "^0.18.16",
"typescript": "^5.1.6"
}
"scripts": {
"build": "esbuild extensionForTesting.js --bundle --outfile=dist.js --target=es6",
"clean": "rm -rf dist/"
},
"dependencies": {
"@exasol/extension-manager-interface": "0.3.0"
},
"devDependencies": {
"esbuild": "^0.18.16"
}
}
16 changes: 0 additions & 16 deletions pkg/integrationTesting/extensionForTesting/tsconfig.json

This file was deleted.

11 changes: 2 additions & 9 deletions pkg/integrationTesting/testExtensionBuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,13 @@ func (builder *TestExtensionBuilder) WithBucketFsUpload(upload BucketFsUploadPar
return builder
}

//go:embed extensionForTesting/tsconfig.json
var tscConfig []byte

func (builder TestExtensionBuilder) Build() *BuiltExtension {
workDir := builder.createWorkDir()
err := os.WriteFile(path.Join(workDir, "package.json"), []byte(builder.createPackageJsonContent()), 0600)
if err != nil {
panic(err)
}
err = os.WriteFile(path.Join(workDir, "extensionForTesting.ts"), []byte(builder.createExtensionTsContent()), 0600)
if err != nil {
panic(err)
}
err = os.WriteFile(path.Join(workDir, "tsconfig.json"), tscConfig, 0600)
err = os.WriteFile(path.Join(workDir, "extensionForTesting.js"), []byte(builder.createExtensionTsContent()), 0600)
if err != nil {
panic(err)
}
Expand All @@ -146,7 +139,7 @@ func (builder TestExtensionBuilder) createPackageJsonContent() string {
return strings.Replace(packageJsonTemplate, "$EXTENSION_API_VERSION$", builder.extensionApiVersion, 1)
}

//go:embed extensionForTesting/extensionForTestingTemplate.ts
//go:embed extensionForTesting/extensionForTestingTemplate.js
var extensionTemplate string

func (builder TestExtensionBuilder) createExtensionTsContent() string {
Expand Down

0 comments on commit a9701f9

Please sign in to comment.