github.com/nextlinux/gosbom@v0.81.1-0.20230627115839-1ff50c281391/gosbom/formats/common/cyclonedxhelpers/format_test.go (about)

     1  package cyclonedxhelpers
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func Test_formatCPE(t *testing.T) {
    10  	tests := []struct {
    11  		cpe      string
    12  		expected string
    13  	}{
    14  		{
    15  			cpe:      "cpe:2.3:o:amazon:amazon_linux:2",
    16  			expected: "cpe:2.3:o:amazon:amazon_linux:2:*:*:*:*:*:*:*",
    17  		},
    18  		{
    19  			cpe:      "cpe:/o:opensuse:leap:15.2",
    20  			expected: "cpe:2.3:o:opensuse:leap:15.2:*:*:*:*:*:*:*",
    21  		},
    22  		{
    23  			cpe:      "invalid-cpe",
    24  			expected: "",
    25  		},
    26  	}
    27  
    28  	for _, test := range tests {
    29  		t.Run(test.cpe, func(t *testing.T) {
    30  			out := formatCPE(test.cpe)
    31  			assert.Equal(t, test.expected, out)
    32  		})
    33  	}
    34  }