github.com/mundipagg/tracer-splunk-writer@v1.0.6/entry_test.go (about)

     1  package splunk
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func TestEntry_Add(t *testing.T) {
    10  	t.Parallel()
    11  	is := assert.New(t)
    12  	subject := Entry{
    13  		"A": 15,
    14  	}
    15  	subject.Add("B", 16)
    16  	expected := Entry{
    17  		"A": 15,
    18  		"B": 16,
    19  	}
    20  	is.Equal(expected, subject, "it should update the entry")
    21  }
    22  
    23  func TestNew(t *testing.T) {
    24  	t.Parallel()
    25  	t.Run("when an interface slice is given", func(t *testing.T) {
    26  		t.Parallel()
    27  		is := assert.New(t)
    28  		type S struct {
    29  			B int
    30  		}
    31  		items := []interface{}{
    32  			"A",
    33  			Entry{
    34  				"X": "Y",
    35  			},
    36  			nil,
    37  			S{15},
    38  			&S{16},
    39  		}
    40  		actual := NewEntry(items)
    41  		expected := Entry{
    42  			"string": "A",
    43  			"X":      "Y",
    44  			"S":      S{15},
    45  			"S1":     S{16},
    46  		}
    47  		is.Equal(expected, actual, "it should return the expected entry")
    48  	})
    49  	t.Run("when multiple items are given", func(t *testing.T) {
    50  		t.Parallel()
    51  		is := assert.New(t)
    52  		type S struct {
    53  			B int
    54  		}
    55  		items := []interface{}{
    56  			"A",
    57  			Entry{
    58  				"X": "Y",
    59  			},
    60  			S{15},
    61  			&S{16},
    62  		}
    63  		actual := NewEntry(items...)
    64  		expected := Entry{
    65  			"string": "A",
    66  			"X":      "Y",
    67  			"S":      S{15},
    68  			"S1":     S{16},
    69  		}
    70  		is.Equal(expected, actual, "it should return the expected entry")
    71  	})
    72  }
    73  
    74  func TestMerge(t *testing.T) {
    75  	t.Parallel()
    76  	is := assert.New(t)
    77  	inputA := Entry{
    78  		"A": 15,
    79  		"B": 16,
    80  		"C": 17,
    81  	}
    82  	inputB := Entry{
    83  		"A": 20,
    84  		"E": 21,
    85  		"F": 22,
    86  	}
    87  	actual := Merge(inputA, inputB)
    88  	expected := Entry{
    89  		"A":  15,
    90  		"B":  16,
    91  		"C":  17,
    92  		"A1": 20,
    93  		"E":  21,
    94  		"F":  22,
    95  	}
    96  	is.Equal(expected, actual, "it should return the expected value")
    97  }