fix(influx): select an active config when deleting the active config
parent
74722d5191
commit
5612930a83
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -770,31 +770,35 @@ func TestConfigDelete(t *testing.T) {
|
|||
},
|
||||
stored: Configs{
|
||||
"a2": {
|
||||
Name: "a2",
|
||||
Host: "host2",
|
||||
Org: "org2",
|
||||
Token: "tok2",
|
||||
Active: true,
|
||||
Name: "a2",
|
||||
Host: "host2",
|
||||
Org: "org2",
|
||||
Token: "tok2",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, c := range cases {
|
||||
svc, store := newBufferSVC()
|
||||
_ = store.writeConfigs(c.exists)
|
||||
result, err := svc.DeleteConfig(c.target)
|
||||
influxtesting.ErrorsEqual(t, err, c.err)
|
||||
if err == nil {
|
||||
if diff := cmp.Diff(result, c.result); diff != "" {
|
||||
t.Fatalf("delete config %s failed, diff %s", c.name, diff)
|
||||
}
|
||||
stored, err := store.ListConfigs()
|
||||
if err != nil {
|
||||
t.Fatalf("delete config %s to list result, err %s", c.name, err.Error())
|
||||
}
|
||||
if diff := cmp.Diff(stored, c.stored); diff != "" {
|
||||
t.Fatalf("delete config %s failed, diff %s", c.name, diff)
|
||||
fn := func(t *testing.T) {
|
||||
svc, store := newBufferSVC()
|
||||
_ = store.writeConfigs(c.exists)
|
||||
result, err := svc.DeleteConfig(c.target)
|
||||
influxtesting.ErrorsEqual(t, err, c.err)
|
||||
if err == nil {
|
||||
if diff := cmp.Diff(result, c.result); diff != "" {
|
||||
t.Fatalf("delete config %s failed, diff %s", c.name, diff)
|
||||
}
|
||||
stored, err := store.ListConfigs()
|
||||
if err != nil {
|
||||
t.Fatalf("delete config %s to list result, err %s", c.name, err.Error())
|
||||
}
|
||||
if diff := cmp.Diff(stored, c.stored); diff != "" {
|
||||
t.Fatalf("delete config %s failed, diff %s", c.name, diff)
|
||||
}
|
||||
}
|
||||
}
|
||||
t.Run(c.name, fn)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue