• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

spdx / tools-golang / 5008105195

17 May 2023 09:34PM UTC coverage: 94.782% (-0.04%) from 94.822%
5008105195

Pull #215

github

Brandon Lum
change packageVerification code for 2.1,2.2 to omitempty
Pull Request #215: Fixing some optional params: copyrightText, licenseListVersion, packageVerificationCode

7157 of 7551 relevant lines covered (94.78%)

15.09 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

50.0
/convert/chain.go
1
// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
2

3
package convert
4

5
import (
6
        "fmt"
7
        "reflect"
8

9
        converter "github.com/anchore/go-struct-converter"
10

11
        "github.com/spdx/tools-golang/spdx/common"
12
        "github.com/spdx/tools-golang/spdx/v2/v2_1"
13
        "github.com/spdx/tools-golang/spdx/v2/v2_2"
14
        "github.com/spdx/tools-golang/spdx/v2/v2_3"
15
)
16

17
var DocumentChain = converter.NewChain(
18
        v2_1.Document{},
19
        v2_2.Document{},
20
        v2_3.Document{},
21
)
22

23
// Document converts from one document to another document
24
// For example, converting a document to the latest version could be done like:
25
//
26
// sourceDoc := // e.g. a v2_2.Document from somewhere
27
// var targetDoc spdx.Document // this can be any document version
28
// err := convert.Document(sourceDoc, &targetDoc) // the target must be passed as a pointer
29
func Document(from common.AnyDocument, to common.AnyDocument) error {
3✔
30
        if !IsPtr(to) {
3✔
31
                return fmt.Errorf("struct to convert to must be a pointer")
×
32
        }
×
33
        from = FromPtr(from)
3✔
34
        if reflect.TypeOf(from) == reflect.TypeOf(FromPtr(to)) {
3✔
35
                reflect.ValueOf(to).Elem().Set(reflect.ValueOf(from))
×
36
                return nil
×
37
        }
×
38
        return DocumentChain.Convert(from, to)
3✔
39
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc