Skip to content

Commit 61ad148

Browse files
committed
Add unit test: can not open(or create) gup.conf
1 parent c98df75 commit 61ad148

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

cmd/export_test.go

+30
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"testing"
1212

1313
"github.com/google/go-cmp/cmp"
14+
"github.com/nao1215/gup/internal/config"
1415
"github.com/nao1215/gup/internal/file"
1516
"github.com/nao1215/gup/internal/goutil"
1617
"github.com/nao1215/gup/internal/print"
@@ -278,3 +279,32 @@ func Test_export_parse_error(t *testing.T) {
278279
}
279280
})
280281
}
282+
283+
func Test_writeConfigFile(t *testing.T) {
284+
type args struct {
285+
pkgs []goutil.Package
286+
}
287+
tests := []struct {
288+
name string
289+
args args
290+
wantErr bool
291+
}{
292+
{
293+
name: "failed to open config file",
294+
args: args{
295+
pkgs: []goutil.Package{},
296+
},
297+
wantErr: true,
298+
},
299+
}
300+
for _, tt := range tests {
301+
t.Run(tt.name, func(t *testing.T) {
302+
config.ConfigFileName = ""
303+
defer func() { config.ConfigFileName = "gup.conf" }()
304+
305+
if err := writeConfigFile(tt.args.pkgs); (err != nil) != tt.wantErr {
306+
t.Errorf("writeConfigFile() error = %v, wantErr %v", err, tt.wantErr)
307+
}
308+
})
309+
}
310+
}

internal/config/config.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ import (
1313
"github.com/nao1215/gup/internal/goutil"
1414
)
1515

16+
// ConfigFileName is gup command configuration file
17+
var ConfigFileName = "gup.conf"
18+
1619
// FilePath return configuration-file path.
1720
func FilePath() string {
18-
return filepath.Join(DirPath(), "gup.conf")
21+
return filepath.Join(DirPath(), ConfigFileName)
1922
}
2023

2124
// DirPath return directory path that store configuration-file.

0 commit comments

Comments
 (0)