github.com/jfrog/jfrog-cli-core/v2@v2.51.0/utils/coreutils/techutils_test.go (about)

     1  package coreutils
     2  
     3  import (
     4  	"path/filepath"
     5  	"reflect"
     6  	"testing"
     7  
     8  	"github.com/stretchr/testify/assert"
     9  	"golang.org/x/exp/maps"
    10  )
    11  
    12  func TestDetectTechnologiesByFilePaths(t *testing.T) {
    13  	tests := []struct {
    14  		name     string
    15  		paths    []string
    16  		expected map[Technology]bool
    17  	}{
    18  		{"simpleMavenTest", []string{"pom.xml"}, map[Technology]bool{Maven: true}},
    19  		{"npmTest", []string{"../package.json"}, map[Technology]bool{Npm: true}},
    20  		{"pnpmTest", []string{"../package.json", "pnpm-lock.yaml"}, map[Technology]bool{Pnpm: true}},
    21  		{"yarnTest", []string{"./package.json", "./.yarn"}, map[Technology]bool{Yarn: true}},
    22  		{"windowsGradleTest", []string{"c:\\users\\test\\package\\build.gradle"}, map[Technology]bool{Gradle: true}},
    23  		{"windowsPipTest", []string{"c:\\users\\test\\package\\setup.py"}, map[Technology]bool{Pip: true}},
    24  		{"windowsPipenvTest", []string{"c:\\users\\test\\package\\Pipfile"}, map[Technology]bool{Pipenv: true}},
    25  		{"golangTest", []string{"/Users/eco/dev/jfrog-cli-core/go.mod"}, map[Technology]bool{Go: true}},
    26  		{"windowsNugetTest", []string{"c:\\users\\test\\package\\project.sln"}, map[Technology]bool{Nuget: true, Dotnet: true}},
    27  		{"noTechTest", []string{"pomxml"}, map[Technology]bool{}},
    28  	}
    29  
    30  	for _, test := range tests {
    31  		t.Run(test.name, func(t *testing.T) {
    32  			detectedTech := detectTechnologiesByFilePaths(test.paths, false)
    33  			assert.True(t, reflect.DeepEqual(test.expected, detectedTech), "expected: %s, actual: %s", test.expected, detectedTech)
    34  		})
    35  	}
    36  }
    37  
    38  func TestMapFilesToRelevantWorkingDirectories(t *testing.T) {
    39  	noRequest := map[Technology][]string{}
    40  	noExclude := map[string][]Technology{}
    41  
    42  	tests := []struct {
    43  		name                 string
    44  		paths                []string
    45  		requestedDescriptors map[Technology][]string
    46  		expectedWorkingDir   map[string][]string
    47  		expectedExcluded     map[string][]Technology
    48  	}{
    49  		{
    50  			name:                 "noTechTest",
    51  			paths:                []string{"pomxml", filepath.Join("sub1", "file"), filepath.Join("sub", "sub", "file")},
    52  			requestedDescriptors: noRequest,
    53  			expectedWorkingDir:   map[string][]string{},
    54  			expectedExcluded:     noExclude,
    55  		},
    56  		{
    57  			name:                 "mavenTest",
    58  			paths:                []string{"pom.xml", filepath.Join("sub1", "pom.xml"), filepath.Join("sub2", "pom.xml")},
    59  			requestedDescriptors: noRequest,
    60  			expectedWorkingDir: map[string][]string{
    61  				".":    {"pom.xml"},
    62  				"sub1": {filepath.Join("sub1", "pom.xml")},
    63  				"sub2": {filepath.Join("sub2", "pom.xml")},
    64  			},
    65  			expectedExcluded: noExclude,
    66  		},
    67  		{
    68  			name:                 "npmTest",
    69  			paths:                []string{filepath.Join("dir", "package.json"), filepath.Join("dir", "package-lock.json"), filepath.Join("dir2", "npm-shrinkwrap.json")},
    70  			requestedDescriptors: noRequest,
    71  			expectedWorkingDir: map[string][]string{
    72  				"dir":  {filepath.Join("dir", "package.json"), filepath.Join("dir", "package-lock.json")},
    73  				"dir2": {filepath.Join("dir2", "npm-shrinkwrap.json")},
    74  			},
    75  			expectedExcluded: noExclude,
    76  		},
    77  		{
    78  			name:                 "pnpmTest",
    79  			paths:                []string{filepath.Join("dir", "package.json"), filepath.Join("dir", "pnpm-lock.yaml")},
    80  			requestedDescriptors: noRequest,
    81  			expectedWorkingDir:   map[string][]string{"dir": {filepath.Join("dir", "package.json"), filepath.Join("dir", "pnpm-lock.yaml")}},
    82  			expectedExcluded:     map[string][]Technology{"dir": {Npm, Yarn}},
    83  		},
    84  		{
    85  			name:                 "yarnTest",
    86  			paths:                []string{filepath.Join("dir", "package.json"), filepath.Join("dir", ".yarn")},
    87  			requestedDescriptors: noRequest,
    88  			expectedWorkingDir:   map[string][]string{"dir": {filepath.Join("dir", "package.json"), filepath.Join("dir", ".yarn")}},
    89  			expectedExcluded:     map[string][]Technology{"dir": {Npm, Pnpm}},
    90  		},
    91  		{
    92  			name:                 "golangTest",
    93  			paths:                []string{filepath.Join("dir", "dir2", "go.mod")},
    94  			requestedDescriptors: noRequest,
    95  			expectedWorkingDir:   map[string][]string{filepath.Join("dir", "dir2"): {filepath.Join("dir", "dir2", "go.mod")}},
    96  			expectedExcluded:     noExclude,
    97  		},
    98  		{
    99  			name: "pipTest",
   100  			paths: []string{
   101  				filepath.Join("users_dir", "test", "package", "setup.py"),
   102  				filepath.Join("users_dir", "test", "package", "blabla.txt"),
   103  				filepath.Join("users_dir", "test", "package2", "requirements.txt"),
   104  			},
   105  			requestedDescriptors: noRequest,
   106  			expectedWorkingDir: map[string][]string{
   107  				filepath.Join("users_dir", "test", "package"):  {filepath.Join("users_dir", "test", "package", "setup.py")},
   108  				filepath.Join("users_dir", "test", "package2"): {filepath.Join("users_dir", "test", "package2", "requirements.txt")}},
   109  			expectedExcluded: noExclude,
   110  		},
   111  		{
   112  			name:                 "pipRequestedDescriptorTest",
   113  			paths:                []string{filepath.Join("dir", "blabla.txt"), filepath.Join("dir", "somefile")},
   114  			requestedDescriptors: map[Technology][]string{Pip: {"blabla.txt"}},
   115  			expectedWorkingDir:   map[string][]string{"dir": {filepath.Join("dir", "blabla.txt")}},
   116  			expectedExcluded:     noExclude,
   117  		},
   118  		{
   119  			name:                 "pipenvTest",
   120  			paths:                []string{filepath.Join("users", "test", "package", "Pipfile")},
   121  			requestedDescriptors: noRequest,
   122  			expectedWorkingDir:   map[string][]string{filepath.Join("users", "test", "package"): {filepath.Join("users", "test", "package", "Pipfile")}},
   123  			expectedExcluded:     map[string][]Technology{filepath.Join("users", "test", "package"): {Pip}},
   124  		},
   125  		{
   126  			name:                 "gradleTest",
   127  			paths:                []string{filepath.Join("users", "test", "package", "build.gradle"), filepath.Join("dir", "build.gradle.kts"), filepath.Join("dir", "file")},
   128  			requestedDescriptors: noRequest,
   129  			expectedWorkingDir: map[string][]string{
   130  				filepath.Join("users", "test", "package"): {filepath.Join("users", "test", "package", "build.gradle")},
   131  				"dir": {filepath.Join("dir", "build.gradle.kts")},
   132  			},
   133  			expectedExcluded: noExclude,
   134  		},
   135  		{
   136  			name:                 "nugetTest",
   137  			paths:                []string{filepath.Join("dir", "project.sln"), filepath.Join("dir", "sub1", "project.csproj"), filepath.Join("dir", "file")},
   138  			requestedDescriptors: noRequest,
   139  			expectedWorkingDir: map[string][]string{
   140  				"dir":                        {filepath.Join("dir", "project.sln")},
   141  				filepath.Join("dir", "sub1"): {filepath.Join("dir", "sub1", "project.csproj")},
   142  			},
   143  			expectedExcluded: noExclude,
   144  		},
   145  	}
   146  	for _, test := range tests {
   147  		t.Run(test.name, func(t *testing.T) {
   148  			detectedWd, detectedExcluded := mapFilesToRelevantWorkingDirectories(test.paths, test.requestedDescriptors)
   149  			// Assert working directories
   150  			expectedKeys := maps.Keys(test.expectedWorkingDir)
   151  			actualKeys := maps.Keys(detectedWd)
   152  			assert.ElementsMatch(t, expectedKeys, actualKeys, "expected: %s, actual: %s", expectedKeys, actualKeys)
   153  			for key, value := range test.expectedWorkingDir {
   154  				assert.ElementsMatch(t, value, detectedWd[key], "expected: %s, actual: %s", value, detectedWd[key])
   155  			}
   156  			// Assert excluded
   157  			expectedKeys = maps.Keys(test.expectedExcluded)
   158  			actualKeys = maps.Keys(detectedExcluded)
   159  			assert.ElementsMatch(t, expectedKeys, actualKeys, "expected: %s, actual: %s", expectedKeys, actualKeys)
   160  			for key, value := range test.expectedExcluded {
   161  				assert.ElementsMatch(t, value, detectedExcluded[key], "expected: %s, actual: %s", value, detectedExcluded[key])
   162  			}
   163  		})
   164  	}
   165  }
   166  
   167  func TestMapWorkingDirectoriesToTechnologies(t *testing.T) {
   168  	noRequestSpecialDescriptors := map[Technology][]string{}
   169  	noRequestTech := []Technology{}
   170  	tests := []struct {
   171  		name                         string
   172  		workingDirectoryToIndicators map[string][]string
   173  		excludedTechAtWorkingDir     map[string][]Technology
   174  		requestedTechs               []Technology
   175  		requestedDescriptors         map[Technology][]string
   176  
   177  		expected map[Technology]map[string][]string
   178  	}{
   179  		{
   180  			name:                         "noTechTest",
   181  			workingDirectoryToIndicators: map[string][]string{},
   182  			excludedTechAtWorkingDir:     map[string][]Technology{},
   183  			requestedTechs:               noRequestTech,
   184  			requestedDescriptors:         noRequestSpecialDescriptors,
   185  			expected:                     map[Technology]map[string][]string{},
   186  		},
   187  		{
   188  			name: "all techs test",
   189  			workingDirectoryToIndicators: map[string][]string{
   190  				"folder":                        {filepath.Join("folder", "pom.xml")},
   191  				filepath.Join("folder", "sub1"): {filepath.Join("folder", "sub1", "pom.xml")},
   192  				filepath.Join("folder", "sub2"): {filepath.Join("folder", "sub2", "pom.xml")},
   193  				"dir":                           {filepath.Join("dir", "package.json"), filepath.Join("dir", "package-lock.json"), filepath.Join("dir", "build.gradle.kts"), filepath.Join("dir", "project.sln")},
   194  				"directory":                     {filepath.Join("directory", "npm-shrinkwrap.json")},
   195  				"dir3":                          {filepath.Join("dir3", "package.json"), filepath.Join("dir3", ".yarn")},
   196  				filepath.Join("dir3", "dir"):    {filepath.Join("dir3", "dir", "package.json"), filepath.Join("dir3", "dir", "pnpm-lock.yaml")},
   197  				filepath.Join("dir", "dir2"):    {filepath.Join("dir", "dir2", "go.mod")},
   198  				filepath.Join("users_dir", "test", "package"):  {filepath.Join("users_dir", "test", "package", "setup.py")},
   199  				filepath.Join("users_dir", "test", "package2"): {filepath.Join("users_dir", "test", "package2", "requirements.txt")},
   200  				filepath.Join("users", "test", "package"):      {filepath.Join("users", "test", "package", "Pipfile"), filepath.Join("users", "test", "package", "build.gradle")},
   201  				filepath.Join("dir", "sub1"):                   {filepath.Join("dir", "sub1", "project.csproj")},
   202  			},
   203  			excludedTechAtWorkingDir: map[string][]Technology{
   204  				filepath.Join("users", "test", "package"): {Pip},
   205  				"dir3":                       {Npm},
   206  				filepath.Join("dir3", "dir"): {Npm, Yarn},
   207  			},
   208  			requestedTechs:       noRequestTech,
   209  			requestedDescriptors: noRequestSpecialDescriptors,
   210  			expected: map[Technology]map[string][]string{
   211  				Maven: {"folder": {filepath.Join("folder", "pom.xml"), filepath.Join("folder", "sub1", "pom.xml"), filepath.Join("folder", "sub2", "pom.xml")}},
   212  				Npm: {
   213  					"dir":       {filepath.Join("dir", "package.json")},
   214  					"directory": {},
   215  				},
   216  				Pnpm: {filepath.Join("dir3", "dir"): {filepath.Join("dir3", "dir", "package.json")}},
   217  				Yarn: {"dir3": {filepath.Join("dir3", "package.json")}},
   218  				Go:   {filepath.Join("dir", "dir2"): {filepath.Join("dir", "dir2", "go.mod")}},
   219  				Pip: {
   220  					filepath.Join("users_dir", "test", "package"):  {filepath.Join("users_dir", "test", "package", "setup.py")},
   221  					filepath.Join("users_dir", "test", "package2"): {filepath.Join("users_dir", "test", "package2", "requirements.txt")},
   222  				},
   223  				Pipenv: {filepath.Join("users", "test", "package"): {filepath.Join("users", "test", "package", "Pipfile")}},
   224  				Gradle: {
   225  					"dir": {filepath.Join("dir", "build.gradle.kts")},
   226  					filepath.Join("users", "test", "package"): {filepath.Join("users", "test", "package", "build.gradle")},
   227  				},
   228  				Nuget:  {"dir": {filepath.Join("dir", "project.sln"), filepath.Join("dir", "sub1", "project.csproj")}},
   229  				Dotnet: {"dir": {filepath.Join("dir", "project.sln"), filepath.Join("dir", "sub1", "project.csproj")}},
   230  			},
   231  		},
   232  	}
   233  
   234  	for _, test := range tests {
   235  		t.Run(test.name, func(t *testing.T) {
   236  			detectedTech := mapWorkingDirectoriesToTechnologies(test.workingDirectoryToIndicators, test.excludedTechAtWorkingDir, test.requestedTechs, test.requestedDescriptors)
   237  			expectedKeys := maps.Keys(test.expected)
   238  			detectedKeys := maps.Keys(detectedTech)
   239  			assert.ElementsMatch(t, expectedKeys, detectedKeys, "expected: %s, actual: %s", expectedKeys, detectedKeys)
   240  			for key, value := range test.expected {
   241  				actualKeys := maps.Keys(detectedTech[key])
   242  				expectedKeys := maps.Keys(value)
   243  				assert.ElementsMatch(t, expectedKeys, actualKeys, "for tech %s, expected: %s, actual: %s", key, expectedKeys, actualKeys)
   244  				for innerKey, innerValue := range value {
   245  					assert.ElementsMatch(t, innerValue, detectedTech[key][innerKey], "expected: %s, actual: %s", innerValue, detectedTech[key][innerKey])
   246  				}
   247  			}
   248  		})
   249  	}
   250  }
   251  
   252  func TestGetExistingRootDir(t *testing.T) {
   253  	tests := []struct {
   254  		name                         string
   255  		path                         string
   256  		workingDirectoryToIndicators map[string][]string
   257  		expected                     string
   258  	}{
   259  		{
   260  			name:                         "empty",
   261  			path:                         "",
   262  			workingDirectoryToIndicators: map[string][]string{},
   263  			expected:                     "",
   264  		},
   265  		{
   266  			name: "no match",
   267  			path: "dir",
   268  			workingDirectoryToIndicators: map[string][]string{
   269  				filepath.Join("folder", "sub1"):    {filepath.Join("folder", "sub1", "pom.xml")},
   270  				"dir2":                             {filepath.Join("dir2", "go.mod")},
   271  				"dir3":                             {},
   272  				filepath.Join("directory", "dir2"): {filepath.Join("directory", "dir2", "go.mod")},
   273  			},
   274  			expected: "dir",
   275  		},
   276  		{
   277  			name: "match root",
   278  			path: filepath.Join("directory", "dir2"),
   279  			workingDirectoryToIndicators: map[string][]string{
   280  				filepath.Join("folder", "sub1"):    {filepath.Join("folder", "sub1", "pom.xml")},
   281  				"dir2":                             {filepath.Join("dir2", "go.mod")},
   282  				"dir3":                             {},
   283  				filepath.Join("directory", "dir2"): {filepath.Join("directory", "dir2", "go.mod")},
   284  			},
   285  			expected: filepath.Join("directory", "dir2"),
   286  		},
   287  		{
   288  			name: "match sub",
   289  			path: filepath.Join("directory", "dir2"),
   290  			workingDirectoryToIndicators: map[string][]string{
   291  				filepath.Join("folder", "sub1"):    {filepath.Join("folder", "sub1", "pom.xml")},
   292  				"dir2":                             {filepath.Join("dir2", "go.mod")},
   293  				"directory":                        {},
   294  				filepath.Join("directory", "dir2"): {filepath.Join("directory", "dir2", "go.mod")},
   295  			},
   296  			expected: "directory",
   297  		},
   298  	}
   299  	for _, test := range tests {
   300  		t.Run(test.name, func(t *testing.T) {
   301  			assert.Equal(t, test.expected, getExistingRootDir(test.path, test.workingDirectoryToIndicators))
   302  		})
   303  	}
   304  }
   305  
   306  func TestCleanSubDirectories(t *testing.T) {
   307  	tests := []struct {
   308  		name                    string
   309  		workingDirectoryToFiles map[string][]string
   310  		expected                map[string][]string
   311  	}{
   312  		{
   313  			name:                    "empty",
   314  			workingDirectoryToFiles: map[string][]string{},
   315  			expected:                map[string][]string{},
   316  		},
   317  		{
   318  			name: "no sub directories",
   319  			workingDirectoryToFiles: map[string][]string{
   320  				"directory":                       {filepath.Join("directory", "file")},
   321  				filepath.Join("dir", "dir"):       {filepath.Join("dir", "dir", "file")},
   322  				filepath.Join("dir", "directory"): {filepath.Join("dir", "directory", "file")},
   323  			},
   324  			expected: map[string][]string{
   325  				"directory":                       {filepath.Join("directory", "file")},
   326  				filepath.Join("dir", "dir"):       {filepath.Join("dir", "dir", "file")},
   327  				filepath.Join("dir", "directory"): {filepath.Join("dir", "directory", "file")},
   328  			},
   329  		},
   330  		{
   331  			name: "sub directories",
   332  			workingDirectoryToFiles: map[string][]string{
   333  				filepath.Join("dir", "dir"):                  {filepath.Join("dir", "dir", "file")},
   334  				filepath.Join("dir", "directory"):            {filepath.Join("dir", "directory", "file")},
   335  				"dir":                                        {filepath.Join("dir", "file")},
   336  				"directory":                                  {filepath.Join("directory", "file")},
   337  				filepath.Join("dir", "dir2"):                 {filepath.Join("dir", "dir2", "file")},
   338  				filepath.Join("dir", "dir2", "dir3"):         {filepath.Join("dir", "dir2", "dir3", "file")},
   339  				filepath.Join("dir", "dir2", "dir3", "dir4"): {filepath.Join("dir", "dir2", "dir3", "dir4", "file")},
   340  			},
   341  			expected: map[string][]string{
   342  				"directory": {filepath.Join("directory", "file")},
   343  				"dir": {
   344  					filepath.Join("dir", "file"),
   345  					filepath.Join("dir", "dir", "file"),
   346  					filepath.Join("dir", "directory", "file"),
   347  					filepath.Join("dir", "dir2", "file"),
   348  					filepath.Join("dir", "dir2", "dir3", "file"),
   349  					filepath.Join("dir", "dir2", "dir3", "dir4", "file"),
   350  				},
   351  			},
   352  		},
   353  	}
   354  	for _, test := range tests {
   355  		t.Run(test.name, func(t *testing.T) {
   356  			cleaned := cleanSubDirectories(test.workingDirectoryToFiles)
   357  			cleanedKeys := maps.Keys(cleaned)
   358  			expectedKeys := maps.Keys(test.expected)
   359  			assert.ElementsMatch(t, expectedKeys, cleanedKeys, "expected: %s, actual: %s", expectedKeys, cleanedKeys)
   360  			for key, value := range test.expected {
   361  				assert.ElementsMatch(t, value, cleaned[key], "expected: %s, actual: %s", value, cleaned[key])
   362  			}
   363  		})
   364  	}
   365  }
   366  
   367  func TestGetTechInformationFromWorkingDir(t *testing.T) {
   368  	workingDirectoryToIndicators := map[string][]string{
   369  		"folder":                        {filepath.Join("folder", "pom.xml")},
   370  		filepath.Join("folder", "sub1"): {filepath.Join("folder", "sub1", "pom.xml")},
   371  		filepath.Join("folder", "sub2"): {filepath.Join("folder", "sub2", "pom.xml")},
   372  		"dir":                           {filepath.Join("dir", "package.json"), filepath.Join("dir", "package-lock.json"), filepath.Join("dir", "build.gradle.kts"), filepath.Join("dir", "project.sln"), filepath.Join("dir", "blabla.txt")},
   373  		"directory":                     {filepath.Join("directory", "npm-shrinkwrap.json")},
   374  		"dir3":                          {filepath.Join("dir3", "package.json"), filepath.Join("dir3", ".yarn")},
   375  		filepath.Join("dir3", "dir"):    {filepath.Join("dir3", "dir", "package.json"), filepath.Join("dir3", "dir", "pnpm-lock.yaml")},
   376  		filepath.Join("dir", "dir2"):    {filepath.Join("dir", "dir2", "go.mod")},
   377  		filepath.Join("users_dir", "test", "package"):  {filepath.Join("users_dir", "test", "package", "setup.py")},
   378  		filepath.Join("users_dir", "test", "package2"): {filepath.Join("users_dir", "test", "package2", "requirements.txt")},
   379  		filepath.Join("users", "test", "package"):      {filepath.Join("users", "test", "package", "Pipfile"), filepath.Join("users", "test", "package", "build.gradle")},
   380  		filepath.Join("dir", "sub1"):                   {filepath.Join("dir", "sub1", "project.csproj")},
   381  	}
   382  	excludedTechAtWorkingDir := map[string][]Technology{
   383  		filepath.Join("users", "test", "package"): {Pip},
   384  		"dir3":                       {Npm, Pnpm},
   385  		filepath.Join("dir3", "dir"): {Npm, Yarn},
   386  	}
   387  
   388  	tests := []struct {
   389  		name                 string
   390  		tech                 Technology
   391  		requestedDescriptors map[Technology][]string
   392  		expected             map[string][]string
   393  	}{
   394  		{
   395  			name:                 "mavenTest",
   396  			tech:                 Maven,
   397  			requestedDescriptors: map[Technology][]string{},
   398  			expected: map[string][]string{
   399  				"folder": {
   400  					filepath.Join("folder", "pom.xml"),
   401  					filepath.Join("folder", "sub1", "pom.xml"),
   402  					filepath.Join("folder", "sub2", "pom.xml"),
   403  				},
   404  			},
   405  		},
   406  		{
   407  			name:                 "npmTest",
   408  			tech:                 Npm,
   409  			requestedDescriptors: map[Technology][]string{},
   410  			expected: map[string][]string{
   411  				"dir":       {filepath.Join("dir", "package.json")},
   412  				"directory": {},
   413  			},
   414  		},
   415  		{
   416  			name:                 "pnpmTest",
   417  			tech:                 Pnpm,
   418  			requestedDescriptors: map[Technology][]string{},
   419  			expected:             map[string][]string{filepath.Join("dir3", "dir"): {filepath.Join("dir3", "dir", "package.json")}},
   420  		},
   421  		{
   422  			name:                 "yarnTest",
   423  			tech:                 Yarn,
   424  			requestedDescriptors: map[Technology][]string{},
   425  			expected:             map[string][]string{"dir3": {filepath.Join("dir3", "package.json")}},
   426  		},
   427  		{
   428  			name:                 "golangTest",
   429  			tech:                 Go,
   430  			requestedDescriptors: map[Technology][]string{},
   431  			expected:             map[string][]string{filepath.Join("dir", "dir2"): {filepath.Join("dir", "dir2", "go.mod")}},
   432  		},
   433  		{
   434  			name:                 "pipTest",
   435  			tech:                 Pip,
   436  			requestedDescriptors: map[Technology][]string{},
   437  			expected: map[string][]string{
   438  				filepath.Join("users_dir", "test", "package"):  {filepath.Join("users_dir", "test", "package", "setup.py")},
   439  				filepath.Join("users_dir", "test", "package2"): {filepath.Join("users_dir", "test", "package2", "requirements.txt")},
   440  			},
   441  		},
   442  		{
   443  			name:                 "pipRequestedDescriptorTest",
   444  			tech:                 Pip,
   445  			requestedDescriptors: map[Technology][]string{Pip: {"blabla.txt"}},
   446  			expected: map[string][]string{
   447  				"dir": {filepath.Join("dir", "blabla.txt")},
   448  				filepath.Join("users_dir", "test", "package"):  {filepath.Join("users_dir", "test", "package", "setup.py")},
   449  				filepath.Join("users_dir", "test", "package2"): {filepath.Join("users_dir", "test", "package2", "requirements.txt")},
   450  			},
   451  		},
   452  		{
   453  			name:                 "pipenvTest",
   454  			tech:                 Pipenv,
   455  			requestedDescriptors: map[Technology][]string{},
   456  			expected:             map[string][]string{filepath.Join("users", "test", "package"): {filepath.Join("users", "test", "package", "Pipfile")}},
   457  		},
   458  		{
   459  			name:                 "gradleTest",
   460  			tech:                 Gradle,
   461  			requestedDescriptors: map[Technology][]string{},
   462  			expected: map[string][]string{
   463  				filepath.Join("users", "test", "package"): {filepath.Join("users", "test", "package", "build.gradle")},
   464  				"dir": {filepath.Join("dir", "build.gradle.kts")},
   465  			},
   466  		},
   467  		{
   468  			name:                 "nugetTest",
   469  			tech:                 Nuget,
   470  			requestedDescriptors: map[Technology][]string{},
   471  			expected:             map[string][]string{"dir": {filepath.Join("dir", "project.sln"), filepath.Join("dir", "sub1", "project.csproj")}},
   472  		},
   473  		{
   474  			name:                 "dotnetTest",
   475  			tech:                 Dotnet,
   476  			requestedDescriptors: map[Technology][]string{},
   477  			expected:             map[string][]string{"dir": {filepath.Join("dir", "project.sln"), filepath.Join("dir", "sub1", "project.csproj")}},
   478  		},
   479  	}
   480  
   481  	for _, test := range tests {
   482  		t.Run(test.name, func(t *testing.T) {
   483  			techInformation := getTechInformationFromWorkingDir(test.tech, workingDirectoryToIndicators, excludedTechAtWorkingDir, test.requestedDescriptors)
   484  			expectedKeys := maps.Keys(test.expected)
   485  			actualKeys := maps.Keys(techInformation)
   486  			assert.ElementsMatch(t, expectedKeys, actualKeys, "expected: %s, actual: %s", expectedKeys, actualKeys)
   487  			for key, value := range test.expected {
   488  				assert.ElementsMatch(t, value, techInformation[key], "expected: %s, actual: %s", value, techInformation[key])
   489  			}
   490  		})
   491  	}
   492  }
   493  
   494  func TestContainsApplicabilityScannableTech(t *testing.T) {
   495  	tests := []struct {
   496  		name         string
   497  		technologies []Technology
   498  		want         bool
   499  	}{
   500  		{name: "contains supported and unsupported techs", technologies: []Technology{Nuget, Go, Npm}, want: true},
   501  		{name: "contains supported techs only", technologies: []Technology{Maven, Yarn, Npm}, want: true},
   502  		{name: "contains unsupported techs only", technologies: []Technology{Dotnet, Nuget, Go}, want: false},
   503  	}
   504  	for _, tt := range tests {
   505  		t.Run(tt.name, func(t *testing.T) {
   506  			assert.Equal(t, tt.want, ContainsApplicabilityScannableTech(tt.technologies))
   507  		})
   508  	}
   509  }