Skip to content

Commit

Permalink
add unit
Browse files Browse the repository at this point in the history
  • Loading branch information
kripsy committed Nov 9, 2023
1 parent 4e590b3 commit 1f92210
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions internal/client/config/config_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package config
import (
"os"
"path/filepath"
"reflect"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -71,3 +72,40 @@ storage_path: ["./data"]
//nolint:gosec
require.NoError(t, os.WriteFile(configPath, invalidYAMLContent, 0644))
}

func TestSetConfig(t *testing.T) {
tests := []struct {
name string
fileCfg Config
flagCfg Flags
wantCfg Config
}{
{
name: "all defaults",
fileCfg: Config{},
flagCfg: Flags{},
wantCfg: Config{StoragePath: defaultStoragePath, UploadPath: defaultUploadPath, ServerAddress: defaultServerAddress},
},
{
name: "all flags provided",
fileCfg: Config{},
flagCfg: Flags{StoragePath: "/custom/storage", UploadPath: "/custom/upload", ServerAddress: "192.168.1.1:6000"},
wantCfg: Config{StoragePath: "/custom/storage", UploadPath: "/custom/upload", ServerAddress: "192.168.1.1:6000"},
},
{
name: "some flags provided",
fileCfg: Config{},
flagCfg: Flags{StoragePath: "/custom/storage"},
wantCfg: Config{StoragePath: "/custom/storage", UploadPath: defaultUploadPath, ServerAddress: defaultServerAddress},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotCfg := setConfig(tt.fileCfg, tt.flagCfg)
if !reflect.DeepEqual(gotCfg, tt.wantCfg) {
t.Errorf("%s: setConfig() got = %v, want %v", tt.name, gotCfg, tt.wantCfg)
}
})
}
}

0 comments on commit 1f92210

Please sign in to comment.