fix(influx): select an active config when deleting the active config

pull/18713/head
Johnny Steenbergen 2020-06-24 15:03:14 -07:00 committed by Johnny Steenbergen
parent 74722d5191
commit 5612930a83
2 changed files with 30 additions and 18 deletions

View File

@ -221,6 +221,14 @@ func (svc localConfigsSVC) DeleteConfig(name string) (Config, error) {
}
delete(cfgs, name)
if p.Active && len(cfgs) > 0 {
for name, cfg := range cfgs {
cfg.Active = true
cfgs[name] = cfg
break
}
}
return p, svc.writeConfigs(cfgs)
}

View File

@ -770,6 +770,7 @@ func TestConfigDelete(t *testing.T) {
},
stored: Configs{
"a2": {
Active: true,
Name: "a2",
Host: "host2",
Org: "org2",
@ -779,6 +780,7 @@ func TestConfigDelete(t *testing.T) {
},
}
for _, c := range cases {
fn := func(t *testing.T) {
svc, store := newBufferSVC()
_ = store.writeConfigs(c.exists)
result, err := svc.DeleteConfig(c.target)
@ -796,6 +798,8 @@ func TestConfigDelete(t *testing.T) {
}
}
}
t.Run(c.name, fn)
}
}
func newBufferSVC() (ConfigsService, *bytesStore) {