Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OSD-21348] Add Test Cases for Helper Function of elevate cmd #394

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions pkg/utils/shell_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package utils

import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

var _ = Describe("ShellChecker", func() {
var (
shellChecker ShellCheckerInterface
)

BeforeEach(func() {
shellChecker = DefaultShellChecker{}
})

Context("When checking a valid shell", func() {
It("Should return true for a valid shell path", func() {
validShellPath := "/bin/bash"
Expect(shellChecker.IsValidShell(validShellPath)).To(BeTrue())
})

It("Should return true for another valid shell path", func() {
validShellPath := "/bin/zsh"
Expect(shellChecker.IsValidShell(validShellPath)).To(BeTrue())
})
})

Context("When checking an invalid shell", func() {
It("Should return false for an invalid shell path", func() {
invalidShellPath := "/invalid/shell/path"
Expect(shellChecker.IsValidShell(invalidShellPath)).To(BeFalse())
})

It("Should return false for another invalid shell path", func() {
invalidShellPath := "/another/invalid/shell/path"
Expect(shellChecker.IsValidShell(invalidShellPath)).To(BeFalse())
})
})

Context("When checking an empty shell path", func() {
It("Should return false", func() {
Expect(shellChecker.IsValidShell("")).To(BeFalse())
})
})

Context("When checking a non-existent shell path", func() {
It("Should return false", func() {
nonExistentShellPath := "/path/that/does/not/exist"
Expect(shellChecker.IsValidShell(nonExistentShellPath)).To(BeFalse())
})
})
})