Skip to content

Commit d8f4875

Browse files
committed
test path updates
1 parent ffadef3 commit d8f4875

File tree

8 files changed

+177
-143
lines changed

8 files changed

+177
-143
lines changed

go/internal/changefile/change_types_test.go

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ import (
44
"testing"
55

66
"github.com/microsoft/beachball/internal/changefile"
7+
"github.com/microsoft/beachball/internal/testutil"
78
"github.com/microsoft/beachball/internal/types"
89
)
910

11+
var testRoot = testutil.FakeRoot()
12+
1013
func TestGetDisallowedChangeTypes_ReturnsNilForUnknownPackage(t *testing.T) {
1114
infos := types.PackageInfos{}
1215
groups := types.PackageGroups{}
@@ -19,12 +22,7 @@ func TestGetDisallowedChangeTypes_ReturnsNilForUnknownPackage(t *testing.T) {
1922
}
2023

2124
func TestGetDisallowedChangeTypes_ReturnsNilWhenNoSettings(t *testing.T) {
22-
infos := types.PackageInfos{
23-
"foo": &types.PackageInfo{
24-
Name: "foo",
25-
Version: "1.0.0",
26-
},
27-
}
25+
infos := testutil.MakePackageInfosSimple(testRoot, "foo")
2826
groups := types.PackageGroups{}
2927
opts := &types.BeachballOptions{}
3028

@@ -35,14 +33,9 @@ func TestGetDisallowedChangeTypes_ReturnsNilWhenNoSettings(t *testing.T) {
3533
}
3634

3735
func TestGetDisallowedChangeTypes_ReturnsPackageLevelDisallowedTypes(t *testing.T) {
38-
infos := types.PackageInfos{
39-
"foo": &types.PackageInfo{
40-
Name: "foo",
41-
Version: "1.0.0",
42-
PackageOptions: &types.PackageOptions{
43-
DisallowedChangeTypes: []string{"major"},
44-
},
45-
},
36+
infos := testutil.MakePackageInfosSimple(testRoot, "foo")
37+
infos["foo"].PackageOptions = &types.PackageOptions{
38+
DisallowedChangeTypes: []string{"major"},
4639
}
4740
groups := types.PackageGroups{}
4841
opts := &types.BeachballOptions{}
@@ -54,12 +47,7 @@ func TestGetDisallowedChangeTypes_ReturnsPackageLevelDisallowedTypes(t *testing.
5447
}
5548

5649
func TestGetDisallowedChangeTypes_ReturnsGroupLevelDisallowedTypes(t *testing.T) {
57-
infos := types.PackageInfos{
58-
"foo": &types.PackageInfo{
59-
Name: "foo",
60-
Version: "1.0.0",
61-
},
62-
}
50+
infos := testutil.MakePackageInfosSimple(testRoot, "foo")
6351
groups := types.PackageGroups{
6452
"grp1": &types.PackageGroup{
6553
Name: "grp1",
@@ -76,12 +64,7 @@ func TestGetDisallowedChangeTypes_ReturnsGroupLevelDisallowedTypes(t *testing.T)
7664
}
7765

7866
func TestGetDisallowedChangeTypes_ReturnsNilIfNotInGroup(t *testing.T) {
79-
infos := types.PackageInfos{
80-
"bar": &types.PackageInfo{
81-
Name: "bar",
82-
Version: "1.0.0",
83-
},
84-
}
67+
infos := testutil.MakePackageInfosSimple(testRoot, "bar")
8568
groups := types.PackageGroups{
8669
"grp1": &types.PackageGroup{
8770
Name: "grp1",
@@ -98,14 +81,9 @@ func TestGetDisallowedChangeTypes_ReturnsNilIfNotInGroup(t *testing.T) {
9881
}
9982

10083
func TestGetDisallowedChangeTypes_PrefersPackageOverGroup(t *testing.T) {
101-
infos := types.PackageInfos{
102-
"foo": &types.PackageInfo{
103-
Name: "foo",
104-
Version: "1.0.0",
105-
PackageOptions: &types.PackageOptions{
106-
DisallowedChangeTypes: []string{"major"},
107-
},
108-
},
84+
infos := testutil.MakePackageInfosSimple(testRoot, "foo")
85+
infos["foo"].PackageOptions = &types.PackageOptions{
86+
DisallowedChangeTypes: []string{"major"},
10987
}
11088
groups := types.PackageGroups{
11189
"grp1": &types.PackageGroup{

go/internal/monorepo/package_groups.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,4 @@ func GetPackageGroups(packageInfos types.PackageInfos, rootPath string, groups [
5555
}
5656

5757
return result
58-
}
58+
}

go/internal/monorepo/package_groups_test.go

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,28 @@
11
package monorepo_test
22

33
import (
4-
"path/filepath"
54
"sort"
65
"testing"
76

87
"github.com/microsoft/beachball/internal/monorepo"
8+
"github.com/microsoft/beachball/internal/testutil"
99
"github.com/microsoft/beachball/internal/types"
1010
)
1111

12-
func makeInfos(root string, folders map[string]string) types.PackageInfos {
13-
infos := make(types.PackageInfos)
14-
for folder, name := range folders {
15-
infos[name] = &types.PackageInfo{
16-
Name: name,
17-
Version: "1.0.0",
18-
PackageJSONPath: filepath.Join(root, folder, "package.json"),
19-
}
20-
}
21-
return infos
22-
}
12+
var root = testutil.FakeRoot()
2313

2414
func TestGetPackageGroups_ReturnsEmptyIfNoGroups(t *testing.T) {
25-
infos := makeInfos("/repo", map[string]string{
15+
infos := testutil.MakePackageInfos(root, map[string]string{
2616
"packages/foo": "foo",
2717
})
28-
result := monorepo.GetPackageGroups(infos, "/repo", nil)
18+
result := monorepo.GetPackageGroups(infos, root, nil)
2919
if len(result) != 0 {
3020
t.Fatalf("expected empty map, got: %v", result)
3121
}
3222
}
3323

3424
func TestGetPackageGroups_ReturnsGroupsBasedOnSpecificFolders(t *testing.T) {
35-
infos := makeInfos("/repo", map[string]string{
25+
infos := testutil.MakePackageInfos(root, map[string]string{
3626
"packages/foo": "foo",
3727
"packages/bar": "bar",
3828
"packages/baz": "baz",
@@ -43,7 +33,7 @@ func TestGetPackageGroups_ReturnsGroupsBasedOnSpecificFolders(t *testing.T) {
4333
Include: []string{"packages/foo", "packages/bar"},
4434
},
4535
}
46-
result := monorepo.GetPackageGroups(infos, "/repo", groups)
36+
result := monorepo.GetPackageGroups(infos, root, groups)
4737
if len(result) != 1 {
4838
t.Fatalf("expected 1 group, got %d", len(result))
4939
}
@@ -61,7 +51,7 @@ func TestGetPackageGroups_ReturnsGroupsBasedOnSpecificFolders(t *testing.T) {
6151
}
6252

6353
func TestGetPackageGroups_HandlesSingleLevelGlobs(t *testing.T) {
64-
infos := makeInfos("/repo", map[string]string{
54+
infos := testutil.MakePackageInfos(root, map[string]string{
6555
"packages/ui-button": "ui-button",
6656
"packages/ui-input": "ui-input",
6757
"packages/core-utils": "core-utils",
@@ -72,7 +62,7 @@ func TestGetPackageGroups_HandlesSingleLevelGlobs(t *testing.T) {
7262
Include: []string{"packages/ui-*"},
7363
},
7464
}
75-
result := monorepo.GetPackageGroups(infos, "/repo", groups)
65+
result := monorepo.GetPackageGroups(infos, root, groups)
7666
grp := result["ui"]
7767
if grp == nil {
7868
t.Fatal("expected ui group to exist")
@@ -87,7 +77,7 @@ func TestGetPackageGroups_HandlesSingleLevelGlobs(t *testing.T) {
8777
}
8878

8979
func TestGetPackageGroups_HandlesMultiLevelGlobs(t *testing.T) {
90-
infos := makeInfos("/repo", map[string]string{
80+
infos := testutil.MakePackageInfos(root, map[string]string{
9181
"packages/ui/button": "ui-button",
9282
"packages/ui/input": "ui-input",
9383
"packages/core": "core",
@@ -98,7 +88,7 @@ func TestGetPackageGroups_HandlesMultiLevelGlobs(t *testing.T) {
9888
Include: []string{"packages/ui/**"},
9989
},
10090
}
101-
result := monorepo.GetPackageGroups(infos, "/repo", groups)
91+
result := monorepo.GetPackageGroups(infos, root, groups)
10292
grp := result["ui"]
10393
if grp == nil {
10494
t.Fatal("expected ui group to exist")
@@ -113,7 +103,7 @@ func TestGetPackageGroups_HandlesMultiLevelGlobs(t *testing.T) {
113103
}
114104

115105
func TestGetPackageGroups_HandlesMultipleIncludePatterns(t *testing.T) {
116-
infos := makeInfos("/repo", map[string]string{
106+
infos := testutil.MakePackageInfos(root, map[string]string{
117107
"packages/foo": "foo",
118108
"libs/bar": "bar",
119109
"other/baz": "baz",
@@ -124,7 +114,7 @@ func TestGetPackageGroups_HandlesMultipleIncludePatterns(t *testing.T) {
124114
Include: []string{"packages/*", "libs/*"},
125115
},
126116
}
127-
result := monorepo.GetPackageGroups(infos, "/repo", groups)
117+
result := monorepo.GetPackageGroups(infos, root, groups)
128118
grp := result["mixed"]
129119
if grp == nil {
130120
t.Fatal("expected mixed group to exist")
@@ -139,7 +129,7 @@ func TestGetPackageGroups_HandlesMultipleIncludePatterns(t *testing.T) {
139129
}
140130

141131
func TestGetPackageGroups_HandlesExcludePatterns(t *testing.T) {
142-
infos := makeInfos("/repo", map[string]string{
132+
infos := testutil.MakePackageInfos(root, map[string]string{
143133
"packages/foo": "foo",
144134
"packages/bar": "bar",
145135
"packages/internal": "internal",
@@ -151,7 +141,7 @@ func TestGetPackageGroups_HandlesExcludePatterns(t *testing.T) {
151141
Exclude: []string{"packages/internal"},
152142
},
153143
}
154-
result := monorepo.GetPackageGroups(infos, "/repo", groups)
144+
result := monorepo.GetPackageGroups(infos, root, groups)
155145
grp := result["public"]
156146
if grp == nil {
157147
t.Fatal("expected public group to exist")
@@ -166,7 +156,7 @@ func TestGetPackageGroups_HandlesExcludePatterns(t *testing.T) {
166156
}
167157

168158
func TestGetPackageGroups_HandlesGlobExclude(t *testing.T) {
169-
infos := makeInfos("/repo", map[string]string{
159+
infos := testutil.MakePackageInfos(root, map[string]string{
170160
"packages/ui/button": "ui-button",
171161
"packages/ui/input": "ui-input",
172162
"packages/core/utils": "core-utils",
@@ -178,7 +168,7 @@ func TestGetPackageGroups_HandlesGlobExclude(t *testing.T) {
178168
Exclude: []string{"packages/core/*"},
179169
},
180170
}
181-
result := monorepo.GetPackageGroups(infos, "/repo", groups)
171+
result := monorepo.GetPackageGroups(infos, root, groups)
182172
grp := result["non-core"]
183173
if grp == nil {
184174
t.Fatal("expected non-core group to exist")
@@ -193,7 +183,7 @@ func TestGetPackageGroups_HandlesGlobExclude(t *testing.T) {
193183
}
194184

195185
func TestGetPackageGroups_OmitsEmptyGroups(t *testing.T) {
196-
infos := makeInfos("/repo", map[string]string{
186+
infos := testutil.MakePackageInfos(root, map[string]string{
197187
"packages/foo": "foo",
198188
})
199189
groups := []types.VersionGroupOptions{
@@ -202,7 +192,7 @@ func TestGetPackageGroups_OmitsEmptyGroups(t *testing.T) {
202192
Include: []string{"nonexistent/*"},
203193
},
204194
}
205-
result := monorepo.GetPackageGroups(infos, "/repo", groups)
195+
result := monorepo.GetPackageGroups(infos, root, groups)
206196
grp := result["empty"]
207197
if grp == nil {
208198
t.Fatal("expected empty group key to exist")

go/internal/monorepo/scoped_packages.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,4 @@ func GetScopedPackages(options *types.BeachballOptions, packageInfos types.Packa
8080
}
8181

8282
return scoped
83-
}
83+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package testutil
2+
3+
import (
4+
"path/filepath"
5+
"runtime"
6+
7+
"github.com/microsoft/beachball/internal/types"
8+
)
9+
10+
// FakeRoot returns a fake root path appropriate for the current OS
11+
// (e.g. "/fake-root" on Unix, `C:\fake-root` on Windows).
12+
func FakeRoot() string {
13+
if runtime.GOOS == "windows" {
14+
return `C:\fake-root`
15+
}
16+
return "/fake-root"
17+
}
18+
19+
// MakePackageInfos builds PackageInfos from a map of folder->name, with root prefix.
20+
func MakePackageInfos(root string, folders map[string]string) types.PackageInfos {
21+
infos := make(types.PackageInfos)
22+
for folder, name := range folders {
23+
infos[name] = &types.PackageInfo{
24+
Name: name,
25+
Version: "1.0.0",
26+
PackageJSONPath: filepath.Join(root, folder, "package.json"),
27+
}
28+
}
29+
return infos
30+
}
31+
32+
// MakePackageInfosSimple builds PackageInfos from names, defaulting folder to packages/{name}.
33+
func MakePackageInfosSimple(root string, names ...string) types.PackageInfos {
34+
folders := make(map[string]string, len(names))
35+
for _, name := range names {
36+
folders[filepath.Join("packages", name)] = name
37+
}
38+
return MakePackageInfos(root, folders)
39+
}

rust/tests/common/mod.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ pub mod repository;
77
#[allow(dead_code)]
88
pub mod repository_factory;
99

10+
use std::path::Path;
1011
use std::process::Command;
1112

1213
use beachball::options::get_options::get_parsed_options_for_test;
1314
use beachball::types::options::{BeachballOptions, CliOptions};
15+
use beachball::types::package_info::{PackageInfo, PackageInfos};
1416

1517
#[allow(dead_code)]
1618
pub const DEFAULT_BRANCH: &str = "master";
@@ -35,6 +37,55 @@ pub fn run_git(args: &[&str], cwd: &str) -> String {
3537
String::from_utf8_lossy(&output.stdout).trim().to_string()
3638
}
3739

40+
/// Returns a fake root path appropriate for the current OS
41+
/// (e.g. `/fake-root` on Unix, `C:\fake-root` on Windows).
42+
#[allow(dead_code)]
43+
pub fn fake_root() -> String {
44+
if cfg!(windows) {
45+
r"C:\fake-root".to_string()
46+
} else {
47+
"/fake-root".to_string()
48+
}
49+
}
50+
51+
/// Build PackageInfos from (name, folder) pairs with default version "1.0.0".
52+
#[allow(dead_code)]
53+
pub fn make_package_infos(packages: &[(&str, &str)], root: &str) -> PackageInfos {
54+
let mut infos = PackageInfos::new();
55+
for (name, folder) in packages {
56+
infos.insert(
57+
name.to_string(),
58+
PackageInfo {
59+
name: name.to_string(),
60+
package_json_path: Path::new(root)
61+
.join(folder)
62+
.join("package.json")
63+
.to_string_lossy()
64+
.to_string(),
65+
version: "1.0.0".to_string(),
66+
..Default::default()
67+
},
68+
);
69+
}
70+
infos
71+
}
72+
73+
/// Build PackageInfos from names only. Puts each package in `packages/{name}/`.
74+
#[allow(dead_code)]
75+
pub fn make_package_infos_simple(names: &[&str], root: &str) -> PackageInfos {
76+
let pairs: Vec<(&str, String)> = names
77+
.iter()
78+
.map(|n| {
79+
(
80+
*n,
81+
Path::new("packages").join(n).to_string_lossy().to_string(),
82+
)
83+
})
84+
.collect();
85+
let refs: Vec<(&str, &str)> = pairs.iter().map(|(n, f)| (*n, f.as_str())).collect();
86+
make_package_infos(&refs, root)
87+
}
88+
3889
/// Build merged options for a test repo. Applies default branch/fetch settings.
3990
#[allow(dead_code)]
4091
pub fn make_test_options(cwd: &str, overrides: Option<BeachballOptions>) -> BeachballOptions {

0 commit comments

Comments
 (0)