.gitignore added
[dotfiles/.git] / .config / coc / extensions / coc-go-data / tools / pkg / mod / golang.org / x / tools@v0.1.1-0.20210319172145-bda8f5cee399 / internal / event / export / ocagent / wire / metrics_test.go
diff --git a/.config/coc/extensions/coc-go-data/tools/pkg/mod/golang.org/x/tools@v0.1.1-0.20210319172145-bda8f5cee399/internal/event/export/ocagent/wire/metrics_test.go b/.config/coc/extensions/coc-go-data/tools/pkg/mod/golang.org/x/tools@v0.1.1-0.20210319172145-bda8f5cee399/internal/event/export/ocagent/wire/metrics_test.go
new file mode 100644 (file)
index 0000000..34247ad
--- /dev/null
@@ -0,0 +1,80 @@
+// Copyright 2020 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package wire
+
+import (
+       "reflect"
+       "testing"
+)
+
+func TestMarshalJSON(t *testing.T) {
+       tests := []struct {
+               name string
+               pt   *Point
+               want string
+       }{
+               {
+                       "PointInt64",
+                       &Point{
+                               Value: PointInt64Value{
+                                       Int64Value: 5,
+                               },
+                       },
+                       `{"int64Value":5}`,
+               },
+               {
+                       "PointDouble",
+                       &Point{
+                               Value: PointDoubleValue{
+                                       DoubleValue: 3.14,
+                               },
+                       },
+                       `{"doubleValue":3.14}`,
+               },
+               {
+                       "PointDistribution",
+                       &Point{
+                               Value: PointDistributionValue{
+                                       DistributionValue: &DistributionValue{
+                                               Count: 3,
+                                               Sum:   10,
+                                               Buckets: []*Bucket{
+                                                       {
+                                                               Count: 1,
+                                                       },
+                                                       {
+                                                               Count: 2,
+                                                       },
+                                               },
+                                               BucketOptions: &BucketOptionsExplicit{
+                                                       Bounds: []float64{
+                                                               0, 5,
+                                                       },
+                                               },
+                                       },
+                               },
+                       },
+                       `{"distributionValue":{"count":3,"sum":10,"bucket_options":{"explicit":{"bounds":[0,5]}},"buckets":[{"count":1},{"count":2}]}}`,
+               },
+               {
+                       "nil point",
+                       nil,
+                       `null`,
+               },
+       }
+
+       for _, tt := range tests {
+               t.Run(tt.name, func(t *testing.T) {
+                       buf, err := tt.pt.MarshalJSON()
+                       if err != nil {
+                               t.Fatalf("Got:\n%v\nWant:\n%v", err, nil)
+                       }
+                       got := string(buf)
+                       if !reflect.DeepEqual(got, tt.want) {
+                               t.Fatalf("Got:\n%s\nWant:\n%s", got, tt.want)
+                       }
+               })
+       }
+}