|
| 1 | +package redisotel |
| 2 | + |
| 3 | +import ( |
| 4 | + "reflect" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "go.opentelemetry.io/otel/attribute" |
| 8 | +) |
| 9 | + |
| 10 | +func Test_poolStatsAttrs(t *testing.T) { |
| 11 | + t.Parallel() |
| 12 | + type args struct { |
| 13 | + conf *config |
| 14 | + } |
| 15 | + tests := []struct { |
| 16 | + name string |
| 17 | + args args |
| 18 | + wantPoolAttrs attribute.Set |
| 19 | + wantIdleAttrs attribute.Set |
| 20 | + wantUsedAttrs attribute.Set |
| 21 | + }{ |
| 22 | + { |
| 23 | + name: "#3122", |
| 24 | + args: func() args { |
| 25 | + conf := &config{ |
| 26 | + attrs: make([]attribute.KeyValue, 0, 4), |
| 27 | + } |
| 28 | + conf.attrs = append(conf.attrs, attribute.String("foo1", "bar1"), attribute.String("foo2", "bar2")) |
| 29 | + conf.attrs = append(conf.attrs, attribute.String("pool.name", "pool1")) |
| 30 | + return args{conf: conf} |
| 31 | + }(), |
| 32 | + wantPoolAttrs: attribute.NewSet(attribute.String("foo1", "bar1"), attribute.String("foo2", "bar2"), |
| 33 | + attribute.String("pool.name", "pool1")), |
| 34 | + wantIdleAttrs: attribute.NewSet(attribute.String("foo1", "bar1"), attribute.String("foo2", "bar2"), |
| 35 | + attribute.String("pool.name", "pool1"), attribute.String("state", "idle")), |
| 36 | + wantUsedAttrs: attribute.NewSet(attribute.String("foo1", "bar1"), attribute.String("foo2", "bar2"), |
| 37 | + attribute.String("pool.name", "pool1"), attribute.String("state", "used")), |
| 38 | + }, |
| 39 | + } |
| 40 | + for _, tt := range tests { |
| 41 | + t.Run(tt.name, func(t *testing.T) { |
| 42 | + gotPoolAttrs, gotIdleAttrs, gotUsedAttrs := poolStatsAttrs(tt.args.conf) |
| 43 | + if !reflect.DeepEqual(gotPoolAttrs, tt.wantPoolAttrs) { |
| 44 | + t.Errorf("poolStatsAttrs() gotPoolAttrs = %v, want %v", gotPoolAttrs, tt.wantPoolAttrs) |
| 45 | + } |
| 46 | + if !reflect.DeepEqual(gotIdleAttrs, tt.wantIdleAttrs) { |
| 47 | + t.Errorf("poolStatsAttrs() gotIdleAttrs = %v, want %v", gotIdleAttrs, tt.wantIdleAttrs) |
| 48 | + } |
| 49 | + if !reflect.DeepEqual(gotUsedAttrs, tt.wantUsedAttrs) { |
| 50 | + t.Errorf("poolStatsAttrs() gotUsedAttrs = %v, want %v", gotUsedAttrs, tt.wantUsedAttrs) |
| 51 | + } |
| 52 | + }) |
| 53 | + } |
| 54 | +} |
0 commit comments