Files
kustomize/api/krusty/duplicatekeys_test.go
Karl Isenberg 43868688d5 Use require for Error and NoError
Assert keeps going after failure, but require immediately fails
the tests, making it easier to find the output related to the test
failure, rather than having to comb through a bunch of subsequent
assertion failures. For equality tests, we may or may not want to
continue, but for error checks we almost always want to immediately
fail the test. Exceptions can be changed as-needed.
2024-03-20 13:19:18 -07:00

48 lines
1004 B
Go

// Copyright 2022 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package krusty_test
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
)
func TestDuplicateKeys(t *testing.T) {
th := kusttest_test.MakeHarness(t)
th.WriteK(".", `
resources:
- resources.yaml
`)
th.WriteF("resources.yaml", `
apiVersion: apps/v1
kind: Deployment
metadata:
name: podinfo
spec:
selector:
matchLabels:
app: podinfo
template:
spec:
containers:
- name: podinfod
image: ghcr.io/stefanprodan/podinfo:5.0.3
command:
- ./podinfo
env:
- name: PODINFO_UI_COLOR
value: "#34577c"
env:
- name: PODINFO_UI_COLOR
value: "#34577c"
`)
m := th.Run(".", th.MakeDefaultOptions())
_, err := m.AsYaml()
require.Error(t, err)
assert.Contains(t, err.Error(), "mapping key \"env\" already defined")
}