github.com/la5nta/wl2k-go@v0.11.8/transport/url_test.go (about)

     1  // Copyright 2016 Martin Hebnes Pedersen (LA5NTA). All rights reserved.
     2  // Use of this source code is governed by the MIT-license that can be
     3  // found in the LICENSE file.
     4  
     5  package transport
     6  
     7  import (
     8  	"net/url"
     9  	"reflect"
    10  	"testing"
    11  )
    12  
    13  func TestParseURL(t *testing.T) {
    14  	tests := map[string]URL{
    15  		"ax25:///LA5NTA":                       {Scheme: "ax25", Target: "LA5NTA", Digis: []string{}, Params: url.Values{}},
    16  		"ax25:///la5nta":                       {Scheme: "ax25", Target: "LA5NTA", Digis: []string{}, Params: url.Values{}},
    17  		"ax25:///LA1B-10/LA5NTA":               {Scheme: "ax25", Target: "LA5NTA", Digis: []string{"LA1B-10"}, Params: url.Values{}},
    18  		"ax25://axport/LA5NTA":                 {Scheme: "ax25", Host: "axport", Target: "LA5NTA", Digis: []string{}, Params: url.Values{}},
    19  		"ax25://0/LA5NTA":                      {Scheme: "ax25", Host: "0", Target: "LA5NTA", Digis: []string{}, Params: url.Values{}},
    20  		"serial-tnc:///LA5NTA?host=/dev/ttyS0": {Scheme: "serial-tnc", Host: "/dev/ttyS0", Target: "LA5NTA", Digis: []string{}, Params: url.Values{"host": []string{"/dev/ttyS0"}}},
    21  
    22  		"telnet://LA5NTA:CMSTelnet@server.winlink.org:8772/wl2k": {
    23  			Scheme: "telnet",
    24  			Host:   "server.winlink.org:8772",
    25  			Target: "WL2K",
    26  			User:   url.UserPassword("LA5NTA", "CMSTelnet"),
    27  			Digis:  []string{},
    28  			Params: url.Values{},
    29  		},
    30  	}
    31  
    32  	for str, expect := range tests {
    33  		got, err := ParseURL(str)
    34  		if err != nil {
    35  			t.Errorf("'%s': Unexpected error (%s)", str, err)
    36  			continue
    37  		}
    38  
    39  		if !reflect.DeepEqual(*got, expect) {
    40  			t.Errorf("'%s':\n\tGot %#v\n\tExpect %#v", str, *got, expect)
    41  		}
    42  	}
    43  
    44  	if _, err := ParseURL("ax25:///"); err == nil {
    45  		t.Errorf("Expected error on no target")
    46  	}
    47  }