From ace4519184ef154a3118b74d7c124bd1c91fe034 Mon Sep 17 00:00:00 2001 From: Mikhail Atuchin Date: Wed, 6 Nov 2024 16:45:16 +0400 Subject: [PATCH] Replace binary test artifacts to json. --- .gitignore | 1 + src/seed_tools/commands/create.test.ts | 33 +++-- .../data/perf_seeds/test1/expected_seed.bin | Bin 78 -> 0 bytes .../data/perf_seeds/test1/expected_seed.json | 36 +++++ .../data/set_seed_version/expected_seed.json | 49 +++++++ .../data/valid_seeds/test1/expected_seed.bin | Bin 121 -> 0 bytes .../data/valid_seeds/test1/expected_seed.json | 49 +++++++ .../data/valid_seeds/test2/expected_seed.bin | Bin 261 -> 0 bytes .../data/valid_seeds/test2/expected_seed.json | 87 ++++++++++++ .../data/valid_seeds/test3/expected_seed.bin | Bin 401 -> 0 bytes .../data/valid_seeds/test3/expected_seed.json | 125 ++++++++++++++++++ 11 files changed, 372 insertions(+), 8 deletions(-) delete mode 100644 src/test/data/perf_seeds/test1/expected_seed.bin create mode 100644 src/test/data/perf_seeds/test1/expected_seed.json create mode 100644 src/test/data/set_seed_version/expected_seed.json delete mode 100644 src/test/data/valid_seeds/test1/expected_seed.bin create mode 100644 src/test/data/valid_seeds/test1/expected_seed.json delete mode 100644 src/test/data/valid_seeds/test2/expected_seed.bin create mode 100644 src/test/data/valid_seeds/test2/expected_seed.json delete mode 100644 src/test/data/valid_seeds/test3/expected_seed.bin create mode 100644 src/test/data/valid_seeds/test3/expected_seed.json diff --git a/.gitignore b/.gitignore index 2168e098..e0df141b 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ seed.bin serialnumber +*.json.failed diff --git a/src/seed_tools/commands/create.test.ts b/src/seed_tools/commands/create.test.ts index af7984c5..895151d0 100644 --- a/src/seed_tools/commands/create.test.ts +++ b/src/seed_tools/commands/create.test.ts @@ -11,6 +11,26 @@ import { VariationsSeed } from 'src/proto/generated/variations_seed'; import { wsPath } from '../../base/path_utils'; import create from './create'; +// Helper function to compare protobuf with expected json. +const compareProtobuf = (actual: Uint8Array, expectedFilename: string) => { + let expectedJson = '{}'; + if (fs_sync.existsSync(expectedFilename)) { + expectedJson = fs_sync.readFileSync(expectedFilename, 'utf-8'); + } + const expected = VariationsSeed.fromJsonString(expectedJson); + const actualObj = VariationsSeed.fromBinary(actual); + try { + expect(actualObj).toEqual(expected); + } catch (error) { + const failedFilename = expectedFilename + '.failed'; + fs_sync.writeFileSync( + failedFilename, + VariationsSeed.toJsonString(actualObj, { prettySpaces: 2 }) + '\n', + ); + throw error; + } +}; + describe('create command', () => { const testDataDir = wsPath('//src/test/data'); @@ -57,10 +77,7 @@ describe('create command', () => { ]); const output = await fs.readFile(outputFile); - const expectedOutput = await fs.readFile( - path.join(testCaseDir, 'expected_seed.bin'), - ); - expect(output).toEqual(expectedOutput); + compareProtobuf(output, path.join(testCaseDir, 'expected_seed.json')); const outputSerialNumber = await fs.readFile(serialNumberPath, 'utf-8'); expect(outputSerialNumber).toEqual('1'); @@ -89,10 +106,7 @@ describe('create command', () => { await create().parseAsync(args); const output = await fs.readFile(outputFile); - const expectedOutput = await fs.readFile( - path.join(testCaseDir, 'expected_seed.bin'), - ); - expect(output).toEqual(expectedOutput); + compareProtobuf(output, path.join(testCaseDir, 'expected_seed.json')); expect(VariationsSeed.fromBinary(output).version).toEqual('1'); }; @@ -125,6 +139,9 @@ describe('create command', () => { ]); const output = await fs.readFile(outputFile); + compareProtobuf(output, path.join(testCaseDir, 'expected_seed.json')); + + // Check the binary output is the same as the expected output. const expectedOutput = await fs.readFile( path.join(testCaseDir, 'expected_seed.bin'), ); diff --git a/src/test/data/perf_seeds/test1/expected_seed.bin b/src/test/data/perf_seeds/test1/expected_seed.bin deleted file mode 100644 index aa3c8238436e1d577c08bdd0d02fed2048522cd9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 78 zcmd;LG!$~<;tWYGE(tCvO{uhCbmDNyEKW?yNlo#R=7O^YQj&OuxIxO?QWHx`i&BI5 X6c`kk6qq#_G#E9QG*}WCl^6{HJ>?S^ diff --git a/src/test/data/perf_seeds/test1/expected_seed.json b/src/test/data/perf_seeds/test1/expected_seed.json new file mode 100644 index 00000000..a96f0405 --- /dev/null +++ b/src/test/data/perf_seeds/test1/expected_seed.json @@ -0,0 +1,36 @@ +{ + "serialNumber": "1", + "study": [ + { + "name": "TestStudy", + "consistency": "PERMANENT", + "defaultExperimentName": "Disabled", + "experiment": [ + { + "name": "Disabled", + "probabilityWeight": 100, + "featureAssociation": { + "disableFeature": [ + "TestFeature" + ] + } + } + ], + "filter": { + "channel": [ + "CANARY", + "BETA", + "STABLE" + ], + "platform": [ + "PLATFORM_WINDOWS", + "PLATFORM_MAC", + "PLATFORM_LINUX", + "PLATFORM_ANDROID" + ] + }, + "activationType": "ACTIVATE_ON_STARTUP" + } + ], + "version": "1" +} diff --git a/src/test/data/set_seed_version/expected_seed.json b/src/test/data/set_seed_version/expected_seed.json new file mode 100644 index 00000000..da0dd2df --- /dev/null +++ b/src/test/data/set_seed_version/expected_seed.json @@ -0,0 +1,49 @@ +{ + "serialNumber": "1", + "study": [ + { + "name": "TestStudy", + "consistency": "PERMANENT", + "experiment": [ + { + "name": "Enabled", + "probabilityWeight": 100, + "featureAssociation": { + "enableFeature": [ + "TestFeature" + ] + } + }, + { + "name": "Disabled", + "probabilityWeight": 0, + "featureAssociation": { + "disableFeature": [ + "TestFeature" + ] + } + }, + { + "name": "Default", + "probabilityWeight": 0 + } + ], + "filter": { + "minVersion": "92.1.30.57", + "channel": [ + "CANARY", + "BETA", + "STABLE" + ], + "platform": [ + "PLATFORM_WINDOWS", + "PLATFORM_MAC", + "PLATFORM_LINUX", + "PLATFORM_ANDROID" + ] + }, + "activationType": "ACTIVATE_ON_STARTUP" + } + ], + "version": "test version value" +} diff --git a/src/test/data/valid_seeds/test1/expected_seed.bin b/src/test/data/valid_seeds/test1/expected_seed.bin deleted file mode 100644 index f849a7719f5ecdec17fa1b5264a7ae2ed40f9055..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 121 zcmd;LG!!c2;tWYGE(tCvO{uhC^pfIYcg;&o%1KQTNJ--5;s(jNr6!h?7NvSgb8)z2 z7DFT%l6ZwsB)PfRT~gB$OLIyD7=omPxGatI4E2l+^i0ha7!;Tkm^BzQ7&VwQSP~eO G7!3i+-yK;1 diff --git a/src/test/data/valid_seeds/test1/expected_seed.json b/src/test/data/valid_seeds/test1/expected_seed.json new file mode 100644 index 00000000..07a85494 --- /dev/null +++ b/src/test/data/valid_seeds/test1/expected_seed.json @@ -0,0 +1,49 @@ +{ + "serialNumber": "1", + "study": [ + { + "name": "TestStudy", + "consistency": "PERMANENT", + "experiment": [ + { + "name": "Enabled", + "probabilityWeight": 100, + "featureAssociation": { + "enableFeature": [ + "TestFeature" + ] + } + }, + { + "name": "Disabled", + "probabilityWeight": 0, + "featureAssociation": { + "disableFeature": [ + "TestFeature" + ] + } + }, + { + "name": "Default", + "probabilityWeight": 0 + } + ], + "filter": { + "minVersion": "92.1.30.57", + "channel": [ + "CANARY", + "BETA", + "STABLE" + ], + "platform": [ + "PLATFORM_WINDOWS", + "PLATFORM_MAC", + "PLATFORM_LINUX", + "PLATFORM_ANDROID" + ] + }, + "activationType": "ACTIVATE_ON_STARTUP" + } + ], + "version": "1" +} diff --git a/src/test/data/valid_seeds/test2/expected_seed.bin b/src/test/data/valid_seeds/test2/expected_seed.bin deleted file mode 100644 index ab88897c9213b9ddd3fb4e623002cdcde8ca9757..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 261 zcmd;LG!*J&IbEf8Qx65$d; zQs|bNSW;S)>ZQTO=aN~BtTH7@Lj0ucF zgIbEf8Qx65$d; zQs|bNSW;S)>ZQTO=aN~BtTH7@Lj0ucH zyTyoTw*Xa=>=q`lTMD^2k;6lZiyays0x3znT-+czSP)2aalnEA7)-oED3aV<>`-3| mFa${naakJa8R{7u=$V=;FeoqqJ