GoPLS Viewer

Home|gopls/internal/event/export/ocagent/wire/metrics_test.go
1// Copyright 2020 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5package wire
6
7import (
8    "reflect"
9    "testing"
10)
11
12func TestMarshalJSON(t *testing.T) {
13    tests := []struct {
14        name string
15        pt   *Point
16        want string
17    }{
18        {
19            "PointInt64",
20            &Point{
21                ValuePointInt64Value{
22                    Int64Value5,
23                },
24            },
25            `{"int64Value":5}`,
26        },
27        {
28            "PointDouble",
29            &Point{
30                ValuePointDoubleValue{
31                    DoubleValue3.14,
32                },
33            },
34            `{"doubleValue":3.14}`,
35        },
36        {
37            "PointDistribution",
38            &Point{
39                ValuePointDistributionValue{
40                    DistributionValue: &DistributionValue{
41                        Count3,
42                        Sum:   10,
43                        Buckets: []*Bucket{
44                            {
45                                Count1,
46                            },
47                            {
48                                Count2,
49                            },
50                        },
51                        BucketOptions: &BucketOptionsExplicit{
52                            Bounds: []float64{
53                                05,
54                            },
55                        },
56                    },
57                },
58            },
59            `{"distributionValue":{"count":3,"sum":10,"bucket_options":{"explicit":{"bounds":[0,5]}},"buckets":[{"count":1},{"count":2}]}}`,
60        },
61        {
62            "nil point",
63            nil,
64            `null`,
65        },
66    }
67
68    for _tt := range tests {
69        t.Run(tt.name, func(t *testing.T) {
70            buferr := tt.pt.MarshalJSON()
71            if err != nil {
72                t.Fatalf("Got:\n%v\nWant:\n%v"errnil)
73            }
74            got := string(buf)
75            if !reflect.DeepEqual(gottt.want) {
76                t.Fatalf("Got:\n%s\nWant:\n%s"gottt.want)
77            }
78        })
79    }
80}
81
MembersX
TestMarshalJSON.RangeStmt_1136.tt
TestMarshalJSON.RangeStmt_1136.BlockStmt.BlockStmt.err
TestMarshalJSON.RangeStmt_1136.BlockStmt.BlockStmt.got
TestMarshalJSON.RangeStmt_1136.BlockStmt.BlockStmt.buf
reflect
testing
TestMarshalJSON
TestMarshalJSON.t
TestMarshalJSON.tests
Members
X