Skip to content

Commit 35e3475

Browse files
committed
test Pkg.Name()
1 parent e1d6791 commit 35e3475

4 files changed

Lines changed: 57 additions & 0 deletions

File tree

src/go/cmd/pkg_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package cmd
5+
6+
import (
7+
"path/filepath"
8+
"testing"
9+
10+
"github.com/stretchr/testify/require"
11+
)
12+
13+
func TestName(t *testing.T) {
14+
for _, test := range []struct {
15+
modulePath, moduleRoot, pkgPath, want string
16+
}{
17+
{
18+
modulePath: "test_package_name",
19+
moduleRoot: "testdata/test_package_name/test_package_name@v1.0.0",
20+
want: "test_package_name",
21+
},
22+
{
23+
modulePath: "test_package_name",
24+
moduleRoot: "testdata/test_package_name/test_package_name@v1.0.0",
25+
pkgPath: "subpackage",
26+
want: "test_package_name/subpackage",
27+
},
28+
{
29+
modulePath: "test_subpackage",
30+
moduleRoot: "testdata/test_subpackage",
31+
want: "test_subpackage",
32+
},
33+
{
34+
modulePath: "test_subpackage",
35+
moduleRoot: "testdata/test_subpackage",
36+
pkgPath: "subpackage",
37+
want: "test_subpackage/subpackage",
38+
},
39+
} {
40+
t.Run("", func(t *testing.T) {
41+
d, err := filepath.Abs(test.moduleRoot)
42+
require.NoError(t, err)
43+
p, err := NewPkg(filepath.Join(d, test.pkgPath), test.modulePath, d)
44+
require.NoError(t, err)
45+
require.Equal(t, test.want, p.Name())
46+
})
47+
}
48+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module test_package_name
2+
3+
go 1.18
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package subpackage
2+
3+
type S string
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package test_package_name
2+
3+
type S string

0 commit comments

Comments
 (0)