github.com/CycloneDX/sbom-utility@v0.16.0/cmd/validate_spdx_test.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 /* 3 * Licensed to the Apache Software Foundation (ASF) under one or more 4 * contributor license agreements. See the NOTICE file distributed with 5 * this work for additional information regarding copyright ownership. 6 * The ASF licenses this file to You under the Apache License, Version 2.0 7 * (the "License"); you may not use this file except in compliance with 8 * the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 package cmd 20 21 import ( 22 "testing" 23 ) 24 25 // Consolidate test file name declarations 26 const ( 27 // SPDX - Test versioned documents meet min. schema requirements 28 TEST_SPDX_2_2_MIN_REQUIRED = "test/spdx/spdx-2-2-min-required.json" 29 30 // SPDX - (invalid) Schema tests 31 TEST_SPDX_2_2_INVALID_CREATION_INFO_MISSING = "test/spdx/spdx-2-2-missing-creationinfo.json" 32 33 // SPDX - Tool samples 34 //TEST_SPDX_SAMPLE_MEND_PACKAGE_NPM_ASYNC_WS = "test/spdx/samples/whitesource.json" 35 ) 36 37 // ----------------------------------------------------------- 38 // SPDX - Min. req. tests 39 // ----------------------------------------------------------- 40 41 // TODO: Need an SPDX 2.1 variant 42 // TODO: Need an SPDX 2.2.1 variant 43 // TODO: Need an SPDX 2.2 "custom" variant 44 func TestValidateSpdx22MinRequiredBasic(t *testing.T) { 45 vti := NewValidateTestInfoMinimum(TEST_SPDX_2_2_MIN_REQUIRED) 46 innerTestValidate(t, *vti) 47 } 48 49 // ----------------------------------------------------------- 50 // SPDX - (invalid) Schema tests 51 // ----------------------------------------------------------- 52 // NOTE: Schema errors do not have an "inner error", but return "[]gojsonschema.ResultError" 53 // This means that these "errors" ARE NOT surfaced in the error return from Validate(); instead, 54 // a `[]gojsonschema.ResultError` (custom error) is returned in the "results" array 55 // ----------------------------------------------------------- 56 57 func TestValidateSchemaSpdx22CreationInfoMissing(t *testing.T) { 58 // Note: actual error "value" is a structure which we cannot easily recreate here; so do not test that field 59 SCHEMA_ERROR_TYPE := "required" 60 SCHEMA_ERROR_FIELD := "(root)" 61 SCHEMA_ERROR_VALUE := "" 62 63 innerTestSchemaErrorAndErrorResults(t, 64 TEST_SPDX_2_2_INVALID_CREATION_INFO_MISSING, 65 SCHEMA_VARIANT_NONE, 66 SCHEMA_ERROR_TYPE, 67 SCHEMA_ERROR_FIELD, 68 SCHEMA_ERROR_VALUE) 69 }