• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pantsbuild / pants / 18252174847

05 Oct 2025 01:36AM UTC coverage: 43.382% (-36.9%) from 80.261%
18252174847

push

github

web-flow
run tests on mac arm (#22717)

Just doing the minimal to pull forward the x86_64 pattern.

ref #20993

25776 of 59416 relevant lines covered (43.38%)

1.3 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

91.67
/src/python/pants/backend/helm/testutil.py
1
# Copyright 2022 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
3

4
from __future__ import annotations
3✔
5

6
from textwrap import dedent  # noqa: PNT20
3✔
7

8
from pants.backend.helm.util_rules.chart_metadata import DEFAULT_API_VERSION, ChartType
3✔
9

10

11
def gen_chart_file(
3✔
12
    name: str,
13
    *,
14
    version: str,
15
    description: str | None = None,
16
    type: ChartType = ChartType.APPLICATION,
17
    api_version: str = DEFAULT_API_VERSION,
18
    icon: str | None = None,
19
) -> str:
20
    metadata_yaml = dedent(
3✔
21
        f"""\
22
    apiVersion: {api_version}
23
    name: {name}
24
    version: {version}
25
    type: {type.value}
26
    """
27
    )
28
    if description:
3✔
29
        metadata_yaml += f"description: {description}\n"
×
30
    if icon:
3✔
31
        metadata_yaml += f"icon: {icon}\n"
×
32
    return metadata_yaml
3✔
33

34

35
HELM_CHART_FILE = gen_chart_file("mychart", version="0.1.0")
3✔
36

37
HELM_CHART_WITH_DEPENDENCIES_FILE = dedent(
3✔
38
    """\
39
    apiVersion: v2
40
    name: mychart
41
    description: A Helm chart for Kubernetes
42
    version: 0.1.0
43
    icon: https://www.example.com/icon.png
44
    dependencies:
45
    - name: other_chart
46
      repository: "@myrepo"
47
      version: "~0.1.0"
48
      alias: dependency_alias
49
    """
50
)
51

52
HELM_CHART_FILE_V1_FULL = dedent(
3✔
53
    """\
54
  name: foo
55
  version: 0.1.0
56
  kubeVersion: 1.17
57
  description: The foo chart
58
  keywords:
59
  - foo
60
  - chart
61
  home: https://example.com
62
  sources:
63
  - https://example.com/git
64
  dependencies:
65
  - name: bar
66
    version: 0.2.0
67
    repository: https://example.com/repo
68
    condition: bar.enabled
69
    tags:
70
    - foo
71
    - bar
72
    import-values:
73
    - data
74
    alias: bar-alias
75
  maintainers:
76
  - name: foo
77
    email: bar@example.com
78
    url: https://example.com/foo
79
  icon: https://example.com/icon.png
80
  appVersion: 0.1.0
81
  deprecated: true
82
  annotations:
83
    example: yes
84
    name: foo
85
  """
86
)
87

88
HELM_CHART_FILE_V2_FULL = dedent(
3✔
89
    """\
90
  apiVersion: v2
91
  name: quxx
92
  version: 0.1.0
93
  kubeVersion: 1.17
94
  description: The foo chart
95
  type: library
96
  keywords:
97
  - foo
98
  - chart
99
  home: https://example.com
100
  sources:
101
  - https://example.com/git
102
  dependencies:
103
  - name: bar
104
    version: 0.2.0
105
    repository: https://example.com/repo
106
    condition: bar.enabled
107
    tags:
108
    - foo
109
    - bar
110
    import-values:
111
    - data
112
    alias: bar-alias
113
  maintainers:
114
  - name: foo
115
    email: bar@example.com
116
    url: https://example.com/foo
117
  icon: https://example.com/icon.png
118
  appVersion: 0.1.0
119
  deprecated: true
120
  annotations:
121
    example: yes
122
    name: quxx
123
  """
124
)
125

126
K8S_SERVICE_TEMPLATE = dedent(
3✔
127
    """\
128
  apiVersion: v1
129
  kind: Service
130
  metadata:
131
    name: {{ template "fullname" . }}
132
    labels:
133
      chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
134
  spec:
135
    type: {{ .Values.service.type }}
136
    ports:
137
        - port: {{ .Values.service.externalPort }}
138
          targetPort: {{ .Values.service.internalPort }}
139
          protocol: TCP
140
          name: {{ .Values.service.name }}
141
    selector:
142
        app: {{ template "fullname" . }}
143
  """
144
)
145

146
K8S_INGRESS_TEMPLATE_WITH_LINT_WARNINGS = dedent(
3✔
147
    """\
148
  apiVersion: extensions/v1beta1
149
  kind: Ingress
150
  metadata:
151
    name: {{ template "fullname" . }}
152
    labels:
153
      chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
154
  spec:
155
    rules:
156
    - host: example.com
157
      http:
158
        paths:
159
        - path: /
160
          pathType: Prefix
161
          backend:
162
            service:
163
              name: {{ template "fullname" . }}
164
              port:
165
                name: http
166
  """
167
)
168

169
K8S_POD_TEMPLATE = dedent(
3✔
170
    """\
171
    apiVersion: v1
172
    kind: Pod
173
    metadata:
174
      name: {{ template "fullname" . }}
175
      labels:
176
        chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
177
    spec:
178
      containers:
179
        - name: myapp-container
180
          image: busybox:1.28
181
      initContainers:
182
        - name: init-service
183
          image: busybox:1.29
184
    """
185
)
186

187
K8S_POD_FILE = dedent(
3✔
188
    """\
189
    apiVersion: v1
190
    kind: Pod
191
    metadata:
192
      name: foo
193
      labels:
194
        chart: foo-bar
195
    spec:
196
      containers:
197
        - name: myapp-container
198
          image: busybox:1.28
199
      initContainers:
200
        - name: init-service
201
          image: busybox:1.29
202
    """
203
)
204

205
K8S_CRD_FILE = dedent(
3✔
206
    """\
207
  apiVersion: apiextensions.k8s.io/v1
208
  kind: CustomResourceDefinition
209
  metadata:
210
  # name must match the spec fields below, and be in the form: <plural>.<group>
211
  name: myplatforms.contoso.com
212
  spec:
213
  # group name to use for REST API: /apis/<group>/<version>
214
  group: contoso.com
215
  names:
216
    # plural name to be used in the URL: /apis/<group>/<version>/<plural>
217
    plural: myplatforms
218
    # singular name to be used as an alias on the CLI and for display
219
    singular: myplatform
220
    # kind is normally the CamelCased singular type. Your resource manifests use this.
221
    kind: MyPlatform
222
    # shortNames allow shorter string to match your resource on the CLI
223
    shortNames:
224
    - myp
225
  # either Namespaced or Cluster
226
  scope: Namespaced
227
  versions:
228
    - name: v1alpha1
229
      # Each version can be enabled/disabled by Served flag.
230
      served: true
231
      # One and only one version must be marked as the storage version.
232
      storage: true
233
      schema:
234
        openAPIV3Schema:
235
          type: object
236
          properties:
237
            spec:
238
              type: object
239
              properties:
240
                appId:
241
                  type: string
242
                language:
243
                  type: string
244
                  enum:
245
                  - csharp
246
                  - python
247
                  - go
248
                os:
249
                  type: string
250
                  enum:
251
                  - windows
252
                  - linux
253
                instanceSize:
254
                  type: string
255
                  enum:
256
                    - small
257
                    - medium
258
                    - large
259
                environmentType:
260
                  type: string
261
                  enum:
262
                  - dev
263
                  - test
264
                  - prod
265
                replicas:
266
                  type: integer
267
                  minimum: 1
268
              required: ["appId", "language", "environmentType"]
269
          required: ["spec"]
270
  """
271
)
272

273
K8S_CUSTOM_RESOURCE_FILE = dedent(
3✔
274
    """\
275
    apiVersion: myplatforms.contoso.com/v1alpha1
276
    kind: MyPlatform
277
    metadata:
278
      name: cr_foo
279
    spec:
280
      appId: foo
281
      language: python
282
      environmentType: test
283
    """
284
)
285

286
K8S_CRD_FILE_IMAGE = dedent(
3✔
287
    """
288
    apiVersion: pants/v1alpha1
289
    kind: CustomResourceDefinition
290
    metadata:
291
      name: crd_foo
292
    spec:
293
      containers:
294
        - name: myapp-container
295
          image: busybox:1.28
296
      initContainers:
297
        - name: init-service
298
          image: busybox:1.29
299
    """
300
)
301

302
HELM_TEMPLATE_HELPERS_FILE = dedent(
3✔
303
    """\
304
  {{- define "fullname" -}}
305
  {{- if .Values.fullnameOverride }}
306
  {{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
307
  {{- else }}
308
  {{- $name := default .Chart.Name .Values.nameOverride }}
309
  {{- if contains $name .Release.Name }}
310
  {{- .Release.Name | trunc 63 | trimSuffix "-" }}
311
  {{- else }}
312
  {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
313
  {{- end }}
314
  {{- end }}
315
  {{- end }}
316
  """
317
)
318

319
HELM_VALUES_FILE = dedent(
3✔
320
    """\
321
  service:
322
    name: test
323
    type: ClusterIP
324
    externalPort: 80
325
    internalPort: 1223
326
  """
327
)
328

329
HELM_BATCH_HOOK_TEMPLATE = dedent(
3✔
330
    """\
331
  apiVersion: batch/v1
332
  kind: Job
333
  metadata:
334
    name: "{{ .Release.Name }}"
335
    labels:
336
      app.kubernetes.io/managed-by: {{ .Release.Service | quote }}
337
      app.kubernetes.io/instance: {{ .Release.Name | quote }}
338
      app.kubernetes.io/version: {{ .Chart.AppVersion }}
339
      helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
340
    annotations:
341
      # This is what defines this resource as a hook. Without this line, the
342
      # job is considered part of the release.
343
      "helm.sh/hook": post-install
344
      "helm.sh/hook-weight": "-5"
345
      "helm.sh/hook-delete-policy": hook-succeeded
346
  spec:
347
    template:
348
      metadata:
349
        name: "{{ .Release.Name }}"
350
        labels:
351
          app.kubernetes.io/managed-by: {{ .Release.Service | quote }}
352
          app.kubernetes.io/instance: {{ .Release.Name | quote }}
353
          helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
354
      spec:
355
        restartPolicy: Never
356
        containers:
357
        - name: post-install-job
358
          image: "alpine:3.3"
359
          command: ["/bin/sleep","{{ default "10" .Values.sleepyTime }}"]
360
  """
361
)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc