rpcpubserver_test.go 551 B

123456789101112131415161718192021222324252627282930313233
  1. package internal
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. "github.com/tal-tech/go-zero/core/netx"
  6. )
  7. func TestFigureOutListenOn(t *testing.T) {
  8. tests := []struct {
  9. input string
  10. expect string
  11. }{
  12. {
  13. input: "192.168.0.5:1234",
  14. expect: "192.168.0.5:1234",
  15. },
  16. {
  17. input: "0.0.0.0:8080",
  18. expect: netx.InternalIp() + ":8080",
  19. },
  20. {
  21. input: ":8080",
  22. expect: netx.InternalIp() + ":8080",
  23. },
  24. }
  25. for _, test := range tests {
  26. val := figureOutListenOn(test.input)
  27. assert.Equal(t, test.expect, val)
  28. }
  29. }