-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Profiling] Fix incorrect status of single-click installation (#159168)
## Summary This PR addresses two bugs discovered after #157949: * when setting up security roles, the incorrect status was set * when merging the statuses of all steps, the merged status could lose some statuses
- Loading branch information
Showing
3 changed files
with
158 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { | ||
areResourcesSetup, | ||
createDefaultSetupState, | ||
mergePartialSetupStates, | ||
PartialSetupState, | ||
} from './setup'; | ||
|
||
function createCloudState(available: boolean): PartialSetupState { | ||
return { | ||
cloud: { | ||
available, | ||
}, | ||
}; | ||
} | ||
|
||
function createDataState(available: boolean): PartialSetupState { | ||
return { | ||
data: { | ||
available, | ||
}, | ||
}; | ||
} | ||
|
||
function createPackageState(installed: boolean): PartialSetupState { | ||
return { | ||
packages: { | ||
installed, | ||
}, | ||
}; | ||
} | ||
|
||
function createPermissionState(configured: boolean): PartialSetupState { | ||
return { | ||
permissions: { | ||
configured, | ||
}, | ||
}; | ||
} | ||
|
||
function createApmPolicyState(installed: boolean): PartialSetupState { | ||
return { | ||
policies: { | ||
apm: { | ||
installed, | ||
}, | ||
}, | ||
}; | ||
} | ||
|
||
function createCollectorPolicyState(installed: boolean): PartialSetupState { | ||
return { | ||
policies: { | ||
collector: { | ||
installed, | ||
}, | ||
}, | ||
}; | ||
} | ||
|
||
function createSymbolizerPolicyState(installed: boolean): PartialSetupState { | ||
return { | ||
policies: { | ||
symbolizer: { | ||
installed, | ||
}, | ||
}, | ||
}; | ||
} | ||
|
||
function createResourceState({ | ||
enabled, | ||
created, | ||
}: { | ||
enabled: boolean; | ||
created: boolean; | ||
}): PartialSetupState { | ||
return { | ||
resource_management: { | ||
enabled, | ||
}, | ||
resources: { | ||
created, | ||
}, | ||
}; | ||
} | ||
|
||
function createSettingsState(configured: boolean): PartialSetupState { | ||
return { | ||
settings: { | ||
configured, | ||
}, | ||
}; | ||
} | ||
|
||
describe('Merging partial state operations', () => { | ||
const defaultSetupState = createDefaultSetupState(); | ||
|
||
test('partial states with missing key', () => { | ||
const mergedState = mergePartialSetupStates(defaultSetupState, [ | ||
createCloudState(true), | ||
createDataState(true), | ||
]); | ||
|
||
expect(mergedState.cloud.available).toEqual(true); | ||
expect(mergedState.cloud.required).toEqual(true); | ||
expect(mergedState.data.available).toEqual(true); | ||
}); | ||
|
||
test('deeply nested partial states with overlap', () => { | ||
const mergedState = mergePartialSetupStates(defaultSetupState, [ | ||
createApmPolicyState(true), | ||
createCollectorPolicyState(true), | ||
createSymbolizerPolicyState(true), | ||
]); | ||
|
||
expect(mergedState.policies.apm.installed).toEqual(true); | ||
expect(mergedState.policies.collector.installed).toEqual(true); | ||
expect(mergedState.policies.symbolizer.installed).toEqual(true); | ||
}); | ||
|
||
test('check resource status with failed partial states', () => { | ||
const mergedState = mergePartialSetupStates(defaultSetupState, [ | ||
createPackageState(false), | ||
createApmPolicyState(true), | ||
createCollectorPolicyState(true), | ||
createSymbolizerPolicyState(true), | ||
createPermissionState(false), | ||
createResourceState({ enabled: true, created: true }), | ||
createSettingsState(true), | ||
]); | ||
|
||
expect(areResourcesSetup(mergedState)).toEqual(false); | ||
}); | ||
|
||
test('check resource status with all successful partial states', () => { | ||
const mergedState = mergePartialSetupStates(defaultSetupState, [ | ||
createPackageState(true), | ||
createApmPolicyState(true), | ||
createCollectorPolicyState(true), | ||
createSymbolizerPolicyState(true), | ||
createPermissionState(true), | ||
createResourceState({ enabled: true, created: true }), | ||
createSettingsState(true), | ||
]); | ||
|
||
expect(areResourcesSetup(mergedState)).toEqual(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters