mirror of
https://github.com/goharbor/harbor.git
synced 2025-02-20 14:01:40 +01:00
Merge pull request #12646 from kofj/fix_update_instance
Fix bug of update preheat instance default.
This commit is contained in:
commit
fa48b9c058
@ -2,6 +2,7 @@ package instance
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
beego_orm "github.com/astaxie/beego/orm"
|
||||
"github.com/goharbor/harbor/src/lib/orm"
|
||||
@ -95,15 +96,10 @@ func (d *dao) Update(ctx context.Context, instance *provider.Instance, props ...
|
||||
}
|
||||
|
||||
// check default instances first
|
||||
for _, prop := range props {
|
||||
if prop == "default" && instance.Default {
|
||||
|
||||
_, err = o.Raw("UPDATE ? SET default = false WHERE id != ?", instance.TableName(), instance.ID).Exec()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
break
|
||||
if instance.Default {
|
||||
_, err = o.Raw(fmt.Sprintf("UPDATE %s SET is_default = false WHERE id != ?", instance.TableName()), instance.ID).Exec()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@ var (
|
||||
AuthMode: "basic",
|
||||
AuthData: "{\"username\": \"admin\", \"password\": \"123456\"}",
|
||||
Status: "healthy",
|
||||
Enabled: true,
|
||||
Enabled: false,
|
||||
SetupTimestamp: 1582721396,
|
||||
}
|
||||
)
|
||||
@ -91,18 +91,17 @@ func (is *instanceSuite) TestUpdate() {
|
||||
assert.Nil(t, err)
|
||||
assert.NotNil(t, i)
|
||||
|
||||
i.Enabled = false
|
||||
err = is.dao.Update(is.ctx, i, "enabled")
|
||||
assert.Nil(t, err)
|
||||
|
||||
// test set default
|
||||
i.Default = true
|
||||
err = is.dao.Update(is.ctx, i, "default")
|
||||
assert.NotNil(t, err)
|
||||
i.Enabled = true
|
||||
err = is.dao.Update(is.ctx, i)
|
||||
assert.Nil(t, err)
|
||||
|
||||
i, err = is.dao.Get(is.ctx, defaultInstance.ID)
|
||||
assert.Nil(t, err)
|
||||
assert.NotNil(t, i)
|
||||
assert.False(t, i.Enabled)
|
||||
assert.True(t, i.Default)
|
||||
assert.True(t, i.Enabled)
|
||||
}
|
||||
|
||||
func (is *instanceSuite) TestList() {
|
||||
|
Loading…
Reference in New Issue
Block a user