fix test on github actions

This commit is contained in:
Serge Smertin 2022-05-16 13:14:27 +02:00
parent 5d8613b21b
commit 749da47c99
2 changed files with 16 additions and 5 deletions

View File

@ -8,6 +8,7 @@ import (
"os" "os"
"path" "path"
"reflect" "reflect"
"strings"
"github.com/databrickslabs/terraform-provider-databricks/clusters" "github.com/databrickslabs/terraform-provider-databricks/clusters"
"github.com/ghodss/yaml" "github.com/ghodss/yaml"
@ -32,7 +33,7 @@ type Assertions struct {
} }
type Project 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? Profile string `json:"profile,omitempty"` // rename?
Isolation Isolation `json:"isolation,omitempty"` Isolation Isolation `json:"isolation,omitempty"`
@ -135,6 +136,17 @@ func getGitOrigin() (*url.URL, error) {
return gitUrls.Parse(url.Value()) 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) { func findDirWithLeaf(leaf string) (string, error) {
dir, err := os.Getwd() dir, err := os.Getwd()
if err != nil { if err != nil {

View File

@ -3,7 +3,6 @@ package project
import ( import (
"fmt" "fmt"
"os" "os"
"path"
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -30,9 +29,9 @@ func TestFindProjectRootInRoot(t *testing.T) {
} }
func TestGetGitOrigin(t *testing.T) { func TestGetGitOrigin(t *testing.T) {
origin, err := getGitOrigin() this, err := GitRepositoryName()
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, "bricks.git", path.Base(origin.Path)) assert.Equal(t, "bricks", this)
} }
func TestLoadProjectConf(t *testing.T) { func TestLoadProjectConf(t *testing.T) {
@ -44,4 +43,4 @@ func TestLoadProjectConf(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, "dev", prj.Name) assert.Equal(t, "dev", prj.Name)
assert.True(t, prj.IsDevClusterJustReference()) assert.True(t, prj.IsDevClusterJustReference())
} }