bosun.org@v0.0.0-20210513094433-e25bc3e69a1f/cmd/bosun/database/test/metric_metadata_test.go (about)

     1  package dbtest
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func TestMetricMetadata_RoundTrip(t *testing.T) {
     8  	metric := randString(5)
     9  	if err := testData.Metadata().PutMetricMetadata(metric, "desc", "cpu of a server"); err != nil {
    10  		t.Fatal(err)
    11  	}
    12  	if err := testData.Metadata().PutMetricMetadata(metric, "unit", "pct"); err != nil {
    13  		t.Fatal(err)
    14  	}
    15  	meta, err := testData.Metadata().GetMetricMetadata(metric)
    16  	if err != nil {
    17  		t.Fatal(err)
    18  	}
    19  	if meta == nil {
    20  		t.Fatal("did not find metadata I put in.")
    21  	}
    22  	if meta.Desc != "cpu of a server" {
    23  		t.Fatal("Wrong description.")
    24  	}
    25  	if meta.Unit != "pct" {
    26  		t.Fatal("Wrong Unit.")
    27  	}
    28  }
    29  
    30  func TestMetricMetadata_NoneExists(t *testing.T) {
    31  	meta, err := testData.Metadata().GetMetricMetadata("asfaklsfjlkasjf")
    32  	if err != nil {
    33  		t.Fatal(err)
    34  	}
    35  	if meta != nil {
    36  		t.Fatal("Should return nil if not exist")
    37  	}
    38  }
    39  
    40  func TestMetricMetadata_BadField(t *testing.T) {
    41  	if err := testData.Metadata().PutMetricMetadata(randString(7), "desc1", "foo"); err == nil {
    42  		t.Fatal("Expected failure to set bad metric metadata field")
    43  	}
    44  }