从可选的YAML文件中读取空手道config-是否存在文件?

发布于 2025-02-12 16:16:35 字数 479 浏览 1 评论 0原文

在类似的用例中,与读取yaml 读取空手道config的我想从yaml文件读取空手道的环境配置。这与空手道。READ很好。我的扩展用例现在将是以下内容:

  • 从版本控件中的yaml文件中读取环境的环境配置,该
  • 文件具有一个文件,该文件具有不在版本控件中的自定义环境,也可以从该文件中读取
  • 所有环境(基于ID字段)在两个文件中定义的自定义环境定义覆盖

我现在必须读取两个文件的通用环境定义,但是对于使用自定义环境的文件,我不知道它是否存在,因为用户可能会选择没有任何自定义环境定义。有没有办法在尝试读取第二个文件之前检查第二个文件是否存在?我已经检查了空手道对象的文档,但没有找到类似的东西。

如果不可能,是否有另一种方法可以实现我的用例?

In a similar use case as in Read Karate config from YAML I want to read my environment config for Karate from a YAML file. This works well with karate.read. My extended use case now would be the following:

  • read environment config of common environments from a YAML file which is in version control
  • have a file with custom environments not in version control and read from that file too
  • for all environments (based on a ID field) that are defined in both files the custom environment definition overwrites the common one

I now have to read two files but for the file with the custom environments I don't know if it will exist because the user might choose to not have any custom environments defined. Is there a way to check if the second file exists before attempting to read it? I have checked the documentation for the karate object but have not found anything like that.

If that wouldn't be possible, is there another way how my use case could be implemented?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

强辩 2025-02-19 16:16:40

空手道具有一种内置的使用方式来使用Dev-env specifc配置,可能不存在: https ://github.com/intuit/karate#envorirnment-specific-config

也就是说,请注意,您可以捕获异常在JS中,这为您提供了更多选择: https://stackoverflow.com/a/5454175/143475

try {
  // read
} catch(e) {
  // print e if needed and ignore
}

Karate has a built-in way to use dev-env specifc config that may not exist: https://github.com/intuit/karate#environment-specific-config

That said, note that you can catch exceptions in JS, so that gives you some more options: https://stackoverflow.com/a/54554175/143475

try {
  // read
} catch(e) {
  // print e if needed and ignore
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文