Skip to content

Commit 4c0df81

Browse files
skywing918Kyle Zhang
andauthored
[TSV-Go] Adjust TSV rules for GO DPG as optional check (Azure#39464)
* set go dpg as optional rules * Add test cases for optional rules with emitter configuration in Tspconfig validation * Add GoDpEmitterOutputDirMatchPatternSubRule to parameter validation * Add Go management module match pattern subrules and corresponding test cases * Refactor Go module match pattern subrules to distinguish between data plane and management plane rules * Go Module case move to optionalTestCases * refactor: reorganize Go subrules for clarity and maintainability --------- Co-authored-by: Kyle Zhang <[email protected]>
1 parent 56f8769 commit 4c0df81

File tree

2 files changed

+89
-17
lines changed

2 files changed

+89
-17
lines changed

eng/tools/typespec-validation/src/rules/sdk-tspconfig-validation.ts

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,18 @@ export class TspConfigGoContainingModuleMatchPatternSubRule extends TspconfigEmi
514514
}
515515

516516
// ----- Go data plane sub rules -----
517+
export class TspConfigGoDpModuleMatchPatternSubRule extends TspConfigGoModuleMatchPatternSubRule {
518+
protected skip(_: any, folder: string) {
519+
return skipForManagementPlane(folder);
520+
}
521+
}
522+
523+
export class TspConfigGoDpContainingModuleMatchPatternSubRule extends TspConfigGoContainingModuleMatchPatternSubRule {
524+
protected skip(_: any, folder: string) {
525+
return skipForManagementPlane(folder);
526+
}
527+
}
528+
517529
export class TspConfigGoDpServiceDirMatchPatternSubRule extends TspconfigEmitterOptionsSubRuleBase {
518530
constructor() {
519531
super("@azure-tools/typespec-go", "service-dir", new RegExp(/^(\{output-dir\}\/)?sdk\/.*$/));
@@ -538,6 +550,18 @@ export class TspConfigGoDpEmitterOutputDirMatchPatternSubRule extends TspconfigE
538550
}
539551

540552
// ----- Go Mgmt plane sub rules -----
553+
export class TspConfigGoMgmtModuleMatchPatternSubRule extends TspConfigGoModuleMatchPatternSubRule {
554+
protected skip(_: any, folder: string) {
555+
return skipForDataPlane(folder);
556+
}
557+
}
558+
559+
export class TspConfigGoMgmtContainingModuleMatchPatternSubRule extends TspConfigGoContainingModuleMatchPatternSubRule {
560+
protected skip(_: any, folder: string) {
561+
return skipForDataPlane(folder);
562+
}
563+
}
564+
541565
export class TspConfigGoMgmtServiceDirMatchPatternSubRule extends TspconfigEmitterOptionsSubRuleBase {
542566
constructor() {
543567
super(
@@ -707,10 +731,8 @@ export const requiredRules = [
707731
new TspConfigGoMgmtGenerateFakesTrueSubRule(),
708732
new TspConfigGoMgmtHeadAsBooleanTrueSubRule(),
709733
new TspConfigGoMgmtInjectSpansTrueSubRule(),
710-
new TspConfigGoDpServiceDirMatchPatternSubRule(),
711-
new TspConfigGoDpEmitterOutputDirMatchPatternSubRule(),
712-
new TspConfigGoModuleMatchPatternSubRule(),
713-
new TspConfigGoContainingModuleMatchPatternSubRule(),
734+
new TspConfigGoMgmtModuleMatchPatternSubRule(),
735+
new TspConfigGoMgmtContainingModuleMatchPatternSubRule(),
714736
new TspConfigPythonMgmtEmitterOutputDirSubRule(),
715737
new TspConfigPythonMgmtNamespaceSubRule(),
716738
new TspConfigPythonDpEmitterOutputDirSubRule(),
@@ -726,7 +748,12 @@ export const requiredRules = [
726748
* the rule is skipped and does not affect the validation result. When the emitter is configured,
727749
* validation failures will affect the overall validation result.
728750
*/
729-
export const optionalRules: TspconfigEmitterOptionsSubRuleBase[] = [];
751+
export const optionalRules: TspconfigEmitterOptionsSubRuleBase[] = [
752+
new TspConfigGoDpServiceDirMatchPatternSubRule(),
753+
new TspConfigGoDpEmitterOutputDirMatchPatternSubRule(),
754+
new TspConfigGoDpModuleMatchPatternSubRule(),
755+
new TspConfigGoDpContainingModuleMatchPatternSubRule(),
756+
];
730757

731758
export class SdkTspConfigValidationRule implements Rule {
732759
private requiredRules: TspconfigSubRuleBase[] = [];

eng/tools/typespec-validation/test/sdk-tspconfig-validation.test.ts

Lines changed: 57 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,18 @@ import { stringify } from "yaml";
1010
import {
1111
SdkTspConfigValidationRule,
1212
TspConfigCommonAzServiceDirMatchPatternSubRule,
13-
TspConfigGoContainingModuleMatchPatternSubRule,
13+
TspConfigGoDpContainingModuleMatchPatternSubRule,
1414
TspConfigGoDpEmitterOutputDirMatchPatternSubRule,
15+
TspConfigGoDpModuleMatchPatternSubRule,
1516
TspConfigGoDpServiceDirMatchPatternSubRule,
17+
TspConfigGoMgmtContainingModuleMatchPatternSubRule,
1618
TspConfigGoMgmtEmitterOutputDirMatchPatternSubRule,
1719
TspConfigGoMgmtGenerateFakesTrueSubRule,
1820
TspConfigGoMgmtGenerateSamplesTrueSubRule,
1921
TspConfigGoMgmtHeadAsBooleanTrueSubRule,
2022
TspConfigGoMgmtInjectSpansTrueSubRule,
23+
TspConfigGoMgmtModuleMatchPatternSubRule,
2124
TspConfigGoMgmtServiceDirMatchPatternSubRule,
22-
TspConfigGoModuleMatchPatternSubRule,
2325
TspConfigJavaAzEmitterOutputDirMatchPatternSubRule,
2426
TspConfigJavaMgmtEmitterOutputDirMatchPatternSubRule,
2527
TspConfigJavaMgmtNamespaceFormatSubRule,
@@ -292,7 +294,7 @@ const goManagementModuleTestCases = createEmitterOptionTestCases(
292294
"module",
293295
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute",
294296
"github.com/Azure/azure-sdk-for-java/sdk/compute/arm-compute",
295-
[new TspConfigGoModuleMatchPatternSubRule()],
297+
[new TspConfigGoMgmtModuleMatchPatternSubRule()],
296298
false,
297299
);
298300

@@ -302,7 +304,7 @@ const goManagementContainingModuleTestCases = createEmitterOptionTestCases(
302304
"containing-module",
303305
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute",
304306
"github.com/Azure/azure-sdk-for-java/sdk/compute/arm-compute",
305-
[new TspConfigGoContainingModuleMatchPatternSubRule()],
307+
[new TspConfigGoMgmtContainingModuleMatchPatternSubRule()],
306308
false,
307309
);
308310

@@ -348,8 +350,7 @@ const goDpModuleTestCases = createEmitterOptionTestCases(
348350
"module",
349351
"github.com/Azure/azure-sdk-for-go/sdk/messaging/aaa",
350352
"github.com/Azure/azure-sdk-for-cpp/bbb",
351-
[new TspConfigGoModuleMatchPatternSubRule()],
352-
false,
353+
[new TspConfigGoDpModuleMatchPatternSubRule()],
353354
);
354355

355356
const goDpContainingModuleTestCases = createEmitterOptionTestCases(
@@ -358,7 +359,7 @@ const goDpContainingModuleTestCases = createEmitterOptionTestCases(
358359
"containing-module",
359360
"github.com/Azure/azure-sdk-for-go/sdk/messaging/aaa",
360361
"github.com/Azure/azure-sdk-for-cpp/bbb",
361-
[new TspConfigGoContainingModuleMatchPatternSubRule()],
362+
[new TspConfigGoDpContainingModuleMatchPatternSubRule()],
362363
false,
363364
);
364365

@@ -645,10 +646,52 @@ parameters:
645646
subRules: [
646647
new TspConfigJavaMgmtNamespaceFormatSubRule(),
647648
new TspConfigTsRlcDpPackageNameMatchPatternSubRule(),
649+
new TspConfigGoDpEmitterOutputDirMatchPatternSubRule(),
650+
new TspConfigGoDpModuleMatchPatternSubRule(),
651+
new TspConfigGoDpContainingModuleMatchPatternSubRule(),
648652
],
649653
},
650654
];
651655

656+
const optionalRulesWithEmitterConfigTestCases: Case[] = [
657+
{
658+
description:
659+
"Validate Go DP emitter-output-dir should fail when not defined (emitter configured with model)",
660+
folder: "",
661+
tspconfigContent: `
662+
options:
663+
"@azure-tools/typespec-go":
664+
model: "a"
665+
`,
666+
success: false,
667+
subRules: [new TspConfigGoDpEmitterOutputDirMatchPatternSubRule()],
668+
},
669+
{
670+
description:
671+
"Validate Go Mgmt Module should fail when not defined (emitter configured with model)",
672+
folder: managementTspconfigFolder,
673+
tspconfigContent: `
674+
options:
675+
"@azure-tools/typespec-go":
676+
model: "a"
677+
`,
678+
success: false,
679+
subRules: [new TspConfigGoMgmtModuleMatchPatternSubRule()],
680+
},
681+
{
682+
description:
683+
"Validate Go Mgmt Containing Module should fail when not defined (emitter configured with model)",
684+
folder: managementTspconfigFolder,
685+
tspconfigContent: `
686+
options:
687+
"@azure-tools/typespec-go":
688+
model: "a"
689+
`,
690+
success: false,
691+
subRules: [new TspConfigGoMgmtContainingModuleMatchPatternSubRule()],
692+
},
693+
];
694+
652695
const suppressEntireRuleTestCase: Case = {
653696
description: "Suppress entire rule",
654697
folder: managementTspconfigFolder,
@@ -690,7 +733,7 @@ options:
690733
folder: managementTspconfigFolder,
691734
subRules: [
692735
new TspConfigGoMgmtEmitterOutputDirMatchPatternSubRule(),
693-
new TspConfigGoModuleMatchPatternSubRule(),
736+
new TspConfigGoDpModuleMatchPatternSubRule(),
694737
],
695738
tspconfigContent: `
696739
options:
@@ -737,10 +780,6 @@ describe("tspconfig", function () {
737780
...goManagementGenerateFakesTestCases,
738781
...goManagementHeadAsBooleanTestCases,
739782
...goManagementInjectSpansTestCases,
740-
...goDpModuleTestCases,
741-
...goDpContainingModuleTestCases,
742-
...goDpEmitterOutputDirTestCases,
743-
...goDpServiceDirTestCases,
744783
// java
745784
...javaAzEmitterOutputDirTestCases,
746785
...javaMgmtEmitterOutputDirTestCases,
@@ -760,6 +799,12 @@ describe("tspconfig", function () {
760799
const optionalTestCases = [
761800
// Test cases for optional rules when emitter is not configured
762801
...optionalRulesWithoutEmitterConfigTestCases,
802+
...optionalRulesWithEmitterConfigTestCases,
803+
// go data plane
804+
...goDpEmitterOutputDirTestCases,
805+
...goDpServiceDirTestCases,
806+
...goDpModuleTestCases,
807+
...goDpContainingModuleTestCases,
763808
];
764809

765810
it.each([...requiredTestCases, ...optionalTestCases])(`$description`, async (c: Case) => {

0 commit comments

Comments
 (0)