-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathstore_test.go
55 lines (44 loc) · 1.94 KB
/
store_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.
package autodiscovery
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/DataDog/datadog-agent/pkg/autodiscovery/integration"
)
func countConfigsForTemplate(s *store, template string) int {
return len(s.templateToConfigs[template])
}
func countConfigsForService(s *store, service string) int {
return len(s.serviceToConfigs[service])
}
func TestServiceToConfig(t *testing.T) {
s := newStore()
service := dummyService{
ID: "a5901276aed1",
ADIdentifiers: []string{"redis"},
Hosts: map[string]string{"bridge": "127.0.0.1"},
}
s.addConfigForService(service.GetServiceID(), integration.Config{Name: "foo"})
s.addConfigForService(service.GetServiceID(), integration.Config{Name: "bar"})
assert.Equal(t, countConfigsForService(s, service.GetServiceID()), 2)
s.removeConfigsForService(service.GetServiceID())
s.addConfigForService(service.GetServiceID(), integration.Config{Name: "foo"})
assert.Equal(t, countConfigsForService(s, service.GetServiceID()), 1)
}
func TestTemplateToConfig(t *testing.T) {
s := newStore()
s.addConfigForTemplate("digest1", integration.Config{Name: "foo"})
s.addConfigForTemplate("digest1", integration.Config{Name: "bar"})
s.addConfigForTemplate("digest2", integration.Config{Name: "foo"})
assert.Equal(t, countConfigsForTemplate(s, "digest1"), 2)
assert.Equal(t, countConfigsForTemplate(s, "digest2"), 1)
s.removeConfigsForTemplate("digest1")
assert.Equal(t, countConfigsForTemplate(s, "digest1"), 0)
assert.Equal(t, countConfigsForTemplate(s, "digest2"), 1)
s.addConfigForTemplate("digest1", integration.Config{Name: "foo"})
assert.Equal(t, countConfigsForTemplate(s, "digest1"), 1)
assert.Equal(t, countConfigsForTemplate(s, "digest2"), 1)
}