Files
kustomize/kyaml/yaml/merge3/scalar_test.go
Phillip Wittrock 5d1a0346b5 Use OpenAPI when merging (3way) resources
- When merging (3way) resources use the patch strategy from the openAPI if the definition exists for the field
- Allow disabling of guessing patch strategy merge keys when no definition exists
- Support defining strategy and key directly on configuration fields through line and header coments
- Support attaching schema to parent fields of lists, and propagating -- e.g. that a field is a PodTemplate
2020-03-02 20:56:53 -08:00

136 lines
2.5 KiB
Go

// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package merge3_test
var scalarTestCases = []testCase{
// Scalar Field Test Cases
//
// Test Case
//
{description: `Set and updated a field`,
origin: `kind: Deployment`,
update: `kind: StatefulSet`,
local: `kind: Deployment`,
expected: `kind: StatefulSet`},
{description: `Add an updated field`,
origin: `
apiVersion: apps/v1
kind: Deployment # old value`,
update: `
apiVersion: apps/v1
kind: StatefulSet # new value`,
local: `
apiVersion: apps/v1`,
expected: `
apiVersion: apps/v1
kind: StatefulSet # new value`},
{description: `Add keep an omitted field`,
origin: `
apiVersion: apps/v1
kind: Deployment`,
update: `
apiVersion: apps/v1
kind: StatefulSet`,
local: `
apiVersion: apps/v1
spec: foo # field not present in source
`,
expected: `
apiVersion: apps/v1
spec: foo # field not present in source
kind: StatefulSet
`},
//
// Test Case
//
// TODO(#36): consider making this an error
{description: `Change an updated field`,
origin: `
apiVersion: apps/v1
kind: Deployment # old value`,
update: `
apiVersion: apps/v1
kind: StatefulSet # new value`,
local: `
apiVersion: apps/v1
kind: Service # conflicting value`,
expected: `
apiVersion: apps/v1
kind: StatefulSet # new value`},
{description: `Ignore a field`,
origin: `
apiVersion: apps/v1
kind: Deployment # ignore this field`,
update: `
apiVersion: apps/v1
kind: Deployment # ignore this field`,
local: `
apiVersion: apps/v1`,
expected: `
apiVersion: apps/v1`},
{description: `Explicitly clear a field`,
origin: `
apiVersion: apps/v1`,
update: `
apiVersion: apps/v1
kind: null # clear this value`,
local: `
apiVersion: apps/v1
kind: Deployment # value to be cleared`,
expected: `
apiVersion: apps/v1`},
{description: `Implicitly clear a field`,
origin: `
apiVersion: apps/v1
kind: Deployment # clear this field`,
update: `
apiVersion: apps/v1`,
local: `
apiVersion: apps/v1
kind: Deployment # clear this field`,
expected: `
apiVersion: apps/v1`},
//
// Test Case
//
// TODO(#36): consider making this an error
{description: `Implicitly clear a changed field`,
origin: `
apiVersion: apps/v1
kind: Deployment`,
update: `
apiVersion: apps/v1`,
local: `
apiVersion: apps/v1
kind: StatefulSet`,
expected: `
apiVersion: apps/v1`},
//
// Test Case
//
{description: `Merge an empty scalar value`,
origin: `
apiVersion: apps/v1
`,
update: `
apiVersion: apps/v1
kind: {}
`,
local: `
apiVersion: apps/v1
`,
expected: `
apiVersion: apps/v1
kind: {}
`},
}