mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Provisioning: Ensure that the default value for orgID is set when provisioning datasources to be deleted (#44244)
Fixes #44243 Signed-off-by: Maicon Costa <maiconscosta@gmail.com>
This commit is contained in:
parent
b615d0558b
commit
8e03541228
@ -93,11 +93,11 @@ func (cr *configReader) parseDatasourceConfig(path string, file os.FileInfo) (*c
|
||||
func (cr *configReader) validateDefaultUniqueness(ctx context.Context, datasources []*configs) error {
|
||||
defaultCount := map[int64]int{}
|
||||
for i := range datasources {
|
||||
if datasources[i].Datasources == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, ds := range datasources[i].Datasources {
|
||||
if ds == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if ds.OrgID == 0 {
|
||||
ds.OrgID = 1
|
||||
}
|
||||
@ -115,6 +115,10 @@ func (cr *configReader) validateDefaultUniqueness(ctx context.Context, datasourc
|
||||
}
|
||||
|
||||
for _, ds := range datasources[i].DeleteDatasources {
|
||||
if ds == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if ds.OrgID == 0 {
|
||||
ds.OrgID = 1
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ var (
|
||||
|
||||
twoDatasourcesConfig = "testdata/two-datasources"
|
||||
twoDatasourcesConfigPurgeOthers = "testdata/insert-two-delete-two"
|
||||
deleteOneDatasource = "testdata/delete-one"
|
||||
doubleDatasourcesConfig = "testdata/double-default"
|
||||
allProperties = "testdata/all-properties"
|
||||
versionZero = "testdata/version-0"
|
||||
@ -129,6 +130,27 @@ func TestDatasourceAsConfig(t *testing.T) {
|
||||
})
|
||||
})
|
||||
|
||||
t.Run("Remove one datasource", func(t *testing.T) {
|
||||
setup()
|
||||
t.Run("Remove one datasource", func(t *testing.T) {
|
||||
fakeRepo.loadAll = []*models.DataSource{}
|
||||
|
||||
t.Run("should have removed old datasource", func(t *testing.T) {
|
||||
dc := newDatasourceProvisioner(logger)
|
||||
err := dc.applyChanges(context.Background(), deleteOneDatasource)
|
||||
if err != nil {
|
||||
t.Fatalf("applyChanges return an error %v", err)
|
||||
}
|
||||
|
||||
require.Equal(t, 1, len(fakeRepo.deleted))
|
||||
// should have set OrgID to 1
|
||||
require.Equal(t, fakeRepo.deleted[0].OrgID, int64(1))
|
||||
require.Equal(t, 0, len(fakeRepo.inserted))
|
||||
require.Equal(t, len(fakeRepo.updated), 0)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
t.Run("Two configured datasource and purge others ", func(t *testing.T) {
|
||||
setup()
|
||||
t.Run("two other datasources in database", func(t *testing.T) {
|
||||
|
3
pkg/services/provisioning/datasources/testdata/delete-one/one-datasource.yaml
vendored
Normal file
3
pkg/services/provisioning/datasources/testdata/delete-one/one-datasource.yaml
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
datasources: []
|
||||
delete_datasources:
|
||||
- name: old-data-source
|
Loading…
Reference in New Issue
Block a user