add GetAddressAndDialer unit test
Signed-off-by: zhangsheng02 <sheng.zhang@daocloud.io>
This commit is contained in:
		 zhangsheng02
					zhangsheng02
				
			
				
					committed by
					
						 zhangsheng02
						zhangsheng02
					
				
			
			
				
	
			
			
			 zhangsheng02
						zhangsheng02
					
				
			
						parent
						
							70f68dbf74
						
					
				
				
					commit
					14d2440b87
				
			| @@ -133,3 +133,41 @@ func TestIsUnixDomainSocket(t *testing.T) { | ||||
| 		assert.Equal(t, result, test.expectSocket, "Unexpected result from IsUnixDomainSocket: %v for %s", result, test.label) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func TestGetAddressAndDialer(t *testing.T) { | ||||
| 	tests := []struct { | ||||
| 		endpoint     string | ||||
| 		expectError  bool | ||||
| 		expectedAddr string | ||||
| 	}{ | ||||
| 		{ | ||||
| 			endpoint:     "unix:///tmp/s1.sock", | ||||
| 			expectError:  false, | ||||
| 			expectedAddr: "/tmp/s1.sock", | ||||
| 		}, | ||||
| 		{ | ||||
| 			endpoint:     "unix:///tmp/f6.sock", | ||||
| 			expectError:  false, | ||||
| 			expectedAddr: "/tmp/f6.sock", | ||||
| 		}, | ||||
| 		{ | ||||
| 			endpoint:    "tco:/localhost:9090", | ||||
| 			expectError: true, | ||||
| 		}, | ||||
| 		{ | ||||
| 			// The misspelling is intentional to make it error | ||||
| 			endpoint:    "htta://free-test.com", | ||||
| 			expectError: true, | ||||
| 		}, | ||||
| 	} | ||||
| 	for _, test := range tests { | ||||
| 		// just test addr and err | ||||
| 		addr, _, err := GetAddressAndDialer(test.endpoint) | ||||
| 		if test.expectError { | ||||
| 			assert.NotNil(t, err, "expected error during parsing %s", test.endpoint) | ||||
| 			continue | ||||
| 		} | ||||
| 		assert.Nil(t, err, "expected no error during parsing %s", test.endpoint) | ||||
| 		assert.Equal(t, test.expectedAddr, addr) | ||||
| 	} | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user