File: builder_test.go

package info (click to toggle)
golang-github-getsentry-sentry-go 0.40.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,900 kB
  • sloc: makefile: 85; sh: 21
file content (88 lines) | stat: -rw-r--r-- 1,779 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package attribute

import (
	"testing"
)

func TestBuilder(t *testing.T) {
	k := "key"
	for _, testcase := range []struct {
		name      string
		value     Builder
		wantType  Type
		wantValue interface{}
	}{
		{
			name:      "Bool correctly returns a boolean builder",
			value:     Bool(k, true),
			wantType:  BOOL,
			wantValue: true,
		},
		{
			name:      "Int64() correctly returns an builder",
			value:     Int64(k, 42),
			wantType:  INT64,
			wantValue: int64(42),
		},
		{
			name:      "Int() correctly returns an builder",
			value:     Int(k, 42),
			wantType:  INT64,
			wantValue: int64(42),
		},
		{
			name:      "Float64() correctly returns a float64 builder",
			value:     Float64(k, 42.1),
			wantType:  FLOAT64,
			wantValue: 42.1,
		},
		{
			name:      "String() correctly returns a string builder",
			value:     String(k, "foo"),
			wantType:  STRING,
			wantValue: "foo",
		},
	} {
		if testcase.value.Value.Type() != testcase.wantType {
			t.Errorf("wrong value type, got %#v, expected %#v", testcase.value.Value.Type(), testcase.wantType)
		}
	}
}

func TestBuilder_Valid(t *testing.T) {
	for _, tt := range []struct {
		name      string
		builder   Builder
		wantValid bool
	}{
		{
			name: "valid key and value are valid",
			builder: Builder{
				Key:   "key",
				Value: BoolValue(true),
			},
			wantValid: true,
		},
		{
			name: "empty key should be invalid",
			builder: Builder{
				Key:   "",
				Value: IntValue(42),
			},
			wantValid: false,
		},
		{
			name: "invalid value should be invalid",
			builder: Builder{
				Key:   "key",
				Value: Value{},
			},
			wantValid: false,
		},
	} {
		valid := tt.builder.Valid()
		if tt.wantValid != valid {
			t.Errorf("expected builder valid to be %v, got %v", tt.wantValid, valid)
		}
	}
}