preamble_test.go 660 B

123456789101112131415161718192021222324252627282930
  1. package sshserver
  2. import (
  3. "github.com/stretchr/testify/assert"
  4. "github.com/stretchr/testify/require"
  5. "testing"
  6. )
  7. func TestHasPort(t *testing.T) {
  8. type testCase struct {
  9. input string
  10. expectedOutput string
  11. }
  12. tests := []testCase{
  13. {"localhost", "localhost:22"},
  14. {"other.addr:22", "other.addr:22"},
  15. {"[2001:db8::1]:8080", "[2001:db8::1]:8080"},
  16. {"[::1]", "[::1]:22"},
  17. {"2001:0db8:3c4d:0015:0000:0000:1a2f:1234", "[2001:0db8:3c4d:0015:0000:0000:1a2f:1234]:22"},
  18. {"::1", "[::1]:22"},
  19. }
  20. for _, test := range tests {
  21. out, err := canonicalizeDest(test.input)
  22. require.Nil(t, err)
  23. assert.Equal(t, test.expectedOutput, out)
  24. }
  25. }