github.com/jiasir/deis@v1.12.2/logger/drain/factory_test.go (about)

     1  package drain
     2  
     3  import (
     4  	"fmt"
     5  	"reflect"
     6  	"testing"
     7  )
     8  
     9  func TestGetUsingInvalidValues(t *testing.T) {
    10  	drainStrs := []string{"bogus"}
    11  	for _, drainStr := range drainStrs {
    12  		_, err := NewDrain(drainStr)
    13  		if err == nil || err.Error() != fmt.Sprintf("Cannot construct a drain for URL: '%s'", drainStr) {
    14  			t.Error("Did not receive expected error message")
    15  		}
    16  	}
    17  }
    18  
    19  func TestGetUsingEmptyString(t *testing.T) {
    20  	d, err := NewDrain("")
    21  	if err != nil {
    22  		t.Error(err)
    23  	}
    24  	// Should return nil by default.  nil means no drain-- which is valid.
    25  	if d != nil {
    26  		dType := reflect.TypeOf(d).String()
    27  		t.Errorf("Expected a nil drain, but got a %s", dType)
    28  	}
    29  }
    30  
    31  func TestGetUdpDrain(t *testing.T) {
    32  	d, err := NewDrain("udp://my-awesome-log-server:514")
    33  	if err != nil {
    34  		t.Error(err)
    35  	}
    36  	if want, got := "*simple.logDrain", reflect.TypeOf(d).String(); want != got {
    37  		t.Errorf("Expected a %s, but got a %s", want, got)
    38  	}
    39  }
    40  
    41  func TestGetSyslogDrain(t *testing.T) {
    42  	d, err := NewDrain("syslog://my-awesome-log-server:514")
    43  	if err != nil {
    44  		t.Error(err)
    45  	}
    46  	if want, got := "*simple.logDrain", reflect.TypeOf(d).String(); want != got {
    47  		t.Errorf("Expected a %s, but got a %s", want, got)
    48  	}
    49  }
    50  
    51  func TestGetTcpDrain(t *testing.T) {
    52  	d, err := NewDrain("tcp://my-awesome-log-server:12345")
    53  	if err != nil {
    54  		t.Error(err)
    55  	}
    56  	if want, got := "*simple.logDrain", reflect.TypeOf(d).String(); want != got {
    57  		t.Errorf("Expected a %s, but got a %s", want, got)
    58  	}
    59  }