satellite/console/wasm: add js tests

Change-Id: I8b1b0e81500836e0408e0517edb6c696698ab5f7
This commit is contained in:
Jessica Grebenschikov 2021-01-08 11:26:37 -08:00 committed by Jess G
parent 1f1d9fce58
commit b7d8dee5e9
3 changed files with 76 additions and 0 deletions

View File

@ -190,6 +190,16 @@ pipeline {
}
}
stage('wasm npm') {
steps {
dir(".build") {
sh 'cp -r ../satellite/console/wasm/tests/ .'
sh 'cd tests && cp "$(go env GOROOT)/misc/wasm/wasm_exec.js" .'
sh 'cd tests && npm install && npm run test'
}
}
}
stage('storagenode npm') {
steps {
dir("web/storagenode") {

View File

@ -0,0 +1,54 @@
// Copyright (C) 2021 Storj Labs, Inc.
// See LICENSE for copying information
require('./wasm_exec.js');
const fs = require('fs');
const path = require('path');
describe('main.wasm Tests', () => {
beforeAll(async () => {
const go = new Go();
wasmPath = __dirname;
if (process.env.WASM_PATH) {
wasmPath = process.env.WASM_PATH;
}
wasmPath = path.resolve(wasmPath, 'main.wasm');
const buffer = fs.readFileSync(wasmPath);
await WebAssembly.instantiate(buffer, go.importObject).then(results => {
go.run(results.instance);
})
})
describe('generateAccessGrant function', () => {
test('returns an error when called without arguments', async () => {
const result = generateAccessGrant();
expect(result["error"]).toContain("not enough argument")
expect(result["value"]).toBeNull()
});
test('happy path returns an access grant', async () => {
const apiKey = "13YqeGFpvtzbUp1QAfpvy2E5ZqLUFFNhEkv7153UDGDVnSmTuYYa7tKUnENGgvFXCCSFP7zNhKw6fsuQmWG5JGdQJbXVaVYFhoM2LcA"
const projectID = "b9e663e0-69e0-48e9-8eb2-4079be85e488"
const result = generateAccessGrant("a",apiKey, "supersecretpassphrase", projectID);
expect(result["error"]).toEqual("")
expect(result["value"]).toEqual("158UWUf6FHtCk8RGQn2JAXETNRnVwyoF7yEQQnuvPrLbsCPpttuAVWwzQ2YgD2bpQLpdBnctHssvQsqeju7kn7gz3LEJZSdRqyRG6rA9Da3PLGsawWMtM3NdGVqq9akyEmotsN7eMJVC1mfTsupiYXeHioTTTg11kY")
});
});
describe('setAPIKeyPermission function', () => {
test('returns an error when called without arguments', async () => {
const result = setAPIKeyPermission();
expect(result["error"]).toContain("not enough arguments")
expect(result["value"]).toBeNull()
});
test('default permissions returns an access grant', async () => {
const apiKey = "13YqeGFpvtzbUp1QAfpvy2E5ZqLUFFNhEkv7153UDGDVnSmTuYYa7tKUnENGgvFXCCSFP7zNhKw6fsuQmWG5JGdQJbXVaVYFhoM2LcA"
const projectID = "b9e663e0-69e0-48e9-8eb2-4079be85e488"
const perm = newPermission()
perm["AllowDownload"] = true
const result = setAPIKeyPermission(apiKey, [], perm);
expect(result["error"]).toEqual("")
expect(result["value"]).toEqual("19JjrwZJK1Ck5PdhRtxujGUnzbbiPYSSPZGyE8xrTbxVaJSEr9JL4vXpca3bSH2igjfeYsWeoe7rzo4QTGnwd29Pa924rtXzRjDzSxvkt4UdFd6iiCg")
});
});
});

View File

@ -0,0 +1,12 @@
{
"name": "testing-wasm",
"version": "1.0.0",
"scripts": {
"build": "GOOS=js GOARCH=wasm go build -o main.wasm storj.io/storj/satellite/console/wasm",
"pretest": "npm run build",
"test": "jest || true"
},
"devDependencies": {
"jest": "^23.5.0"
}
}