From 7aa151a9ed9200a2c73e279506474f56d10e2135 Mon Sep 17 00:00:00 2001 From: Yash Khare Date: Sun, 23 Apr 2023 22:33:12 +0530 Subject: [PATCH] =?UTF-8?q?=F0=9F=8C=B1=20added=20test=20for=20exec.go=20(?= =?UTF-8?q?#3352)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit added test for exec.go pass test cases updated tests updated tests Revert "updated tests" This reverts commit 7a465c049905efd93fe5bc60156048d07802dc67. updated tests Revert "added test for exec.go" This reverts commit da172c4514566a5bafba7d42b24bf0f799e7a4ac. added exec tests rerun suits stop added test files removed Test Plugin File solved bugs minor code changes added license header removed exec_test added exec_tests finally rebase commits --- pkg/plugin/util/exec_test.go | 47 ++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 pkg/plugin/util/exec_test.go diff --git a/pkg/plugin/util/exec_test.go b/pkg/plugin/util/exec_test.go new file mode 100644 index 0000000000..58d449852c --- /dev/null +++ b/pkg/plugin/util/exec_test.go @@ -0,0 +1,47 @@ +/* +Copyright 2022 The Kubernetes Authors. +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package util + +import ( + "bytes" + "os/exec" + "strings" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" +) + +var _ = Describe("RunCmd", func() { + var ( + output *bytes.Buffer + err error + ) + BeforeEach(func() { + output = &bytes.Buffer{} + }) + AfterEach(func() { + output.Reset() + }) + It("executes the command and redirects output to stdout", func() { + cmd := exec.Command("echo", "test") + cmd.Stdout = output + err = cmd.Run() + Expect(err).ToNot(HaveOccurred()) + Expect(strings.TrimSpace(output.String())).To(Equal("test")) + }) + It("returns an error if the command fails", func() { + err = RunCmd("unknown command", "unknowncommand") + Expect(err).To(HaveOccurred()) + }) +})