Skip to content
Open
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
24 changes: 14 additions & 10 deletions core/lib/common/suite.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const State = require('./state');
const Teardown = require('./teardown');
const Test = require('./test');
const utils = require('./utils');
const contrato = require('@balena/contrato');

function cleanObject(object) {
if (!isObject(object)) {
Expand Down Expand Up @@ -136,19 +137,22 @@ class Suite {

// Recursive DFS
const treeExpander = async ([
{ interactive, os, skip, deviceType, title, run, tests },
{ interactive, skip, title, run, tests, contract },
testNode,
]) => {
// Check our contracts
if (
skip ||
(interactive && !this.options.interactiveTests) ||
(deviceType != null && !ajv.compile(deviceType)(this.deviceType)) ||
(os != null &&
this.context.get().os != null &&
!ajv.compile(os)(this.context.get().os.contract))
) {
return;
if(contract != null){
const suiteContract = new contrato.Contract({})
const os = (this.context.get().os != null) ? this.context.get().os.contract : {}
suiteContract.addChildren([
new contrato.Contract(this.deviceType),
new contrato.Contract(os)
])
const testContract = new contrato.Contract(contract);
let result = suiteContract.satisfiesChildContract(testContract)
if (!result) {
return;
}
}

const test = new Test(title, this);
Expand Down
18 changes: 13 additions & 5 deletions core/lib/components/os/balenaos.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ const { fs } = require('mz');
const { join } = require('path');
const pipeline = Bluebird.promisify(require('stream').pipeline);
const zlib = require('zlib');
const contrato = require('@balena/contrato');
const { contains } = require('lodash/fp');

// TODO: This function should be implemented using Reconfix
const injectBalenaConfiguration = (image, configuration) => {
Expand Down Expand Up @@ -147,12 +149,16 @@ module.exports = class BalenaOS {
};
this.configJson = options.configJson || {};
this.contract = {
network: mapValues(this.network, value => {
return typeof value === 'boolean' ? value : true;
}),
type: 'test.os',
data: {
network: mapValues(this.network, value => {
return typeof value === 'boolean' ? value : true;
}),
}
};
this.logger = logger;
this.releaseInfo = { version: null, variant: null };
console.log(this.contract)
}

/**
Expand Down Expand Up @@ -223,10 +229,12 @@ module.exports = class BalenaOS {

await readVersion(/VERSION="(.*)"/g, 'version');
await readVersion(/VARIANT="(.*)"/g, 'variant');
assignIn(this.contract, {
/*assignIn(this.contract, {
version: this.releaseInfo.version,
variant: this.releaseInfo.variant,
});
});*/
this.contract.data['version'] = this.releaseInfo.version;
this.contract.data['variant'] = this.releaseInfo.variant;
}

addCloudConfig(configJson) {
Expand Down
Loading