github.com/nextlinux/gosbom@v0.81.1-0.20230627115839-1ff50c281391/test/integration/license_list_test.go (about)

     1  package integration
     2  
     3  import (
     4  	"encoding/json"
     5  	"net/http"
     6  	"testing"
     7  
     8  	"github.com/nextlinux/gosbom/internal/spdxlicense"
     9  	"github.com/stretchr/testify/assert"
    10  )
    11  
    12  func TestSPDXLicenseListIsTheLatest(t *testing.T) {
    13  	resp, err := http.Get("https://spdx.org/licenses/licenses.json")
    14  	if err != nil {
    15  		t.Fatalf("unable to get licenses list: %+v", err)
    16  	}
    17  
    18  	type licenseList struct {
    19  		Version  string `json:"licenseListVersion"`
    20  		Licenses []struct {
    21  			ID          string   `json:"licenseId"`
    22  			Name        string   `json:"name"`
    23  			Text        string   `json:"licenseText"`
    24  			Deprecated  bool     `json:"isDeprecatedLicenseId"`
    25  			OSIApproved bool     `json:"isOsiApproved"`
    26  			SeeAlso     []string `json:"seeAlso"`
    27  		} `json:"licenses"`
    28  	}
    29  
    30  	var latest licenseList
    31  	if err = json.NewDecoder(resp.Body).Decode(&latest); err != nil {
    32  		t.Fatalf("unable to decode license list: %+v", err)
    33  	}
    34  
    35  	assert.Equal(t, latest.Version, spdxlicense.Version)
    36  }