agent: test coverage loading service/check tokens from persisted files

This commit is contained in:
Ryan Uber 2015-04-27 22:46:01 -07:00
parent 1264f7edf3
commit 1557f7f19c
2 changed files with 18 additions and 2 deletions

View File

@ -1029,6 +1029,7 @@ func (a *Agent) loadChecks(conf *Config) error {
if err := json.Unmarshal(content, &p); err != nil {
return err
}
a.state.AddCheckToken(p.Check.CheckID, p.Token)
if _, ok := a.state.checks[p.Check.CheckID]; ok {
// Purge previously persisted check. This allows config to be

View File

@ -521,6 +521,9 @@ func TestAgent_PersistService(t *testing.T) {
file := filepath.Join(agent.config.DataDir, servicesDir, stringHash(svc.ID))
// Configure a service token
agent.state.AddServiceToken(svc.ID, "hello")
// Check is not persisted unless requested
if err := agent.AddService(svc, nil, false); err != nil {
t.Fatalf("err: %v", err)
@ -538,7 +541,10 @@ func TestAgent_PersistService(t *testing.T) {
t.Fatalf("err: %s", err)
}
expected, err := json.Marshal(&persistedService{Service: svc})
expected, err := json.Marshal(&persistedService{
Token: "hello",
Service: svc,
})
if err != nil {
t.Fatalf("err: %s", err)
}
@ -561,6 +567,9 @@ func TestAgent_PersistService(t *testing.T) {
if _, ok := agent2.state.services[svc.ID]; !ok {
t.Fatalf("bad: %#v", agent2.state.services)
}
if agent2.state.serviceTokens[svc.ID] != "hello" {
t.Fatalf("bad: %#v", agent2.state.services[svc.ID])
}
}
func TestAgent_PurgeService(t *testing.T) {
@ -667,6 +676,9 @@ func TestAgent_PersistCheck(t *testing.T) {
file := filepath.Join(agent.config.DataDir, checksDir, stringHash(check.CheckID))
// Configure a service registration token
agent.state.AddCheckToken(check.CheckID, "hello")
// Not persisted if not requested
if err := agent.AddCheck(check, chkType, false); err != nil {
t.Fatalf("err: %v", err)
@ -684,7 +696,7 @@ func TestAgent_PersistCheck(t *testing.T) {
t.Fatalf("err: %s", err)
}
p := persistedCheck{check, chkType, ""}
p := persistedCheck{check, chkType, "hello"}
expected, err := json.Marshal(p)
if err != nil {
t.Fatalf("err: %s", err)
@ -717,6 +729,9 @@ func TestAgent_PersistCheck(t *testing.T) {
if _, ok := agent2.checkMonitors[p.Check.CheckID]; !ok {
t.Fatalf("bad: %#v", agent2.checkMonitors)
}
if agent2.state.checkTokens[p.Check.CheckID] != "hello" {
t.Fatalf("bad: %s", agent2.state.checkTokens[p.Check.CheckID])
}
}
func TestAgent_PurgeCheck(t *testing.T) {