Skip to content

Commit

Permalink
馃尡 added test for exec.go (#3352)
Browse files Browse the repository at this point in the history
added test for exec.go

pass test cases

updated tests

updated tests

Revert "updated tests"

This reverts commit 7a465c0.

updated tests

Revert "added test for exec.go"

This reverts commit da172c4.

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
  • Loading branch information
khareyash05 committed Apr 23, 2023
1 parent ccd8944 commit 7aa151a
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions pkg/plugin/util/exec_test.go
Original file line number Diff line number Diff line change
@@ -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())
})
})

0 comments on commit 7aa151a

Please sign in to comment.