github.com/thanos-io/thanos@v0.32.5/pkg/discovery/cache/cache_test.go (about)

     1  // Copyright (c) The Thanos Authors.
     2  // Licensed under the Apache License 2.0.
     3  
     4  package cache
     5  
     6  import (
     7  	"reflect"
     8  	"sort"
     9  	"testing"
    10  
    11  	"github.com/prometheus/common/model"
    12  	"github.com/prometheus/prometheus/discovery/targetgroup"
    13  )
    14  
    15  func TestCacheAddresses(t *testing.T) {
    16  	tgs := make(map[string]*targetgroup.Group)
    17  	tgs["g1"] = &targetgroup.Group{
    18  		Targets: []model.LabelSet{
    19  			{model.AddressLabel: "localhost:9090"},
    20  			{model.AddressLabel: "localhost:9091"},
    21  			{model.AddressLabel: "localhost:9092"},
    22  		},
    23  	}
    24  	tgs["g2"] = &targetgroup.Group{
    25  		Targets: []model.LabelSet{
    26  			{model.AddressLabel: "localhost:9091"},
    27  			{model.AddressLabel: "localhost:9092"},
    28  			{model.AddressLabel: "localhost:9093"},
    29  		},
    30  	}
    31  
    32  	c := &Cache{tgs: tgs}
    33  
    34  	expected := []string{
    35  		"localhost:9090",
    36  		"localhost:9091",
    37  		"localhost:9092",
    38  		"localhost:9093",
    39  	}
    40  
    41  	got := c.Addresses()
    42  	sort.Strings(got)
    43  	if !reflect.DeepEqual(got, expected) {
    44  		t.Errorf("expected %v, want %v", got, expected)
    45  	}
    46  }