小编Cam*_*ron的帖子

测试 HttpInterceptor Angular 10 时出错

我正在开发一个 Angular 10 应用程序,该应用程序使用HttpInterceptor向所有响应添加特定标头。不幸的是,在尝试测试此拦截器时,我不断收到以下错误:

Error: Expected one matching request for criteria "Match by function: ", found none.
Run Code Online (Sandbox Code Playgroud)

或类似的变体:

Error: Expected one matching request for criteria "Match URL: /endpoint", found none.
Run Code Online (Sandbox Code Playgroud)

我的期望是这个测试会通过,但我现在不知道为什么它不起作用。

这是我的拦截器:

Error: Expected one matching request for criteria "Match by function: ", found none.
Run Code Online (Sandbox Code Playgroud)

这是我的测试:

Error: Expected one matching request for criteria "Match URL: /endpoint", found none.
Run Code Online (Sandbox Code Playgroud)

也就是说,可能值得指出的是,我尝试应用以下资源中的解决方案但无济于事(大多数似乎与我已经拥有的类似,而且许多似乎适用于旧版本的 Angular):

  • 来自 Angular 4 的单元测试 HttpInterceptor:在这里,我发现了一篇有用的文章,它几乎完全满足了我的需求,但实际上并不适用于我的情况(我遇到了上述错误)。我这么说几乎完全是因为我用来获取令牌的服务实际上并没有使用HttpClient我所知道的。
  • 并不完全像我的问题,但它足够相似,可以尝试一下。我尝试使用教科书描述的解决方法,但显然这与我遇到的问题不够接近。 …

testing typescript angular angular-httpclient angular-httpclient-interceptors

5
推荐指数
0
解决办法
313
查看次数

在 Kubernetes cron 作业中运行的应用程序未连接到同一 Kubernetes 集群中的数据库

我有一个运行 PostgreSQL 数据库的 Kubernetes 集群、一个 Grafana 仪表板和一个 Python 单次运行应用程序(构建为 Docker 映像),它在 Kubernetes 中每小时运行一次CronJob(参见下面的清单)。此外,这一切都是使用 ArgoCD 和 Istio side-car 注入进行部署的。

我遇到的问题(如标题所示)是我的 Python 应用程序无法连接到集群中的数据库。这对我来说很奇怪,因为仪表板实际上可以连接到数据库,所以我不确定 Python 应用程序可能会有什么不同。

以下是我的清单(更改了一些内容以删除可识别信息):

内容database.yaml

---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: database
  name: database
spec:
  replicas: 1
  selector:
    matchLabels:
      app: database
  strategy: {}
  template:
    metadata:
      labels:
        app: database
    spec:
      containers:
      - image: postgres:12.5
        imagePullPolicy: ""
        name: database
        ports:
        - containerPort: 5432
        env:
          - name: POSTGRES_DB
            valueFrom:
              secretKeyRef:
                name: postgres-secret
                key: POSTGRES_DB
          - …
Run Code Online (Sandbox Code Playgroud)

postgresql python-3.x kubernetes istio

3
推荐指数
1
解决办法
365
查看次数