Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b7be568

Browse files
authoredJun 19, 2023
Add CMT_HOME (or remove it?) (celestiaorg#983)
Closes celestiaorg#982 Added `CMT_HOME` everywhere `CMTHOME` is used. ### Notes to reviewers This could be fixed the opposite way, by removing the only reference to `CMT_HOME` in the code, and also the reference in `UPGRADING.md` (two lines of code). However, the reference in `UPGRADING.md`, which is part of our documentation, is already present in `v0.34.x` (not in `v0.37.x` though!). That's why this PR introduces `CMT_HOME` to work in equal conditions as `CMTHOME`. If reviewers lean toward removing `CMT_HOME` from the doc in `v0.34.x` (and unreleased `v0.38.x` and `main`), I can do it easily. --- #### PR checklist - [x] Tests written/updated - [ ] Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog) - [ ] Updated relevant documentation (`docs/` or `spec/`) and code comments
1 parent c0a5715 commit b7be568

File tree

2 files changed

+26
-34
lines changed

2 files changed

+26
-34
lines changed
 

‎UPGRADING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ on instead of `~/.tendermint`.
117117
### Environment variables
118118

119119
The environment variable prefixes have now changed from `TM` to `CMT`. For
120-
example, `TMHOME` or `TM_HOME` become `CMTHOME` or `CMT_HOME`.
120+
example, `TMHOME` becomes `CMTHOME`.
121121

122122
We have implemented a fallback check in case `TMHOME` is still set and `CMTHOME`
123123
is not, but you will start to see a warning message in the logs if the old

‎cmd/cometbft/commands/root_test.go

+25-33
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,12 @@ import (
1717
cmtos "github.com/cometbft/cometbft/libs/os"
1818
)
1919

20-
var defaultRoot = os.ExpandEnv("$HOME/.some/test/dir")
21-
2220
// clearConfig clears env vars, the given root dir, and resets viper.
23-
func clearConfig(dir string) {
24-
if err := os.Unsetenv("CMTHOME"); err != nil {
25-
panic(err)
26-
}
27-
if err := os.Unsetenv("CMT_HOME"); err != nil {
28-
panic(err)
29-
}
30-
if err := os.Unsetenv("TMHOME"); err != nil {
31-
// XXX: Deprecated.
32-
panic(err)
33-
}
34-
if err := os.Unsetenv("TM_HOME"); err != nil {
35-
// XXX: Deprecated.
36-
panic(err)
37-
}
21+
func clearConfig(t *testing.T, dir string) {
22+
os.Clearenv()
23+
err := os.RemoveAll(dir)
24+
require.NoError(t, err)
3825

39-
if err := os.RemoveAll(dir); err != nil {
40-
panic(err)
41-
}
4226
viper.Reset()
4327
config = cfg.DefaultConfig()
4428
}
@@ -56,34 +40,39 @@ func testRootCmd() *cobra.Command {
5640
return rootCmd
5741
}
5842

59-
func testSetup(args []string, env map[string]string) error {
60-
clearConfig(defaultRoot)
43+
func testSetup(t *testing.T, root string, args []string, env map[string]string) error {
44+
clearConfig(t, root)
6145

6246
rootCmd := testRootCmd()
63-
cmd := cli.PrepareBaseCmd(rootCmd, "CMT", defaultRoot)
47+
cmd := cli.PrepareBaseCmd(rootCmd, "CMT", root)
6448

6549
// run with the args and env
6650
args = append([]string{rootCmd.Use}, args...)
6751
return cli.RunWithArgs(cmd, args, env)
6852
}
6953

7054
func TestRootHome(t *testing.T) {
71-
newRoot := filepath.Join(defaultRoot, "something-else")
55+
tmpDir := os.TempDir()
56+
root := filepath.Join(tmpDir, "adir")
57+
newRoot := filepath.Join(tmpDir, "something-else")
58+
defer clearConfig(t, root)
59+
defer clearConfig(t, newRoot)
60+
7261
cases := []struct {
7362
args []string
7463
env map[string]string
7564
root string
7665
}{
77-
{nil, nil, defaultRoot},
66+
{nil, nil, root},
7867
{[]string{"--home", newRoot}, nil, newRoot},
7968
{nil, map[string]string{"TMHOME": newRoot}, newRoot}, // XXX: Deprecated.
8069
{nil, map[string]string{"CMTHOME": newRoot}, newRoot},
8170
}
8271

8372
for i, tc := range cases {
84-
idxString := strconv.Itoa(i)
73+
idxString := "idx: " + strconv.Itoa(i)
8574

86-
err := testSetup(tc.args, tc.env)
75+
err := testSetup(t, root, tc.args, tc.env)
8776
require.Nil(t, err, idxString)
8877

8978
assert.Equal(t, tc.root, config.RootDir, idxString)
@@ -115,8 +104,10 @@ func TestRootFlagsEnv(t *testing.T) {
115104

116105
for i, tc := range cases {
117106
idxString := strconv.Itoa(i)
118-
119-
err := testSetup(tc.args, tc.env)
107+
root := filepath.Join(os.TempDir(), "adir2_"+idxString)
108+
idxString = "idx: " + idxString
109+
defer clearConfig(t, root)
110+
err := testSetup(t, root, tc.args, tc.env)
120111
require.Nil(t, err, idxString)
121112

122113
assert.Equal(t, tc.logLevel, config.LogLevel, idxString)
@@ -144,10 +135,11 @@ func TestRootConfig(t *testing.T) {
144135

145136
for i, tc := range cases {
146137
idxString := strconv.Itoa(i)
147-
clearConfig(defaultRoot)
148-
138+
root := filepath.Join(os.TempDir(), "adir3_"+idxString)
139+
idxString = "idx: " + idxString
140+
defer clearConfig(t, root)
149141
// XXX: path must match cfg.defaultConfigPath
150-
configFilePath := filepath.Join(defaultRoot, "config")
142+
configFilePath := filepath.Join(root, "config")
151143
err := cmtos.EnsureDir(configFilePath, 0o700)
152144
require.Nil(t, err)
153145

@@ -157,7 +149,7 @@ func TestRootConfig(t *testing.T) {
157149
require.Nil(t, err)
158150

159151
rootCmd := testRootCmd()
160-
cmd := cli.PrepareBaseCmd(rootCmd, "CMT", defaultRoot)
152+
cmd := cli.PrepareBaseCmd(rootCmd, "CMT", root)
161153

162154
// run with the args and env
163155
tc.args = append([]string{rootCmd.Use}, tc.args...)

0 commit comments

Comments
 (0)
Please sign in to comment.