Skip to content

Commit

Permalink
move the tests of GetDeviceNumber to the right package
Browse files Browse the repository at this point in the history
Signed-off-by: Arik Hadas <[email protected]>
  • Loading branch information
ahadas committed Jun 20, 2024
1 parent 4bbf97d commit 2429fe6
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 28 deletions.
1 change: 0 additions & 1 deletion pkg/controller/plan/adapter/vsphere/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ go_test(
"//pkg/apis/forklift/v1beta1/plan",
"//pkg/apis/forklift/v1beta1/ref",
"//pkg/controller/plan/context",
"//pkg/controller/plan/util",
"//pkg/controller/provider/model/vsphere",
"//pkg/controller/provider/web",
"//pkg/controller/provider/web/vsphere",
Expand Down
26 changes: 0 additions & 26 deletions pkg/controller/plan/adapter/vsphere/vsphere_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package vsphere
import (
"testing"

utils "github.com/konveyor/forklift-controller/pkg/controller/plan/util"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
Expand All @@ -12,28 +11,3 @@ func TestVsphere(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "vSphere Suite")
}

func TestGetDeviceNumber(t *testing.T) {
tests := []struct {
input string
expected int
}{
{"/dev/sda", 1},
{"/dev/sdb", 2},
{"/dev/sdz", 26},
{"/dev/sda1", 1},
{"/dev/sda5", 1},
{"/dev/sdb2", 2},
{"/dev/sdza", 26},
{"/dev/sdzb", 26},
{"/dev/sd", 0},
{"test", 0},
}

for _, test := range tests {
result := utils.GetDeviceNumber(test.input)
if result != test.expected {
t.Errorf("For input '%s', expected %d, but got %d", test.input, test.expected, result)
}
}
}
15 changes: 14 additions & 1 deletion pkg/controller/plan/util/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

go_library(
name = "util",
Expand All @@ -18,3 +18,16 @@ go_library(
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:meta",
],
)

go_test(
name = "util_test",
srcs = [
"util_suite_test.go",
"utils_test.go",
],
embed = [":util"],
deps = [
"//vendor/github.com/onsi/ginkgo/v2:ginkgo",
"//vendor/github.com/onsi/gomega",
],
)
13 changes: 13 additions & 0 deletions pkg/controller/plan/util/util_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package util

import (
"testing"

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

func TestUtil(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "plan/util Suite")
}
23 changes: 23 additions & 0 deletions pkg/controller/plan/util/utils_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package util

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

var _ = Describe("Plan/utils", func() {
DescribeTable("convert dev", func(dev string, number int) {
Expect(GetDeviceNumber(dev)).Should(Equal(number))
},
Entry("sda", "/dev/sda", 1),
Entry("sdb", "/dev/sdb", 2),
Entry("sdz", "/dev/sdz", 26),
Entry("sda1", "/dev/sda1", 1),
Entry("sda5", "/dev/sda5", 1),
Entry("sdb2", "/dev/sdb2", 2),
Entry("sdza", "/dev/sdza", 26),
Entry("sdzb", "/dev/sdzb", 26),
Entry("sd", "/dev/sd", 0),
Entry("test", "test", 0),
)
})

0 comments on commit 2429fe6

Please sign in to comment.