go.etcd.io/etcd@v3.3.27+incompatible/pkg/flags/urls_test.go (about)

     1  // Copyright 2015 The etcd Authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package flags
    16  
    17  import (
    18  	"testing"
    19  )
    20  
    21  func TestValidateURLsValueBad(t *testing.T) {
    22  	tests := []string{
    23  		// bad IP specification
    24  		":2379",
    25  		"127.0:8080",
    26  		"123:456",
    27  		// bad port specification
    28  		"127.0.0.1:foo",
    29  		"127.0.0.1:",
    30  		// unix sockets not supported
    31  		"unix://",
    32  		"unix://tmp/etcd.sock",
    33  		// bad strings
    34  		"somewhere",
    35  		"234#$",
    36  		"file://foo/bar",
    37  		"http://hello/asdf",
    38  		"http://10.1.1.1",
    39  	}
    40  	for i, in := range tests {
    41  		u := URLsValue{}
    42  		if err := u.Set(in); err == nil {
    43  			t.Errorf(`#%d: unexpected nil error for in=%q`, i, in)
    44  		}
    45  	}
    46  }
    47  
    48  func TestValidateURLsValueGood(t *testing.T) {
    49  	tests := []string{
    50  		"https://1.2.3.4:8080",
    51  		"http://10.1.1.1:80",
    52  		"http://localhost:80",
    53  		"http://:80",
    54  	}
    55  	for i, in := range tests {
    56  		u := URLsValue{}
    57  		if err := u.Set(in); err != nil {
    58  			t.Errorf("#%d: err=%v, want nil for in=%q", i, err, in)
    59  		}
    60  	}
    61  }