mirror of
https://github.com/go-micro/go-micro.git
synced 2025-06-18 22:17:44 +02:00
Runtime name should be base folder outside repos (#1598)
This commit is contained in:
@ -5,14 +5,14 @@ import (
|
||||
)
|
||||
|
||||
type parseCase struct {
|
||||
url string
|
||||
source string
|
||||
expected *Source
|
||||
}
|
||||
|
||||
func TestParseSource(t *testing.T) {
|
||||
cases := []parseCase{
|
||||
{
|
||||
url: "helloworld",
|
||||
source: "helloworld",
|
||||
expected: &Source{
|
||||
Repo: "github.com/micro/services",
|
||||
Folder: "helloworld",
|
||||
@ -20,7 +20,7 @@ func TestParseSource(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
url: "github.com/micro/services/helloworld",
|
||||
source: "github.com/micro/services/helloworld",
|
||||
expected: &Source{
|
||||
Repo: "github.com/micro/services",
|
||||
Folder: "helloworld",
|
||||
@ -28,7 +28,7 @@ func TestParseSource(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
url: "github.com/micro/services/helloworld@v1.12.1",
|
||||
source: "github.com/micro/services/helloworld@v1.12.1",
|
||||
expected: &Source{
|
||||
Repo: "github.com/micro/services",
|
||||
Folder: "helloworld",
|
||||
@ -36,7 +36,7 @@ func TestParseSource(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
url: "github.com/micro/services/helloworld@branchname",
|
||||
source: "github.com/micro/services/helloworld@branchname",
|
||||
expected: &Source{
|
||||
Repo: "github.com/micro/services",
|
||||
Folder: "helloworld",
|
||||
@ -44,7 +44,7 @@ func TestParseSource(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
url: "github.com/crufter/reponame/helloworld@branchname",
|
||||
source: "github.com/crufter/reponame/helloworld@branchname",
|
||||
expected: &Source{
|
||||
Repo: "github.com/crufter/reponame",
|
||||
Folder: "helloworld",
|
||||
@ -53,7 +53,45 @@ func TestParseSource(t *testing.T) {
|
||||
},
|
||||
}
|
||||
for i, c := range cases {
|
||||
result, err := ParseSource(c.url)
|
||||
result, err := ParseSource(c.source)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed case %v: %v", i, err)
|
||||
}
|
||||
if result.Folder != c.expected.Folder {
|
||||
t.Fatalf("Folder does not match for '%v', expected '%v', got '%v'", i, c.expected.Folder, result.Folder)
|
||||
}
|
||||
if result.Repo != c.expected.Repo {
|
||||
t.Fatalf("Repo address does not match for '%v', expected '%v', got '%v'", i, c.expected.Repo, result.Repo)
|
||||
}
|
||||
if result.Ref != c.expected.Ref {
|
||||
t.Fatalf("Ref does not match for '%v', expected '%v', got '%v'", i, c.expected.Ref, result.Ref)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type localParseCase struct {
|
||||
source string
|
||||
expected *Source
|
||||
workDir string
|
||||
pathExists bool
|
||||
}
|
||||
|
||||
func TestLocalParseSource(t *testing.T) {
|
||||
cases := []localParseCase{
|
||||
{
|
||||
source: ".",
|
||||
expected: &Source{
|
||||
Folder: "folder2",
|
||||
Ref: "latest",
|
||||
},
|
||||
workDir: "/folder1/folder2",
|
||||
pathExists: true,
|
||||
},
|
||||
}
|
||||
for i, c := range cases {
|
||||
result, err := ParseSourceLocal(c.workDir, c.source, func(s string) (bool, error) {
|
||||
return c.pathExists, nil
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("Failed case %v: %v", i, err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user