github.com/anchore/syft@v1.38.2/syft/pkg/cataloger/python/virtual_env_test.go (about)

     1  package python
     2  
     3  import (
     4  	"os"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  	"github.com/stretchr/testify/require"
     9  
    10  	"github.com/anchore/syft/syft/file"
    11  )
    12  
    13  func Test_parsePyvenvCfgReader(t *testing.T) {
    14  	location := file.NewLocation("/some/bogus/path")
    15  
    16  	tests := []struct {
    17  		name    string
    18  		fixture string
    19  		want    *virtualEnvInfo
    20  		wantErr require.ErrorAssertionFunc
    21  	}{
    22  		{
    23  			name:    "parse basic pyenv file",
    24  			fixture: "test-fixtures/pyenv/good-config",
    25  			want: &virtualEnvInfo{
    26  				Location:                  location,
    27  				Version:                   "3.9.5",
    28  				IncludeSystemSitePackages: true,
    29  			},
    30  		},
    31  		{
    32  			name:    "trixy config cases",
    33  			fixture: "test-fixtures/pyenv/trixy-config",
    34  			want: &virtualEnvInfo{
    35  				Location:                  location,
    36  				Version:                   "3.3.3",
    37  				IncludeSystemSitePackages: true,
    38  			},
    39  		},
    40  	}
    41  	for _, tt := range tests {
    42  		t.Run(tt.name, func(t *testing.T) {
    43  			if tt.wantErr == nil {
    44  				tt.wantErr = require.NoError
    45  			}
    46  			reader, err := os.Open(tt.fixture)
    47  			require.NoError(t, err)
    48  
    49  			got, err := parsePyvenvCfgReader(file.NewLocationReadCloser(location, reader))
    50  			tt.wantErr(t, err)
    51  			assert.Equal(t, tt.want, got)
    52  		})
    53  	}
    54  }