go.mondoo.com/cnquery@v0.0.0-20231005093811-59568235f6ea/_motor/discovery/common/projectname_test.go (about) 1 // Copyright (c) Mondoo, Inc. 2 // SPDX-License-Identifier: BUSL-1.1 3 4 package common 5 6 import ( 7 "testing" 8 9 "github.com/stretchr/testify/assert" 10 ) 11 12 func TestProjectName(t *testing.T) { 13 // absolute path where the file does not exist locally 14 assert.Equal(t, "projectname", ProjectNameFromPath("/testdata/terraform/projectname")) 15 assert.Equal(t, "file", ProjectNameFromPath("/testdata/terraform/projectname/file.tf")) 16 assert.Equal(t, "manifest", ProjectNameFromPath("/testdata/terraform/projectname/manifest.yaml")) 17 // relative path where the file does not exist locally 18 assert.Equal(t, "manifest", ProjectNameFromPath("./projectname/manifest.yaml")) 19 assert.Equal(t, "manifest", ProjectNameFromPath("./manifest.yaml")) 20 // if we get a directory which exists, add it to the project name to be more expressive 21 assert.Equal(t, "directory azure", ProjectNameFromPath("../azure")) 22 // if we get a dot, use the current directory since . does not make any sense 23 assert.Equal(t, "directory common", ProjectNameFromPath(".")) 24 }