Merge pull request #2629 from phanimarupaka/ListSettersNoSet

Tests for List setters should not alter resources
This commit is contained in:
Morten Torkildsen
2020-06-23 17:17:30 -07:00
committed by GitHub

View File

@@ -7,6 +7,7 @@ import (
"bytes"
"io/ioutil"
"os"
"strings"
"testing"
"github.com/stretchr/testify/assert"
@@ -49,6 +50,32 @@ spec:
replicas 3 me hello world 1 Yes
`,
},
{
name: "list-replicas inconsistent with openapi",
openapi: `
openAPI:
definitions:
io.k8s.cli.setters.replicas:
x-k8s-cli:
setter:
name: replicas
value: "4"
setBy: me
description: "hello world"
`,
input: `
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 3 # {"$ref": "#/definitions/io.k8s.cli.setters.replicas"}
`,
expected: ` NAME VALUE SET BY DESCRIPTION COUNT
replicas 4 me hello world 1
`,
},
{
name: "list-multiple",
openapi: `
@@ -414,6 +441,27 @@ openAPI:
if !assert.Equal(t, test.expected, actual.String()) {
t.FailNow()
}
// make sure that the resources are not altered
actualResources, err := ioutil.ReadFile(r.Name())
if !assert.NoError(t, err) {
t.FailNow()
}
if !assert.Equal(t,
strings.TrimSpace(test.input),
strings.TrimSpace(string(actualResources))) {
t.FailNow()
}
actualOpenAPI, err := ioutil.ReadFile(f.Name())
if !assert.NoError(t, err) {
t.FailNow()
}
if !assert.Equal(t,
strings.TrimSpace(test.openapi),
strings.TrimSpace(string(actualOpenAPI))) {
t.FailNow()
}
})
}
}