github.com/devseccon/trivy@v0.47.1-0.20231123133102-bd902a0bd996/pkg/commands/artifact/run_test.go (about)

     1  package artifact
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/require"
     7  )
     8  
     9  func TestCanonicalVersion(t *testing.T) {
    10  	tests := []struct {
    11  		title string
    12  		input string
    13  		want  string
    14  	}{
    15  		{
    16  			title: "good way",
    17  			input: "0.34.0",
    18  			want:  "v0.34",
    19  		},
    20  		{
    21  			title: "version with v - isn't right semver version",
    22  			input: "v0.34.0",
    23  			want:  devVersion,
    24  		},
    25  		{
    26  			title: "dev version",
    27  			input: devVersion,
    28  			want:  devVersion,
    29  		},
    30  		{
    31  			title: "pre-release",
    32  			input: "v0.34.0-beta1+snapshot-1",
    33  			want:  devVersion,
    34  		},
    35  		{
    36  			title: "no version",
    37  			input: "",
    38  			want:  devVersion,
    39  		},
    40  	}
    41  
    42  	for _, test := range tests {
    43  		t.Run(test.title, func(t *testing.T) {
    44  			got := canonicalVersion(test.input)
    45  			require.Equal(t, test.want, got)
    46  		})
    47  	}
    48  }