diff options
| author | Shulhan <ms@kilabit.info> | 2023-07-24 13:01:36 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2023-10-06 10:03:04 +0700 |
| commit | 8a1a81a6428ae970569d9c2a506acf90deb2e0c4 (patch) | |
| tree | d3e82e19718962181b51572a0395ed6b1cef2222 /config_test.go | |
| parent | 479e33040d93e582aa10f19c299b2633f2270d24 (diff) | |
| download | gotp-8a1a81a6428ae970569d9c2a506acf90deb2e0c4.tar.xz | |
all: unfold private key path before reading
By unfolding, user can set the path to private key using "~" that points
to their home.
This make the key can works across home directory, in case user have
multiple homes (Linux and macOS have different home path and maybe
user name, but both can use "~" as substitution for $HOME)
Diffstat (limited to 'config_test.go')
| -rw-r--r-- | config_test.go | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/config_test.go b/config_test.go index b877236..477b438 100644 --- a/config_test.go +++ b/config_test.go @@ -4,6 +4,8 @@ package gotp import ( + "os" + "path/filepath" "testing" "github.com/shuLhan/share/lib/test" @@ -57,3 +59,41 @@ func TestNewConfig(t *testing.T) { test.Assert(t, `Issuer`, c.expConfig, gotConfig) } } + +func TestMarshaler(t *testing.T) { + var ( + cfg = config{} + + tdata *test.Data + userHomeDir string + err error + ) + + tdata, err = test.LoadData(`testdata/config_marshaler_test.txt`) + if err != nil { + t.Fatal(err) + } + + err = cfg.UnmarshalText(tdata.Input[`input.ini`]) + if err != nil { + t.Fatal(err) + } + + userHomeDir, err = os.UserHomeDir() + if err != nil { + t.Fatal(err) + } + + var expPrivateKey = filepath.Join(userHomeDir, `myprivatekey.pem`) + + test.Assert(t, `UnmarshalText: PrivateKey`, expPrivateKey, cfg.PrivateKey) + + var gotText []byte + + gotText, err = cfg.MarshalText() + if err != nil { + t.Fatal(err) + } + + test.Assert(t, `MarshalText`, string(tdata.Output[`output.ini`]), string(gotText)) +} |
