This is an automated email from the ASF dual-hosted git repository.
kvn pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix-ingress-controller.git
The following commit(s) were added to refs/heads/master by this push:
new f924022 fix: broken unit test cases for pkg/cmd/ingress (#169)
f924022 is described below
commit f924022b559c66028e11bf2dd9f963b74bf12ae3
Author: Alex Zhang <[email protected]>
AuthorDate: Mon Jan 11 11:25:13 2021 +0800
fix: broken unit test cases for pkg/cmd/ingress (#169)
---
cmd/ingress/ingress_test.go | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)
diff --git a/cmd/ingress/ingress_test.go b/cmd/ingress/ingress_test.go
index 47494c5..473c367 100644
--- a/cmd/ingress/ingress_test.go
+++ b/cmd/ingress/ingress_test.go
@@ -19,6 +19,7 @@ import (
"bytes"
"encoding/json"
"fmt"
+ "math/rand"
"os"
"strings"
"syscall"
@@ -42,6 +43,10 @@ type fields struct {
Message string
}
+func init() {
+ rand.Seed(int64(time.Now().Nanosecond()))
+}
+
func (fws *fakeWriteSyncer) Sync() error {
return nil
}
@@ -58,12 +63,18 @@ func (fws *fakeWriteSyncer) bytes() (p []byte) {
return
}
+func getRandomListen() string {
+ port := rand.Intn(10000) + 10000
+ return fmt.Sprintf("127.0.0.1:%d", port)
+}
+
func TestSignalHandler(t *testing.T) {
cmd := NewIngressCommand()
+ listen := getRandomListen()
cmd.SetArgs([]string{
"--log-level", "debug",
- "--log-output", "./test.log",
- "--http-listen", "127.0.0.1:16780",
+ "--log-output", "stderr",
+ "--http-listen", listen,
"--enable-profiling",
"--kubeconfig", "/foo/bar/baz",
"--resync-interval", "24h",
@@ -92,11 +103,12 @@ func TestSignalHandler(t *testing.T) {
}
func TestNewIngressCommandEffectiveLog(t *testing.T) {
+ listen := getRandomListen()
cmd := NewIngressCommand()
cmd.SetArgs([]string{
"--log-level", "debug",
"--log-output", "./test.log",
- "--http-listen", "127.0.0.1:16780",
+ "--http-listen", listen,
"--enable-profiling",
"--kubeconfig", "/foo/bar/baz",
"--resync-interval", "24h",
@@ -134,7 +146,7 @@ func TestNewIngressCommandEffectiveLog(t *testing.T) {
assert.Equal(t, cfg.LogOutput, "./test.log")
assert.Equal(t, cfg.LogLevel, "debug")
- assert.Equal(t, cfg.HTTPListen, "127.0.0.1:16780")
+ assert.Equal(t, cfg.HTTPListen, listen)
assert.Equal(t, cfg.EnableProfiling, true)
assert.Equal(t, cfg.Kubernetes.Kubeconfig, "/foo/bar/baz")
assert.Equal(t, cfg.Kubernetes.ResyncInterval, types.TimeDuration{24 *
time.Hour})