-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SDA-4714 - Add missing latestAutoUpdateChannelEnabled into plist file (…
- Loading branch information
1 parent
5488ef8
commit 5c76460
Showing
2 changed files
with
67 additions
and
0 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
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,65 @@ | ||
import * as fs from 'fs'; | ||
|
||
const extractUserDefaults = (filePath: string) => { | ||
const content = fs.readFileSync(filePath, 'utf-8'); | ||
const fieldRegex = | ||
/^\s*sudo -u "\$userName"\s+defaults write "\$plistFilePath"\s+([a-zA-Z_][a-zA-Z0-9_]*)/gm; | ||
return Array.from(content.matchAll(fieldRegex), (match) => match[1]); | ||
}; | ||
|
||
const extractSystemDefaults = (filePath: string) => { | ||
const content = fs.readFileSync(filePath, 'utf-8'); | ||
const fieldRegex = | ||
/^\s*defaults write "\$plistFilePath"\s+([a-zA-Z_][a-zA-Z0-9_]*)/gm; | ||
return Array.from(content.matchAll(fieldRegex), (match) => match[1]); | ||
}; | ||
|
||
const isArraySubset = (array1: string[], array2: string[]): boolean => { | ||
return array2.every((item) => array1.includes(item)); | ||
}; | ||
|
||
const removeFields = (array: string[], stringsToRemove: string[]): string[] => { | ||
return array.filter((item) => !stringsToRemove.includes(item)); | ||
}; | ||
|
||
describe('Shell Script Field Validation', () => { | ||
it('should contain all the user defaults fields from JSON', async () => { | ||
const jsonFilePath = './config/Symphony.config'; | ||
const scriptFilePath = './installer/mac/postinstall.sh'; | ||
|
||
// Read Symphony config JSON file | ||
const jsonContent = JSON.parse(fs.readFileSync(jsonFilePath, 'utf-8')); | ||
const fields = Object.keys(jsonContent) as []; | ||
const filteredFields = removeFields(fields, [ | ||
'notificationSettings', | ||
'customFlags', | ||
'permissions', | ||
]); | ||
|
||
// Read fields from post install script file | ||
const scriptFields = extractUserDefaults(scriptFilePath); | ||
scriptFields.splice(scriptFields.indexOf('ApplicationName'), 1); | ||
|
||
expect(isArraySubset(scriptFields, filteredFields)).toBe(true); | ||
}); | ||
|
||
it('should contain all the system defaults fields from JSON', async () => { | ||
const jsonFilePath = './config/Symphony.config'; | ||
const scriptFilePath = './installer/mac/postinstall.sh'; | ||
|
||
// Read Symphony config JSON file | ||
const jsonContent = JSON.parse(fs.readFileSync(jsonFilePath, 'utf-8')); | ||
const fields = Object.keys(jsonContent) as []; | ||
const filteredFields = removeFields(fields, [ | ||
'notificationSettings', | ||
'customFlags', | ||
'permissions', | ||
]); | ||
|
||
// Read fields from post install script file | ||
const scriptFields = extractSystemDefaults(scriptFilePath); | ||
scriptFields.splice(scriptFields.indexOf('ApplicationName'), 1); | ||
|
||
expect(isArraySubset(scriptFields, filteredFields)).toBe(true); | ||
}); | ||
}); |