github.com/metasources/buildx@v0.0.0-20230418141019-7aa1459cedea/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/stretchr/testify/assert"
     9  
    10  	"github.com/metasources/buildx/internal/spdxlicense"
    11  )
    12  
    13  func TestSPDXLicenseListIsTheLatest(t *testing.T) {
    14  	resp, err := http.Get("https://spdx.org/licenses/licenses.json")
    15  	if err != nil {
    16  		t.Fatalf("unable to get licenses list: %+v", err)
    17  	}
    18  
    19  	type licenseList struct {
    20  		Version  string `json:"licenseListVersion"`
    21  		Licenses []struct {
    22  			ID          string   `json:"licenseId"`
    23  			Name        string   `json:"name"`
    24  			Text        string   `json:"licenseText"`
    25  			Deprecated  bool     `json:"isDeprecatedLicenseId"`
    26  			OSIApproved bool     `json:"isOsiApproved"`
    27  			SeeAlso     []string `json:"seeAlso"`
    28  		} `json:"licenses"`
    29  	}
    30  
    31  	var latest licenseList
    32  	if err = json.NewDecoder(resp.Body).Decode(&latest); err != nil {
    33  		t.Fatalf("unable to decode license list: %+v", err)
    34  	}
    35  
    36  	assert.Equal(t, latest.Version, spdxlicense.Version)
    37  }