Skip to content

Commit

Permalink
[YAML] Get simulated clusters related code to merge clusters/commands…
Browse files Browse the repository at this point in the history
…/attributes for real clusters and simulated clusters to be into a dedicated file (#12288)
  • Loading branch information
vivien-apple authored and pull[bot] committed Jul 2, 2022
1 parent ea09de0 commit 4080976
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 44 deletions.
46 changes: 2 additions & 44 deletions src/app/zap-templates/common/ClusterTestGeneration.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ const path = require('path');
// Import helpers from zap core
const templateUtil = require(zapPath + 'dist/src-electron/generator/template-util.js')

const { DelayCommands } = require('./simulated-clusters/TestDelayCommands.js');
const { LogCommands } = require('./simulated-clusters/TestLogCommands.js');
const { Clusters, asBlocks, asPromise } = require('./ClustersHelper.js');
const { asUpperCamelCase } = require(basePath + 'src/app/zap-templates/templates/app/helper.js');
const { getClusters, getCommands, getAttributes, isTestOnlyCluster } = require('./simulated-clusters/SimulatedClusters.js');
const { asBlocks } = require('./ClustersHelper.js');

const kClusterName = 'cluster';
const kEndpointName = 'endpoint';
Expand Down Expand Up @@ -341,37 +339,6 @@ function printErrorAndExit(context, msg)
process.exit(1);
}

function getClusters()
{
// Create a new array to merge the configured clusters list and test
// simulated clusters.
return Clusters.getClusters().then(clusters => clusters.concat(DelayCommands, LogCommands));
}

function getCommands(clusterName)
{
switch (clusterName) {
case DelayCommands.name:
return Promise.resolve(DelayCommands.commands);
case LogCommands.name:
return Promise.resolve(LogCommands.commands);
default:
return Clusters.getClientCommands(clusterName);
}
}

function getAttributes(clusterName)
{
switch (clusterName) {
case DelayCommands.name:
return Promise.resolve(DelayCommands.attributes);
case LogCommands.name:
return Promise.resolve(LogCommands.attributes);
default:
return Clusters.getServerAttributes(clusterName);
}
}

function assertCommandOrAttribute(context)
{
const clusterName = context.cluster;
Expand Down Expand Up @@ -469,15 +436,6 @@ function chip_tests_items(options)
return templateUtil.collectBlocks(this.tests, options, this);
}

function isTestOnlyCluster(name)
{
const testOnlyClusters = [
DelayCommands.name,
LogCommands.name,
];
return testOnlyClusters.includes(name);
}

// test_cluster_command_value and test_cluster_value-equals are recursive partials using #each. At some point the |global|
// context is lost and it fails. Make sure to attach the global context as a property of the | value |
// that is evaluated.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
*
* Copyright (c) 2021 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

const { Clusters } = require('../ClustersHelper.js');
const { DelayCommands } = require('./TestDelayCommands.js');
const { LogCommands } = require('./TestLogCommands.js');

const SimulatedClusters = [
DelayCommands,
LogCommands,
];

function getSimulatedCluster(clusterName)
{
return SimulatedClusters.find(cluster => cluster.name == clusterName);
}

function getClusters()
{
return Clusters.getClusters().then(clusters => clusters.concat(SimulatedClusters).flat(1));
}

function getCommands(clusterName)
{
const cluster = getSimulatedCluster(clusterName);
return cluster ? Promise.resolve(cluster.commands) : Clusters.getClientCommands(clusterName);
}

function getAttributes(clusterName)
{
const cluster = getSimulatedCluster(clusterName);
return cluster ? Promise.resolve(cluster.attributes) : Clusters.getServerAttributes(clusterName);
}

function isTestOnlyCluster(clusterName)
{
return !!getSimulatedCluster(clusterName);
}

//
// Module exports
//
exports.getClusters = getClusters;
exports.getCommands = getCommands;
exports.getAttributes = getAttributes;
exports.isTestOnlyCluster = isTestOnlyCluster;

0 comments on commit 4080976

Please sign in to comment.