pkg/utils: sysctl package should use black-box testing

Signed-off-by: Bruce Ma <brucema19901024@gmail.com>
This commit is contained in:
Bruce Ma 2020-01-27 21:09:04 +08:00
parent 832f2699c2
commit 37207f05b4
2 changed files with 7 additions and 6 deletions

View File

@ -59,7 +59,7 @@ func setSysctl(name, value string) (string, error) {
// Sysctl names can use dots or slashes as separator: // Sysctl names can use dots or slashes as separator:
// - if dots are used, dots and slashes are interchanged. // - if dots are used, dots and slashes are interchanged.
// - if slashes are used, slashes and dots are left intact. // - if slashes are used, slashes and dots are left intact.
// Separator in use is determined by firt ocurrence. // Separator in use is determined by first occurrence.
func toNormalName(name string) string { func toNormalName(name string) string {
interchange := false interchange := false
for _, c := range name { for _, c := range name {

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package sysctl package sysctl_test
import ( import (
"fmt" "fmt"
@ -22,6 +22,7 @@ import (
"github.com/containernetworking/plugins/pkg/ns" "github.com/containernetworking/plugins/pkg/ns"
"github.com/containernetworking/plugins/pkg/testutils" "github.com/containernetworking/plugins/pkg/testutils"
"github.com/containernetworking/plugins/pkg/utils/sysctl"
. "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo"
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
"github.com/vishvananda/netlink" "github.com/vishvananda/netlink"
@ -77,7 +78,7 @@ var _ = Describe("Sysctl tests", func() {
sysctlIfaceName := strings.Replace(testIfaceName, ".", "/", -1) sysctlIfaceName := strings.Replace(testIfaceName, ".", "/", -1)
sysctlKey := fmt.Sprintf(sysctlDotKeyTemplate, sysctlIfaceName) sysctlKey := fmt.Sprintf(sysctlDotKeyTemplate, sysctlIfaceName)
_, err := Sysctl(sysctlKey) _, err := sysctl.Sysctl(sysctlKey)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
}) })
}) })
@ -86,7 +87,7 @@ var _ = Describe("Sysctl tests", func() {
It("reads keys with slash separators", func() { It("reads keys with slash separators", func() {
sysctlKey := fmt.Sprintf(sysctlSlashKeyTemplate, testIfaceName) sysctlKey := fmt.Sprintf(sysctlSlashKeyTemplate, testIfaceName)
_, err := Sysctl(sysctlKey) _, err := sysctl.Sysctl(sysctlKey)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
}) })
}) })
@ -96,7 +97,7 @@ var _ = Describe("Sysctl tests", func() {
sysctlIfaceName := strings.Replace(testIfaceName, ".", "/", -1) sysctlIfaceName := strings.Replace(testIfaceName, ".", "/", -1)
sysctlKey := fmt.Sprintf(sysctlDotKeyTemplate, sysctlIfaceName) sysctlKey := fmt.Sprintf(sysctlDotKeyTemplate, sysctlIfaceName)
_, err := Sysctl(sysctlKey, "1") _, err := sysctl.Sysctl(sysctlKey, "1")
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
}) })
}) })
@ -105,7 +106,7 @@ var _ = Describe("Sysctl tests", func() {
It("writes keys with slash separators", func() { It("writes keys with slash separators", func() {
sysctlKey := fmt.Sprintf(sysctlSlashKeyTemplate, testIfaceName) sysctlKey := fmt.Sprintf(sysctlSlashKeyTemplate, testIfaceName)
_, err := Sysctl(sysctlKey, "1") _, err := sysctl.Sysctl(sysctlKey, "1")
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
}) })
}) })