Add support for specifying content type (#10)
This commit is contained in:
Родитель
3293d26c81
Коммит
d27de5c67d
|
@ -28,6 +28,9 @@ inputs:
|
|||
tags:
|
||||
description: 'Stringified form of a JSON object with the following shape: { [propertyName: string]: string; }'
|
||||
required: false
|
||||
contentType:
|
||||
description: 'Content type associated with the values'
|
||||
required: false
|
||||
runs:
|
||||
using: 'node12'
|
||||
main: 'lib/index.js'
|
||||
|
|
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
|
@ -15,8 +15,9 @@ const userAgentPrefix = "GitHub-AppConfiguration-Sync/1.0.0";
|
|||
* @param label Label assigned to the modified settings.
|
||||
* @param prefix Prefix appended to the front of the setting key.
|
||||
* @param tags Tags applied to the modified settings.
|
||||
* @param contentType Content type applied to the settings.
|
||||
*/
|
||||
export async function syncConfig(config: any, connectionString: string, strict: boolean, label?: string, prefix?: string, tags?: Tags): Promise<void> {
|
||||
export async function syncConfig(config: any, connectionString: string, strict: boolean, label?: string, prefix?: string, tags?: Tags, contentType?: string): Promise<void> {
|
||||
const appConfigurationOptions = {
|
||||
userAgentOptions: {
|
||||
userAgentPrefix: userAgentPrefix
|
||||
|
@ -25,7 +26,7 @@ export async function syncConfig(config: any, connectionString: string, strict:
|
|||
const client = new AppConfigurationClient(connectionString, appConfigurationOptions);
|
||||
|
||||
core.info('Determining which keys to sync');
|
||||
const settingsToAdd = getSettingsToAdd(config, label, prefix, tags);
|
||||
const settingsToAdd = getSettingsToAdd(config, label, prefix, tags, contentType);
|
||||
const settingsToDelete = strict ? await getSettingsToDelete(client, settingsToAdd, label, prefix) : [];
|
||||
|
||||
const failedDeletes = await deleteSettings(client, settingsToDelete);
|
||||
|
@ -51,7 +52,7 @@ export async function syncConfig(config: any, connectionString: string, strict:
|
|||
}
|
||||
}
|
||||
|
||||
function getSettingsToAdd(config: any, label?: string, prefix?: string, tags?: Tags): SetConfigurationSettingParam[] {
|
||||
function getSettingsToAdd(config: any, label?: string, prefix?: string, tags?: Tags, contentType?: string): SetConfigurationSettingParam[] {
|
||||
const settings: SetConfigurationSettingParam[] = [];
|
||||
|
||||
for (const key in config) {
|
||||
|
@ -60,6 +61,7 @@ function getSettingsToAdd(config: any, label?: string, prefix?: string, tags?: T
|
|||
value: getSettingValue(config[key]),
|
||||
label: label ? label : undefined,
|
||||
tags: tags ? tags : undefined,
|
||||
contentType: contentType ? contentType : undefined
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ export interface Input {
|
|||
label?: string;
|
||||
depth?: number;
|
||||
tags?: Tags;
|
||||
contentType?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -40,7 +41,8 @@ export function getInput(): Input {
|
|||
prefix: getNonRequiredInputString('prefix'),
|
||||
label: getNonRequiredInputString('label'),
|
||||
depth: getDepth(),
|
||||
tags: getTags()
|
||||
tags: getTags(),
|
||||
contentType: getNonRequiredInputString('contentType')
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ async function main(): Promise<void> {
|
|||
const input = getInput();
|
||||
const config = await loadConfigFiles(input.workspace, input.configFile, input.format, input.separator, input.depth);
|
||||
|
||||
await syncConfig(config, input.connectionString, input.strict, input.label, input.prefix, input.tags);
|
||||
await syncConfig(config, input.connectionString, input.strict, input.label, input.prefix, input.tags, input.contentType);
|
||||
} catch (error) {
|
||||
core.setFailed(getErrorMessage(error));
|
||||
}
|
||||
|
|
|
@ -358,6 +358,19 @@ describe('syncConfig', () => {
|
|||
expect(core.error).not.toBeCalled();
|
||||
})
|
||||
|
||||
it('adds setting with content type', async () => {
|
||||
const config = { "Key1": "Value1" };
|
||||
await configstore.syncConfig(config, "connection string", false, undefined, undefined, undefined, "contentType");
|
||||
|
||||
expect(AppConfigurationClient).toBeCalled();
|
||||
expect(AppConfigurationClient.prototype.listConfigurationSettings).not.toBeCalled();
|
||||
expect(AppConfigurationClient.prototype.deleteConfigurationSetting).not.toBeCalled();
|
||||
expect(AppConfigurationClient.prototype.setConfigurationSetting).toHaveBeenCalledTimes(1);
|
||||
expect(AppConfigurationClient.prototype.setConfigurationSetting).toHaveBeenCalledWith({ key: "Key1", value: "Value1", contentType: "contentType" });
|
||||
expect(core.setFailed).not.toBeCalled();
|
||||
expect(core.error).not.toBeCalled();
|
||||
})
|
||||
|
||||
function setListConfigurationSettingsMock(...configurationSettings: ConfigurationSetting[]) {
|
||||
AppConfigurationClient.prototype.listConfigurationSettings = jest.fn((options?: ListConfigurationSettingsOptions) => {
|
||||
const iter = getConfigurationSettingIterator(configurationSettings);
|
||||
|
|
|
@ -362,6 +362,22 @@ describe('input', () => {
|
|||
expect(input.tags).toEqual({ A: "foo", B: "foo" });
|
||||
})
|
||||
|
||||
it('validation succeeds with missing content type', () => {
|
||||
mockInput = getDefaultInput();
|
||||
mockInput.contentType = undefined;
|
||||
|
||||
const input = getInput();
|
||||
expect(input.contentType).toBe(undefined);
|
||||
})
|
||||
|
||||
it('validation succeeds with content type', () => {
|
||||
mockInput = getDefaultInput();
|
||||
mockInput.contentType = "contentType";
|
||||
|
||||
const input = getInput();
|
||||
expect(input.contentType).toBe("contentType");
|
||||
})
|
||||
|
||||
function verifySeparator(separator: string) {
|
||||
mockInput = getDefaultInput();
|
||||
mockInput.separator = separator
|
||||
|
|
Загрузка…
Ссылка в новой задаче