diff --git a/cmd/influx/config/config.go b/cmd/influx/config/config.go index b5fba2b20c..d9bc4656a9 100644 --- a/cmd/influx/config/config.go +++ b/cmd/influx/config/config.go @@ -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) } diff --git a/cmd/influx/config/config_test.go b/cmd/influx/config/config_test.go index d72618b949..4ba6a121d8 100644 --- a/cmd/influx/config/config_test.go +++ b/cmd/influx/config/config_test.go @@ -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) } }