Skip to content

Commit 6a07663

Browse files
committed
tests for new implementations
Signed-off-by: Jan Kowalleck <[email protected]>
1 parent e85e477 commit 6a07663

File tree

1 file changed

+68
-9
lines changed

1 file changed

+68
-9
lines changed

tests/integration/Factories.PackageUrlFactory.test.js

+68-9
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ suite('Factories.PackageUrlFactory', () => {
4141
''
4242
)
4343
const expected = undefined
44+
4445
const actual = sut.makeFromComponent(component)
46+
4547
assert.strictEqual(actual, expected)
4648
})
4749

@@ -58,7 +60,9 @@ suite('Factories.PackageUrlFactory', () => {
5860
}
5961
)
6062
const expected = new PackageURL('testing', `@group-${salt}`, `name-${salt}`, `v1+${salt}`, {}, undefined)
63+
6164
const actual = sut.makeFromComponent(component)
65+
6266
assert.deepStrictEqual(actual, expected)
6367
})
6468

@@ -68,12 +72,14 @@ suite('Factories.PackageUrlFactory', () => {
6872
`name-${salt}`,
6973
{
7074
externalReferences: new Models.ExternalReferenceRepository([
71-
new Models.ExternalReference('git://foo.bar', Enums.ExternalReferenceType.VCS)
75+
new Models.ExternalReference('git+https://foo.bar/repo.git', Enums.ExternalReferenceType.VCS)
7276
])
7377
}
7478
)
75-
const expected = new PackageURL('testing', undefined, `name-${salt}`, undefined, { vcs_url: 'git://foo.bar' }, undefined)
79+
const expected = new PackageURL('testing', undefined, `name-${salt}`, undefined, { vcs_url: 'git+https://foo.bar/repo.git' }, undefined)
80+
7681
const actual = sut.makeFromComponent(component)
82+
7783
assert.deepStrictEqual(actual, expected)
7884
})
7985

@@ -83,27 +89,80 @@ suite('Factories.PackageUrlFactory', () => {
8389
`name-${salt}`,
8490
{
8591
externalReferences: new Models.ExternalReferenceRepository([
86-
new Models.ExternalReference('git://foo.bar#sub/path', Enums.ExternalReferenceType.VCS)
92+
new Models.ExternalReference('git+https://foo.bar/repo.git#sub/path', Enums.ExternalReferenceType.VCS)
8793
])
8894
}
8995
)
90-
const expected = new PackageURL('testing', undefined, `name-${salt}`, undefined, { vcs_url: 'git://foo.bar' }, 'sub/path')
96+
const expected = new PackageURL('testing', undefined, `name-${salt}`, undefined, { vcs_url: 'git+https://foo.bar/repo.git' }, 'sub/path')
97+
9198
const actual = sut.makeFromComponent(component)
99+
92100
assert.deepStrictEqual(actual, expected)
93101
})
94102

95103
test('extRef[distribution] -> qualifiers.download_url', () => {
96-
assert.strictEqual(false, true, 'TODO')
104+
const component = new Models.Component(
105+
Enums.ComponentType.Library,
106+
`name-${salt}`,
107+
{
108+
externalReferences: new Models.ExternalReferenceRepository([
109+
new Models.ExternalReference('https://foo.bar/download', Enums.ExternalReferenceType.Distribution)
110+
])
111+
}
112+
)
113+
const expected = new PackageURL('testing', undefined, `name-${salt}`, undefined, { download_url: 'https://foo.bar/download' }, undefined)
114+
115+
const actual = sut.makeFromComponent(component)
116+
117+
assert.deepStrictEqual(actual, expected)
97118
})
98119

99120
test('hashes -> qualifiers.checksum', () => {
100-
assert.strictEqual(false, true, 'TODO')
121+
const component = new Models.Component(
122+
Enums.ComponentType.Library,
123+
`name-${salt}`,
124+
{
125+
hashes: new Models.HashRepository([
126+
[Enums.HashAlgorithm['SHA-256'], 'C3AB8FF13720E8AD9047DD39466B3C8974E592C2FA383D4A3960714CAEF0C4F2']
127+
])
128+
}
129+
)
130+
const expected = new PackageURL('testing', undefined, `name-${salt}`, undefined, { checksum: 'sha-256:c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2' }, undefined)
131+
132+
const actual = sut.makeFromComponent(component)
133+
134+
assert.deepStrictEqual(actual, expected)
101135
})
102136

103137
test('sorted', () => {
104-
assert.strictEqual(false, true, 'TODO')
138+
const component = new Models.Component(
139+
Enums.ComponentType.Library,
140+
`name-${salt}`,
141+
{
142+
externalReferences: new Models.ExternalReferenceRepository([
143+
new Models.ExternalReference('git+https://foo.bar/repo.git', Enums.ExternalReferenceType.VCS),
144+
new Models.ExternalReference('https://foo.bar/download', Enums.ExternalReferenceType.Distribution)
145+
]),
146+
hashes: new Models.HashRepository([
147+
[Enums.HashAlgorithm['SHA-256'], 'C3AB8FF13720E8AD9047DD39466B3C8974E592C2FA383D4A3960714CAEF0C4F2'],
148+
[Enums.HashAlgorithm.BLAKE3, 'aa51dcd43d5c6c5203ee16906fd6b35db298b9b2e1de3fce81811d4806b76b7d']
149+
])
150+
}
151+
)
152+
const expectedObject = new PackageURL('testing', undefined, 'name', undefined,
153+
{
154+
// expect sorted hash list
155+
checksum: 'blake3:aa51dcd43d5c6c5203ee16906fd6b35db298b9b2e1de3fce81811d4806b76b7d,sha-256:c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2',
156+
download_url: 'https://foo.bar/download',
157+
vcs_url: 'git+https://foo.bar/repo.git'
158+
}, undefined)
159+
// expect objet's keys in alphabetical oder, expect sorted hash list
160+
const expectedString = 'pkg:testing/name?checksum=blake3:aa51dcd43d5c6c5203ee16906fd6b35db298b9b2e1de3fce81811d4806b76b7d,sha-256:c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2&download_url=https://foo.bar/download&vcs_url=git+https://foo.bar/repo.git'
161+
162+
const actual = sut.makeFromComponent(component, true)
163+
164+
assert.deepStrictEqual(actual, expectedObject)
165+
assert.deepStrictEqual(actual.toString(), expectedString)
105166
})
106167
})
107-
108-
109168
})

0 commit comments

Comments
 (0)