|
|
|
@ -533,11 +533,9 @@ func TestAgent_PersistService(t *testing.T) {
|
|
|
|
|
if err := agent.AddService(svc, nil, true, "mytoken"); err != nil { |
|
|
|
|
t.Fatalf("err: %v", err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if _, err := os.Stat(file); err != nil { |
|
|
|
|
t.Fatalf("err: %s", err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
expected, err := json.Marshal(persistedService{ |
|
|
|
|
Token: "mytoken", |
|
|
|
|
Service: svc, |
|
|
|
@ -552,6 +550,26 @@ func TestAgent_PersistService(t *testing.T) {
|
|
|
|
|
if !bytes.Equal(expected, content) { |
|
|
|
|
t.Fatalf("bad: %s", string(content)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Updates service definition on disk
|
|
|
|
|
svc.Port = 8001 |
|
|
|
|
if err := agent.AddService(svc, nil, true, "mytoken"); err != nil { |
|
|
|
|
t.Fatalf("err: %v", err) |
|
|
|
|
} |
|
|
|
|
expected, err = json.Marshal(persistedService{ |
|
|
|
|
Token: "mytoken", |
|
|
|
|
Service: svc, |
|
|
|
|
}) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatalf("err: %s", err) |
|
|
|
|
} |
|
|
|
|
content, err = ioutil.ReadFile(file) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatalf("err: %s", err) |
|
|
|
|
} |
|
|
|
|
if !bytes.Equal(expected, content) { |
|
|
|
|
t.Fatalf("bad: %s", string(content)) |
|
|
|
|
} |
|
|
|
|
agent.Shutdown() |
|
|
|
|
|
|
|
|
|
// Should load it back during later start
|
|
|
|
@ -561,12 +579,16 @@ func TestAgent_PersistService(t *testing.T) {
|
|
|
|
|
} |
|
|
|
|
defer agent2.Shutdown() |
|
|
|
|
|
|
|
|
|
if _, ok := agent2.state.services[svc.ID]; !ok { |
|
|
|
|
restored, ok := agent2.state.services[svc.ID] |
|
|
|
|
if !ok { |
|
|
|
|
t.Fatalf("bad: %#v", agent2.state.services) |
|
|
|
|
} |
|
|
|
|
if agent2.state.serviceTokens[svc.ID] != "mytoken" { |
|
|
|
|
t.Fatalf("bad: %#v", agent2.state.services[svc.ID]) |
|
|
|
|
} |
|
|
|
|
if restored.Port != 8001 { |
|
|
|
|
t.Fatalf("bad: %#v", restored) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestAgent_persistedService_compat(t *testing.T) { |
|
|
|
@ -731,11 +753,9 @@ func TestAgent_PersistCheck(t *testing.T) {
|
|
|
|
|
if err := agent.AddCheck(check, chkType, true, "mytoken"); err != nil { |
|
|
|
|
t.Fatalf("err: %v", err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if _, err := os.Stat(file); err != nil { |
|
|
|
|
t.Fatalf("err: %s", err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
expected, err := json.Marshal(persistedCheck{ |
|
|
|
|
Check: check, |
|
|
|
|
ChkType: chkType, |
|
|
|
@ -751,6 +771,27 @@ func TestAgent_PersistCheck(t *testing.T) {
|
|
|
|
|
if !bytes.Equal(expected, content) { |
|
|
|
|
t.Fatalf("bad: %s", string(content)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Updates the check definition on disk
|
|
|
|
|
check.Name = "mem1" |
|
|
|
|
if err := agent.AddCheck(check, chkType, true, "mytoken"); err != nil { |
|
|
|
|
t.Fatalf("err: %v", err) |
|
|
|
|
} |
|
|
|
|
expected, err = json.Marshal(persistedCheck{ |
|
|
|
|
Check: check, |
|
|
|
|
ChkType: chkType, |
|
|
|
|
Token: "mytoken", |
|
|
|
|
}) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatalf("err: %s", err) |
|
|
|
|
} |
|
|
|
|
content, err = ioutil.ReadFile(file) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatalf("err: %s", err) |
|
|
|
|
} |
|
|
|
|
if !bytes.Equal(expected, content) { |
|
|
|
|
t.Fatalf("bad: %s", string(content)) |
|
|
|
|
} |
|
|
|
|
agent.Shutdown() |
|
|
|
|
|
|
|
|
|
// Should load it back during later start
|
|
|
|
@ -767,6 +808,9 @@ func TestAgent_PersistCheck(t *testing.T) {
|
|
|
|
|
if result.Status != structs.HealthCritical { |
|
|
|
|
t.Fatalf("bad: %#v", result) |
|
|
|
|
} |
|
|
|
|
if result.Name != "mem1" { |
|
|
|
|
t.Fatalf("bad: %#v", result) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Should have restored the monitor
|
|
|
|
|
if _, ok := agent2.checkMonitors[check.CheckID]; !ok { |
|
|
|
|