Skip to content
Merged
Show file tree
Hide file tree
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
89 changes: 50 additions & 39 deletions pkg/utils/runtimes/options/init_port_check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,44 +17,55 @@ limitations under the License.
package options

import (
"testing"
"os"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

func TestPortCheckEnabled(t *testing.T) {
type testCase struct {
name string
env map[string]string
expect bool
}

testCases := []testCase{
{
name: "not_set",
env: map[string]string{},
expect: false,
}, {
name: "set_true",
env: map[string]string{
EnvPortCheckEnabled: "true",
},
expect: true,
}, {
name: "set_false",
env: map[string]string{
EnvPortCheckEnabled: "false",
},
expect: false,
},
}

for _, test := range testCases {
for k, v := range test.env {
t.Setenv(k, v)
}
setPortCheckOption()
got := PortCheckEnabled()
if got != test.expect {
t.Errorf("testcase %s is failed due to expect %v, but got %v", test.name, test.expect, got)
}
}
}
var _ = Describe("PortCheckEnabled", func() {

Context("when environment variable is not set", func() {
BeforeEach(func() {
os.Unsetenv(EnvPortCheckEnabled)
})

It("should return false", func() {
setPortCheckOption()
got := PortCheckEnabled()
Expect(got).To(BeFalse())
})
})

Context("when environment variable is set to true", func() {
BeforeEach(func() {
os.Setenv(EnvPortCheckEnabled, "true")
})

AfterEach(func() {
os.Unsetenv(EnvPortCheckEnabled)
})

It("should return true", func() {
setPortCheckOption()
got := PortCheckEnabled()
Expect(got).To(BeTrue())
})
})

Context("when environment variable is set to false", func() {
BeforeEach(func() {
os.Setenv(EnvPortCheckEnabled, "false")
})

AfterEach(func() {
os.Unsetenv(EnvPortCheckEnabled)
})

It("should return false", func() {
setPortCheckOption()
got := PortCheckEnabled()
Expect(got).To(BeFalse())
})
})
})
13 changes: 13 additions & 0 deletions pkg/utils/runtimes/options/options_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package options

import (
"testing"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

func TestOptions(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Options Suite")
}
Loading