...

Source file src/github.com/opentracing/opentracing-go/log/field_test.go

Documentation: github.com/opentracing/opentracing-go/log

     1  package log
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  )
     7  
     8  func TestFieldString(t *testing.T) {
     9  	testCases := []struct {
    10  		field    Field
    11  		expected string
    12  	}{
    13  		{
    14  			field:    String("key", "value"),
    15  			expected: "key:value",
    16  		},
    17  		{
    18  			field:    Bool("key", true),
    19  			expected: "key:true",
    20  		},
    21  		{
    22  			field:    Int("key", 5),
    23  			expected: "key:5",
    24  		},
    25  		{
    26  			field:    Error(fmt.Errorf("err msg")),
    27  			expected: "error.object:err msg",
    28  		},
    29  		{
    30  			field:    Error(nil),
    31  			expected: "error.object:<nil>",
    32  		},
    33  		{
    34  			field:    Noop(),
    35  			expected: ":<nil>",
    36  		},
    37  		{
    38  			field:    Event("test"),
    39  			expected: "event:test",
    40  		},
    41  		{
    42  			field:    Message("test2"),
    43  			expected: "message:test2",
    44  		},
    45  	}
    46  	for i, tc := range testCases {
    47  		if str := tc.field.String(); str != tc.expected {
    48  			t.Errorf("%d: expected '%s', got '%s'", i, tc.expected, str)
    49  		}
    50  	}
    51  }
    52  
    53  func TestNoopDoesNotMarshal(t *testing.T) {
    54  	mockEncoder := struct {
    55  		Encoder
    56  	}{}
    57  	f := Noop()
    58  	f.Marshal(mockEncoder) // panics if any Encoder method is invoked
    59  }
    60  

View as plain text