github.com/hyperledger-labs/bdls@v2.1.1+incompatible/common/metrics/gendoc/options_test.go (about)

     1  /*
     2  Copyright IBM Corp. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package gendoc_test
     8  
     9  import (
    10  	"github.com/hyperledger/fabric/common/metrics"
    11  	"github.com/hyperledger/fabric/common/metrics/gendoc"
    12  	. "github.com/onsi/ginkgo"
    13  	. "github.com/onsi/gomega"
    14  )
    15  
    16  var _ = Describe("Options", func() {
    17  	It("finds standard options", func() {
    18  		f, err := ParseFile("testdata/basic.go")
    19  		Expect(err).NotTo(HaveOccurred())
    20  		Expect(f).NotTo(BeNil())
    21  
    22  		options, err := gendoc.FileOptions(f)
    23  		Expect(err).NotTo(HaveOccurred())
    24  		Expect(options).To(HaveLen(3))
    25  
    26  		for _, opt := range options {
    27  			switch opt := opt.(type) {
    28  			case metrics.CounterOpts:
    29  				Expect(opt).To(Equal(metrics.CounterOpts{
    30  					Namespace:  "fixtures",
    31  					Name:       "counter",
    32  					Help:       "This is some help text that is more than a few words long. It really can be quite long. Really long.",
    33  					LabelNames: []string{"label_one", "label_two", "missing_help"},
    34  					LabelHelp: map[string]string{
    35  						"label_one": "this is a really cool label that is the first of many",
    36  						"label_two": "short and sweet",
    37  					},
    38  					StatsdFormat: "%{#fqname}.%{label_one}.%{label_two}",
    39  				}))
    40  
    41  			case metrics.GaugeOpts:
    42  				Expect(opt).To(Equal(metrics.GaugeOpts{
    43  					Namespace:    "fixtures",
    44  					Name:         "gauge",
    45  					Help:         "This is some help text that is more than a few words long. It really can be quite long. Really long. This is some help text that is more than a few words long. It really can be quite long. Really long.",
    46  					LabelNames:   []string{"label_one", "label_two"},
    47  					StatsdFormat: "%{#fqname}.%{label_one}.%{label_two}",
    48  				}))
    49  
    50  			case metrics.HistogramOpts:
    51  				Expect(opt).To(Equal(metrics.HistogramOpts{
    52  					Namespace:  "fixtures",
    53  					Name:       "histogram",
    54  					Help:       "This is some help text",
    55  					LabelNames: []string{"label_one", "label_two"},
    56  					LabelHelp: map[string]string{
    57  						"label_one": "This is a very long help message for label_one, which could be really, really long, and it may never end...",
    58  					},
    59  					StatsdFormat: "%{#fqname}.%{label_one}.%{label_two}",
    60  				}))
    61  
    62  			default:
    63  				Fail("unexpected option")
    64  			}
    65  		}
    66  	})
    67  
    68  	It("finds options that use named imports", func() {
    69  		f, err := ParseFile("testdata/named_import.go")
    70  		Expect(err).NotTo(HaveOccurred())
    71  		Expect(f).NotTo(BeNil())
    72  
    73  		options, err := gendoc.FileOptions(f)
    74  		Expect(err).NotTo(HaveOccurred())
    75  		Expect(options).To(HaveLen(3))
    76  	})
    77  
    78  	It("ignores variables that are tagged", func() {
    79  		f, err := ParseFile("testdata/ignored.go")
    80  		Expect(err).NotTo(HaveOccurred())
    81  		Expect(f).NotTo(BeNil())
    82  
    83  		options, err := gendoc.FileOptions(f)
    84  		Expect(err).NotTo(HaveOccurred())
    85  		Expect(options).To(BeEmpty())
    86  	})
    87  })