|
| 1 | +import path from 'path' |
| 2 | + |
| 3 | +import { expect } from 'chai' |
| 4 | + |
| 5 | +import golangGomodulesProvider from '../../src/providers/golang_gomodules.js' |
| 6 | +import Java_gradle_groovy from '../../src/providers/java_gradle_groovy.js' |
| 7 | +import Java_gradle_kotlin from '../../src/providers/java_gradle_kotlin.js' |
| 8 | +import Java_maven from '../../src/providers/java_maven.js' |
| 9 | +import Javascript_npm from '../../src/providers/javascript_npm.js' |
| 10 | +import Javascript_pnpm from '../../src/providers/javascript_pnpm.js' |
| 11 | +import Javascript_yarn from '../../src/providers/javascript_yarn.js' |
| 12 | +import pythonPipProvider from '../../src/providers/python_pip.js' |
| 13 | + |
| 14 | +suite('testing readLicenseFromManifest with existing test manifests', () => { |
| 15 | + |
| 16 | + suite('Java Maven provider', () => { |
| 17 | + const provider = new Java_maven(); |
| 18 | + |
| 19 | + test('should read Apache-2.0 license when found', () => { |
| 20 | + const pomPath = path.resolve('test/providers/tst_manifests/maven/pom_deps_with_ignore_version_from_property/pom.xml'); |
| 21 | + const license = provider.readLicenseFromManifest(pomPath); |
| 22 | + expect(license).to.equal('Apache-2.0'); |
| 23 | + }); |
| 24 | + |
| 25 | + test('should return null when license not present', () => { |
| 26 | + const pomPath = path.resolve('test/providers/tst_manifests/maven/pom_deps_with_no_ignore/pom.xml'); |
| 27 | + const license = provider.readLicenseFromManifest(pomPath); |
| 28 | + expect(license).to.be.null; |
| 29 | + }); |
| 30 | + }); |
| 31 | + |
| 32 | + suite('Java Gradle Groovy provider', () => { |
| 33 | + const provider = new Java_gradle_groovy(); |
| 34 | + |
| 35 | + test('should always return null (no standard license field)', () => { |
| 36 | + const gradlePath = path.resolve('test/providers/tst_manifests/gradle/deps_with_no_ignore_common_paths/build.gradle'); |
| 37 | + const license = provider.readLicenseFromManifest(gradlePath); |
| 38 | + expect(license).to.be.null; |
| 39 | + }); |
| 40 | + }); |
| 41 | + |
| 42 | + suite('Java Gradle Kotlin provider', () => { |
| 43 | + const provider = new Java_gradle_kotlin(); |
| 44 | + |
| 45 | + test('should always return null (no standard license field)', () => { |
| 46 | + const gradlePath = path.resolve('test/providers/tst_manifests/gradle/deps_with_no_ignore_common_paths/build.gradle.kts'); |
| 47 | + const license = provider.readLicenseFromManifest(gradlePath); |
| 48 | + expect(license).to.be.null; |
| 49 | + }); |
| 50 | + }); |
| 51 | + |
| 52 | + suite('JavaScript npm provider', () => { |
| 53 | + const provider = new Javascript_npm(); |
| 54 | + |
| 55 | + test('should read ISC license when found', () => { |
| 56 | + const packagePath = path.resolve('test/providers/tst_manifests/npm/package_json_deps_with_exhortignore_object/package.json'); |
| 57 | + const license = provider.readLicenseFromManifest(packagePath); |
| 58 | + expect(license).to.equal('ISC'); |
| 59 | + }); |
| 60 | + |
| 61 | + test('should return null for non-existent file', () => { |
| 62 | + const license = provider.readLicenseFromManifest('/fake/path/package.json'); |
| 63 | + expect(license).to.be.null; |
| 64 | + }); |
| 65 | + }); |
| 66 | + |
| 67 | + suite('JavaScript pnpm provider', () => { |
| 68 | + const provider = new Javascript_pnpm(); |
| 69 | + |
| 70 | + test('should read ISC license when found', () => { |
| 71 | + const packagePath = path.resolve('test/providers/tst_manifests/pnpm/package_json_deps_with_exhortignore_object/package.json'); |
| 72 | + const license = provider.readLicenseFromManifest(packagePath); |
| 73 | + expect(license).to.equal('ISC'); |
| 74 | + }); |
| 75 | + |
| 76 | + test('should return null for non-existent file', () => { |
| 77 | + const license = provider.readLicenseFromManifest('/fake/path/package.json'); |
| 78 | + expect(license).to.be.null; |
| 79 | + }); |
| 80 | + }); |
| 81 | + |
| 82 | + suite('JavaScript yarn provider', () => { |
| 83 | + const provider = new Javascript_yarn(); |
| 84 | + |
| 85 | + test('should read ISC license when found', () => { |
| 86 | + const packagePath = path.resolve('test/providers/tst_manifests/yarn-classic/package_json_deps_with_exhortignore_object/package.json'); |
| 87 | + const license = provider.readLicenseFromManifest(packagePath); |
| 88 | + expect(license).to.equal('ISC'); |
| 89 | + }); |
| 90 | + |
| 91 | + test('should return null for non-existent file', () => { |
| 92 | + const license = provider.readLicenseFromManifest('/fake/path/package.json'); |
| 93 | + expect(license).to.be.null; |
| 94 | + }); |
| 95 | + }); |
| 96 | + |
| 97 | + suite('Golang go.mod provider', () => { |
| 98 | + test('should always return null (no standard license field)', () => { |
| 99 | + const goModPath = path.resolve('test/providers/tst_manifests/golang/go_mod_no_ignore/go.mod'); |
| 100 | + const license = golangGomodulesProvider.readLicenseFromManifest(goModPath); |
| 101 | + expect(license).to.be.null; |
| 102 | + }); |
| 103 | + }); |
| 104 | + |
| 105 | + suite('Python requirements.txt provider', () => { |
| 106 | + test('should always return null (no standard license field)', () => { |
| 107 | + const reqPath = path.resolve('test/providers/tst_manifests/pip/pip_requirements_txt_no_ignore/requirements.txt'); |
| 108 | + const license = pythonPipProvider.readLicenseFromManifest(reqPath); |
| 109 | + expect(license).to.be.null; |
| 110 | + }); |
| 111 | + }); |
| 112 | + |
| 113 | + suite('All providers have readLicenseFromManifest method', () => { |
| 114 | + const allProviders = [ |
| 115 | + { name: 'Java Maven', instance: new Java_maven() }, |
| 116 | + { name: 'Java Gradle Groovy', instance: new Java_gradle_groovy() }, |
| 117 | + { name: 'Java Gradle Kotlin', instance: new Java_gradle_kotlin() }, |
| 118 | + { name: 'JavaScript npm', instance: new Javascript_npm() }, |
| 119 | + { name: 'JavaScript pnpm', instance: new Javascript_pnpm() }, |
| 120 | + { name: 'JavaScript yarn', instance: new Javascript_yarn() }, |
| 121 | + { name: 'Golang', instance: golangGomodulesProvider }, |
| 122 | + { name: 'Python', instance: pythonPipProvider } |
| 123 | + ]; |
| 124 | + |
| 125 | + allProviders.forEach(({ name, instance }) => { |
| 126 | + test(`${name} provider exports readLicenseFromManifest`, () => { |
| 127 | + expect(instance.readLicenseFromManifest).to.be.a('function'); |
| 128 | + }); |
| 129 | + |
| 130 | + test(`${name} provider readLicenseFromManifest accepts manifestPath parameter`, () => { |
| 131 | + // Should not throw when called with a path argument |
| 132 | + expect(() => instance.readLicenseFromManifest('/test/path')).to.not.throw(); |
| 133 | + }); |
| 134 | + }); |
| 135 | + }); |
| 136 | +}); |
0 commit comments