diff --git a/eng/tools/generator/cmd/v2/common/fileProcessor.go b/eng/tools/generator/cmd/v2/common/fileProcessor.go index 30e625af72e3..2ac6c1dd6464 100644 --- a/eng/tools/generator/cmd/v2/common/fileProcessor.go +++ b/eng/tools/generator/cmd/v2/common/fileProcessor.go @@ -566,3 +566,27 @@ func replaceModuleImport(path, rpName, namespaceName, previousVersion, currentVe return nil }) } + +func existSuffixFile(path, suffix string) bool { + + existed := false + err := filepath.WalkDir(path, func(p string, d fs.DirEntry, err error) error { + if err != nil { + return err + } + + if d.IsDir() { + return nil + } + + if strings.HasSuffix(d.Name(), suffix) { + existed = true + } + return nil + }) + if err != nil { + return false + } + + return existed +} diff --git a/eng/tools/generator/cmd/v2/common/generation.go b/eng/tools/generator/cmd/v2/common/generation.go index 643e56c1ecec..e201a7783bbb 100644 --- a/eng/tools/generator/cmd/v2/common/generation.go +++ b/eng/tools/generator/cmd/v2/common/generation.go @@ -306,6 +306,15 @@ func (ctx *GenerateContext) GenerateForSingleRPNamespace(generateParam *Generate } } + // When sdk has major version bump, the live test needs to update the module referenced in the code. + if changelog.HasBreakingChanges() && existSuffixFile(packagePath, "_live_test.go") { + log.Printf("Replace live test module v2+...") + if err = replaceModuleImport(packagePath, generateParam.RPName, generateParam.NamespaceName, previousVersion, version.String(), + "", "_live_test.go"); err != nil { + return nil, err + } + } + // Example generation should be the last step because the package import relay on the new calculated version if !generateParam.SkipGenerateExample { log.Printf("Generate examples...")