config/diff: add utility function to get diffs scoped with struct tags (#20206)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
aa59c28b04
Коммит
8802c6c9d6
@@ -958,3 +958,105 @@ func TestDiff(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestDiffTags(t *testing.T) {
|
||||
tcs := []struct {
|
||||
name string
|
||||
base *model.Config
|
||||
actual *model.Config
|
||||
diffs ConfigDiffs
|
||||
tag string
|
||||
value string
|
||||
err string
|
||||
}{
|
||||
{
|
||||
name: "changed field is not in scope",
|
||||
base: defaultConfigGen(),
|
||||
actual: func() *model.Config {
|
||||
cfg := defaultConfigGen()
|
||||
cfg.ServiceSettings.EnableLinkPreviews = model.NewBool(false)
|
||||
return cfg
|
||||
}(),
|
||||
diffs: nil,
|
||||
tag: "access",
|
||||
value: "cloud_restrictable",
|
||||
err: "",
|
||||
},
|
||||
{
|
||||
name: "changed field is in scope",
|
||||
base: defaultConfigGen(),
|
||||
actual: func() *model.Config {
|
||||
cfg := defaultConfigGen()
|
||||
cfg.ServiceSettings.ReadTimeout = model.NewInt(500)
|
||||
return cfg
|
||||
}(),
|
||||
diffs: ConfigDiffs{
|
||||
{
|
||||
Path: "ServiceSettings.ReadTimeout",
|
||||
BaseVal: 300,
|
||||
ActualVal: 500,
|
||||
},
|
||||
},
|
||||
tag: "access",
|
||||
value: "cloud_restrictable",
|
||||
err: "",
|
||||
},
|
||||
{
|
||||
name: "changed struct is in scope",
|
||||
base: defaultConfigGen(),
|
||||
actual: func() *model.Config {
|
||||
cfg := defaultConfigGen()
|
||||
cfg.BleveSettings.BatchSize = model.NewInt(500)
|
||||
return cfg
|
||||
}(),
|
||||
diffs: ConfigDiffs{
|
||||
{
|
||||
Path: "BleveSettings.BatchSize",
|
||||
BaseVal: 10000,
|
||||
ActualVal: 500,
|
||||
},
|
||||
},
|
||||
tag: "access",
|
||||
value: "cloud_restrictable",
|
||||
err: "",
|
||||
},
|
||||
{
|
||||
name: "changed struct is not in scope",
|
||||
base: defaultConfigGen(),
|
||||
actual: func() *model.Config {
|
||||
cfg := defaultConfigGen()
|
||||
cfg.LocalizationSettings.DefaultServerLocale = model.NewString("Elvish")
|
||||
return cfg
|
||||
}(),
|
||||
diffs: nil,
|
||||
tag: "access",
|
||||
value: "cloud_restrictable",
|
||||
err: "",
|
||||
},
|
||||
{
|
||||
name: "changed field is not in scope due to its value but has the same tag",
|
||||
base: defaultConfigGen(),
|
||||
actual: func() *model.Config {
|
||||
cfg := defaultConfigGen()
|
||||
cfg.TeamSettings.SiteName = model.NewString("Mordor")
|
||||
return cfg
|
||||
}(),
|
||||
diffs: nil,
|
||||
tag: "access",
|
||||
value: "cloud_restrictable",
|
||||
err: "",
|
||||
},
|
||||
}
|
||||
for _, tc := range tcs {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
diffs, err := DiffTags(tc.base, tc.actual, tc.tag, tc.value)
|
||||
if tc.err != "" {
|
||||
require.EqualError(t, err, tc.err)
|
||||
require.Nil(t, diffs)
|
||||
} else {
|
||||
require.NoError(t, err)
|
||||
}
|
||||
require.Equal(t, tc.diffs, diffs)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user