Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 55ae718

Browse files
committed
fix: Set HOME for motd test as well
1 parent ace966c commit 55ae718

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@
128128
"tfplan",
129129
"tfstate",
130130
"tios",
131+
"tmpdir",
131132
"tparallel",
132133
"trialer",
133134
"trimprefix",

agent/agent_test.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,8 @@ func TestAgent(t *testing.T) {
194194
}
195195
})
196196

197+
//nolint:paralleltest // This test sets an environment variable.
197198
t.Run("Session TTY MOTD", func(t *testing.T) {
198-
t.Parallel()
199-
200199
if runtime.GOOS == "windows" {
201200
// This might be our implementation, or ConPTY itself.
202201
// It's difficult to find extensive tests for it, so
@@ -206,10 +205,14 @@ func TestAgent(t *testing.T) {
206205

207206
wantMOTD := "Welcome to your Coder workspace!"
208207

209-
name := filepath.Join(t.TempDir(), "motd")
208+
tmpdir := t.TempDir()
209+
name := filepath.Join(tmpdir, "motd")
210210
err := os.WriteFile(name, []byte(wantMOTD), 0o600)
211211
require.NoError(t, err, "write motd file")
212212

213+
// Set HOME so we can ensure no ~/.hushlogin is present.
214+
t.Setenv("HOME", tmpdir)
215+
213216
session := setupSSHSession(t, codersdk.WorkspaceAgentMetadata{
214217
MOTDFile: name,
215218
})
@@ -246,11 +249,14 @@ func TestAgent(t *testing.T) {
246249
name := filepath.Join(tmpdir, "motd")
247250
err := os.WriteFile(name, []byte(wantNotMOTD), 0o600)
248251
require.NoError(t, err, "write motd file")
252+
253+
// Create hushlogin to silence motd.
249254
f, err := os.Create(filepath.Join(tmpdir, ".hushlogin"))
250255
require.NoError(t, err, "create .hushlogin file")
251256
err = f.Close()
252257
require.NoError(t, err, "close .hushlogin file")
253258

259+
// Set HOME so we can ensure ~/.hushlogin is present.
254260
t.Setenv("HOME", tmpdir)
255261

256262
session := setupSSHSession(t, codersdk.WorkspaceAgentMetadata{

0 commit comments

Comments
 (0)