Skip to content

Commit 65118cb

Browse files
committed
chore: update environment variable handling in tests and build command
1 parent 21f0aed commit 65118cb

2 files changed

Lines changed: 14 additions & 18 deletions

File tree

config/application_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ func (s *ApplicationTestSuite) SetupTest() {
5555
}
5656

5757
func (s *ApplicationTestSuite) TestOsVariables() {
58-
s.Nil(os.Setenv("APP_KEY", "12345678901234567890123456789013"))
59-
s.Nil(os.Setenv("OS_APP_NAME", "goravel"))
60-
s.Nil(os.Setenv("OS_APP_PORT", "3306"))
61-
s.Nil(os.Setenv("OS_APP_DEBUG", "true"))
62-
s.Nil(os.Setenv("OS_TIMEOUT", "5s"))
58+
s.T().Setenv("APP_KEY", "12345678901234567890123456789013")
59+
s.T().Setenv("OS_APP_NAME", "goravel")
60+
s.T().Setenv("OS_APP_PORT", "3306")
61+
s.T().Setenv("OS_APP_DEBUG", "true")
62+
s.T().Setenv("OS_TIMEOUT", "5s")
6363

6464
s.Equal("12345678901234567890123456789013", s.config.GetString("APP_KEY"))
6565
s.Equal("12345678901234567890123456789013", s.customConfig.GetString("APP_KEY"))
@@ -179,10 +179,10 @@ func (s *ApplicationTestSuite) TestGetDuration() {
179179
}
180180

181181
func TestOsVariables(t *testing.T) {
182-
assert.Nil(t, os.Setenv("APP_KEY", "12345678901234567890123456789013"))
183-
assert.Nil(t, os.Setenv("APP_NAME", "goravel"))
184-
assert.Nil(t, os.Setenv("APP_PORT", "3306"))
185-
assert.Nil(t, os.Setenv("APP_DEBUG", "true"))
182+
t.Setenv("APP_KEY", "12345678901234567890123456789013")
183+
t.Setenv("APP_NAME", "goravel")
184+
t.Setenv("APP_PORT", "3306")
185+
t.Setenv("APP_DEBUG", "true")
186186

187187
config := NewApplication(support.EnvFilePath)
188188

console/console/build_command.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package console
22

33
import (
44
"fmt"
5-
"os"
65
"os/exec"
76
"slices"
87

@@ -104,25 +103,22 @@ func (r *BuildCommand) Handle(ctx console.Context) error {
104103
}
105104

106105
func (r *BuildCommand) build(system string, command []string) error {
107-
_ = os.Setenv("CGO_ENABLED", "0")
108-
_ = os.Setenv("GOOS", system)
109-
_ = os.Setenv("GOARCH", "amd64")
110-
111106
cmd := exec.Command(command[0], command[1:]...)
107+
cmd.Env = append(cmd.Environ(), "CGO_ENABLED=0", "GOARCH=amd64", "GOOS="+system)
112108
_, err := cmd.Output()
113109
return err
114110
}
115111

116112
func generateCommand(name string, static bool) []string {
117-
command := []string{"go", "build"}
113+
commands := []string{"go", "build"}
118114

119115
if static {
120-
command = append(command, "-ldflags", "-extldflags -static")
116+
commands = append(commands, "-ldflags", "-extldflags -static")
121117
}
122118

123119
if name != "" {
124-
command = append(command, "-o", name)
120+
commands = append(commands, "-o", name)
125121
}
126122

127-
return append(command, ".")
123+
return append(commands, ".")
128124
}

0 commit comments

Comments
 (0)