-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #145 from yandex-cloud/feature/check-endpoints
test: add script to check that all services have corresponding endpoints
- Loading branch information
Showing
5 changed files
with
94 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import * as fg from 'fast-glob'; | ||
import * as path from 'path'; | ||
import { | ||
Namespace, NamespaceBase, Root, Service, | ||
} from 'protobufjs'; | ||
import { SERVICE_ENDPOINTS_LIST } from '../src/service-endpoints'; | ||
|
||
const PROTO_DIR = path.resolve('./cloudapi'); | ||
|
||
const protoFiles = fg.sync('**/*.proto', { cwd: PROTO_DIR }); | ||
|
||
const pbRoot = new Root(); | ||
|
||
pbRoot.resolvePath = (origin, target) => { | ||
const targets = target.split('/'); | ||
|
||
switch (targets[0]) { | ||
case 'google': { | ||
switch (targets[1]) { | ||
case 'protobuf': { | ||
return `./node_modules/protobufjs/${target}`; | ||
} | ||
default: { | ||
return `./cloudapi/third_party/googleapis/${target}`; | ||
} | ||
} | ||
} | ||
case 'third_party': { | ||
return `./cloudapi/${target}`; | ||
} | ||
case 'yandex': { | ||
return `./cloudapi/${target}`; | ||
} | ||
default: { | ||
return target; | ||
} | ||
} | ||
}; | ||
|
||
const SERVICES: Service[] = []; | ||
const findServices = <T extends NamespaceBase>(node: T) => { | ||
for (const child of Object.values(node.nested ?? {}) | ||
.sort((a, b) => (a.name < b.name ? -1 : (a.name === b.name ? 0 : 1)))) { | ||
if (child instanceof Service) { | ||
SERVICES.push(child); | ||
} else if (child instanceof Namespace) { | ||
findServices(child); | ||
} | ||
} | ||
}; | ||
|
||
// eslint-disable-next-line unicorn/prefer-top-level-await | ||
pbRoot.load(protoFiles, { alternateCommentMode: true }).then((loadedRoot) => { | ||
const SERVICE_IDS = new Set<string>(); | ||
let hasMissing = false; | ||
|
||
for (const serviceEndpoint of SERVICE_ENDPOINTS_LIST) { | ||
for (const service of serviceEndpoint.serviceIds) { | ||
SERVICE_IDS.add(service); | ||
} | ||
} | ||
|
||
findServices(loadedRoot); | ||
for (const s of SERVICES) { | ||
// full name without leading dot | ||
const fullName = s.fullName.slice(1); | ||
|
||
if (!SERVICE_IDS.has(fullName)) { | ||
// eslint-disable-next-line no-console | ||
console.log('Missing service', fullName); | ||
hasMissing = true; | ||
} | ||
} | ||
|
||
if (hasMissing) { | ||
// eslint-disable-next-line unicorn/no-process-exit | ||
process.exit(1); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters