Skip to content

Commit f6990ca

Browse files
KevRiveraybabtme
authored andcommitted
rewrite using t.TempDir
1 parent cc28ad4 commit f6990ca

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

cmd/humanlog/main_test.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,31 @@
11
package main
22

33
import (
4+
"encoding/json"
45
"os"
5-
"strings"
66
"testing"
7+
8+
"github.com/humanlogio/humanlog/internal/pkg/config"
9+
"github.com/stretchr/testify/require"
710
)
811

912
func TestApplyConfigFromConfigFile_when_one_of_skip_or_keep_is_given(t *testing.T) {
1013

11-
wd, _ := os.Getwd()
12-
dirs := strings.Split(wd, "/")
13-
root := strings.Join(dirs[:len(dirs)-2], "/")
14-
configFilePath := root + "/test/cases/00065-apply-config/config.json"
15-
t.Logf("config file path: %v", configFilePath)
14+
cfg := config.Config{
15+
Skip: ptr([]string{"foo", "bar"}),
16+
}
17+
18+
dir := t.TempDir()
19+
f, err := os.CreateTemp(dir, "00065-apply-config.json")
20+
require.NoError(t, err)
21+
22+
err = json.NewEncoder(f).Encode(cfg)
23+
require.NoError(t, err)
24+
25+
err = f.Close()
26+
require.NoError(t, err)
1627

17-
args := []string{"program-path"}
18-
args = append(args, "--config", configFilePath)
28+
args := []string{"program-path", "--config", f.Name()}
1929

2030
app := newApp()
2131
if err := app.Run(args); err != nil {

0 commit comments

Comments
 (0)