From 749da47c998f9707c261262da236acb8db33d16a Mon Sep 17 00:00:00 2001 From: Serge Smertin Date: Mon, 16 May 2022 13:14:27 +0200 Subject: [PATCH] fix test on github actions --- project/config.go | 14 +++++++++++++- project/config_test.go | 7 +++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/project/config.go b/project/config.go index 13bac13fa..483312198 100644 --- a/project/config.go +++ b/project/config.go @@ -8,6 +8,7 @@ import ( "os" "path" "reflect" + "strings" "github.com/databrickslabs/terraform-provider-databricks/clusters" "github.com/ghodss/yaml" @@ -32,7 +33,7 @@ type Assertions struct { } type Project struct { - Name string `json:"name"` // or do default from folder name?.. + Name string `json:"name"` // or do default from folder name?.. Profile string `json:"profile,omitempty"` // rename? Isolation Isolation `json:"isolation,omitempty"` @@ -135,6 +136,17 @@ func getGitOrigin() (*url.URL, error) { return gitUrls.Parse(url.Value()) } +// GitRepositoryName returns repository name as last path entry from detected +// git repository up the tree or returns error if it fails to do so. +func GitRepositoryName() (string, error) { + origin, err := getGitOrigin() + if err != nil { + return "", err + } + base := path.Base(origin.Path) + return strings.ReplaceAll(base, ".git", ""), nil +} + func findDirWithLeaf(leaf string) (string, error) { dir, err := os.Getwd() if err != nil { diff --git a/project/config_test.go b/project/config_test.go index 0b76db3b2..5c3501100 100644 --- a/project/config_test.go +++ b/project/config_test.go @@ -3,7 +3,6 @@ package project import ( "fmt" "os" - "path" "testing" "github.com/stretchr/testify/assert" @@ -30,9 +29,9 @@ func TestFindProjectRootInRoot(t *testing.T) { } func TestGetGitOrigin(t *testing.T) { - origin, err := getGitOrigin() + this, err := GitRepositoryName() assert.NoError(t, err) - assert.Equal(t, "bricks.git", path.Base(origin.Path)) + assert.Equal(t, "bricks", this) } func TestLoadProjectConf(t *testing.T) { @@ -44,4 +43,4 @@ func TestLoadProjectConf(t *testing.T) { assert.NoError(t, err) assert.Equal(t, "dev", prj.Name) assert.True(t, prj.IsDevClusterJustReference()) -} \ No newline at end of file +}