Skip to content

Commit 9fa71a1

Browse files
vivien-applepull[bot]
authored andcommitted
[YAML] Get simulated clusters related code to merge clusters/commands/attributes for real clusters and simulated clusters to be into a dedicated file (#12288)
1 parent 57c2274 commit 9fa71a1

File tree

2 files changed

+62
-44
lines changed

2 files changed

+62
-44
lines changed

src/app/zap-templates/common/ClusterTestGeneration.js

+2-44
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,8 @@ const path = require('path');
2626
// Import helpers from zap core
2727
const templateUtil = require(zapPath + 'dist/src-electron/generator/template-util.js')
2828

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

3432
const kClusterName = 'cluster';
3533
const kEndpointName = 'endpoint';
@@ -341,37 +339,6 @@ function printErrorAndExit(context, msg)
341339
process.exit(1);
342340
}
343341

344-
function getClusters()
345-
{
346-
// Create a new array to merge the configured clusters list and test
347-
// simulated clusters.
348-
return Clusters.getClusters().then(clusters => clusters.concat(DelayCommands, LogCommands));
349-
}
350-
351-
function getCommands(clusterName)
352-
{
353-
switch (clusterName) {
354-
case DelayCommands.name:
355-
return Promise.resolve(DelayCommands.commands);
356-
case LogCommands.name:
357-
return Promise.resolve(LogCommands.commands);
358-
default:
359-
return Clusters.getClientCommands(clusterName);
360-
}
361-
}
362-
363-
function getAttributes(clusterName)
364-
{
365-
switch (clusterName) {
366-
case DelayCommands.name:
367-
return Promise.resolve(DelayCommands.attributes);
368-
case LogCommands.name:
369-
return Promise.resolve(LogCommands.attributes);
370-
default:
371-
return Clusters.getServerAttributes(clusterName);
372-
}
373-
}
374-
375342
function assertCommandOrAttribute(context)
376343
{
377344
const clusterName = context.cluster;
@@ -469,15 +436,6 @@ function chip_tests_items(options)
469436
return templateUtil.collectBlocks(this.tests, options, this);
470437
}
471438

472-
function isTestOnlyCluster(name)
473-
{
474-
const testOnlyClusters = [
475-
DelayCommands.name,
476-
LogCommands.name,
477-
];
478-
return testOnlyClusters.includes(name);
479-
}
480-
481439
// test_cluster_command_value and test_cluster_value-equals are recursive partials using #each. At some point the |global|
482440
// context is lost and it fails. Make sure to attach the global context as a property of the | value |
483441
// that is evaluated.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
*
3+
* Copyright (c) 2021 Project CHIP Authors
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
const { Clusters } = require('../ClustersHelper.js');
19+
const { DelayCommands } = require('./TestDelayCommands.js');
20+
const { LogCommands } = require('./TestLogCommands.js');
21+
22+
const SimulatedClusters = [
23+
DelayCommands,
24+
LogCommands,
25+
];
26+
27+
function getSimulatedCluster(clusterName)
28+
{
29+
return SimulatedClusters.find(cluster => cluster.name == clusterName);
30+
}
31+
32+
function getClusters()
33+
{
34+
return Clusters.getClusters().then(clusters => clusters.concat(SimulatedClusters).flat(1));
35+
}
36+
37+
function getCommands(clusterName)
38+
{
39+
const cluster = getSimulatedCluster(clusterName);
40+
return cluster ? Promise.resolve(cluster.commands) : Clusters.getClientCommands(clusterName);
41+
}
42+
43+
function getAttributes(clusterName)
44+
{
45+
const cluster = getSimulatedCluster(clusterName);
46+
return cluster ? Promise.resolve(cluster.attributes) : Clusters.getServerAttributes(clusterName);
47+
}
48+
49+
function isTestOnlyCluster(clusterName)
50+
{
51+
return !!getSimulatedCluster(clusterName);
52+
}
53+
54+
//
55+
// Module exports
56+
//
57+
exports.getClusters = getClusters;
58+
exports.getCommands = getCommands;
59+
exports.getAttributes = getAttributes;
60+
exports.isTestOnlyCluster = isTestOnlyCluster;

0 commit comments

Comments
 (0)