Fix reference to versioned object in kubectl apply

Fixes #19639
This commit is contained in:
Sam Ghods
2016-02-09 16:07:02 -08:00
parent 494186f40e
commit fd5747f89c
5 changed files with 96 additions and 9 deletions

View File

@@ -52,8 +52,9 @@ func validateApplyArgs(cmd *cobra.Command, args []string) error {
}
const (
filenameRC = "../../../examples/guestbook/redis-master-controller.yaml"
filenameSVC = "../../../examples/guestbook/frontend-service.yaml"
filenameRC = "../../../test/fixtures/pkg/kubectl/cmd/apply/rc.yaml"
filenameSVC = "../../../test/fixtures/pkg/kubectl/cmd/apply/service.yaml"
filenameRCSVC = "../../../test/fixtures/pkg/kubectl/cmd/apply/rc-service.yaml"
)
func readBytesFromFile(t *testing.T, filename string) []byte {
@@ -245,7 +246,15 @@ func TestApplyNonExistObject(t *testing.T) {
}
}
func TestApplyMultipleObject(t *testing.T) {
func TestApplyMultipleObjectsAsList(t *testing.T) {
testApplyMultipleObjects(t, true)
}
func TestApplyMultipleObjectsAsFiles(t *testing.T) {
testApplyMultipleObjects(t, false)
}
func testApplyMultipleObjects(t *testing.T, asList bool) {
nameRC, currentRC := readAndAnnotateReplicationController(t, filenameRC)
pathRC := "/namespaces/test/replicationcontrollers/" + nameRC
@@ -282,8 +291,12 @@ func TestApplyMultipleObject(t *testing.T) {
buf := bytes.NewBuffer([]byte{})
cmd := NewCmdApply(f, buf)
cmd.Flags().Set("filename", filenameRC)
cmd.Flags().Set("filename", filenameSVC)
if asList {
cmd.Flags().Set("filename", filenameRCSVC)
} else {
cmd.Flags().Set("filename", filenameRC)
cmd.Flags().Set("filename", filenameSVC)
}
cmd.Flags().Set("output", "name")
cmd.Run(cmd, []string{})
@@ -291,8 +304,10 @@ func TestApplyMultipleObject(t *testing.T) {
// Names should come from the REST response, NOT the files
expectRC := "replicationcontroller/" + nameRC + "\n"
expectSVC := "service/" + nameSVC + "\n"
expect := expectRC + expectSVC
if buf.String() != expect {
t.Fatalf("unexpected output: %s\nexpected: %s", buf.String(), expect)
// Test both possible orders since output is non-deterministic.
expectOne := expectRC + expectSVC
expectTwo := expectSVC + expectRC
if buf.String() != expectOne && buf.String() != expectTwo {
t.Fatalf("unexpected output: %s\nexpected: %s OR %s", buf.String(), expectOne, expectTwo)
}
}