From 30ada1a1fc2aefdf41dd44fef604225532f719e3 Mon Sep 17 00:00:00 2001 From: Adrien Waksberg Date: Thu, 8 Aug 2019 18:27:31 +0200 Subject: [PATCH] feat: add test for config --- gpm/config_test.go | 72 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 gpm/config_test.go diff --git a/gpm/config_test.go b/gpm/config_test.go new file mode 100644 index 0000000..9b9d409 --- /dev/null +++ b/gpm/config_test.go @@ -0,0 +1,72 @@ +package gpm + +import ( + "io/ioutil" + "os" + "testing" +) + +func TestInit(t *testing.T) { + var config Config + + err := config.Init() + if err != nil { + t.Error("the config init mustn't return an error") + } + + if config.WalletDefault != "default" { + t.Errorf("the WalletDefaut must be 'default': %s", config.WalletDefault) + } + + if config.PasswordLength != 16 { + t.Errorf("the PasswordLength must be 16: %d", config.PasswordLength) + } + + if config.PasswordLetter != true { + t.Error("the PasswordLetter must be true") + } + + if config.PasswordDigit != true { + t.Error("the PasswordDigit must be true") + } + + if config.PasswordSpecial != false { + t.Error("the PasswordSpecial must be false") + } +} + +func TestSave(t *testing.T) { + var config Config + + tmpFile, _ := ioutil.TempFile(os.TempDir(), "gpm_test-") + defer os.Remove(tmpFile.Name()) + + config.Init() + err := config.Save(tmpFile.Name()) + if err != nil { + t.Errorf("save config mustn't return an error: %s", err) + } +} + +func TestLoadWithFile(t *testing.T) { + var config Config + + tmpFile, _ := ioutil.TempFile(os.TempDir(), "gpm_test-") + defer os.Remove(tmpFile.Name()) + + config.Init() + config.Save(tmpFile.Name()) + err := config.Load(tmpFile.Name()) + if err != nil { + t.Errorf("load config with file mustn't return an error: %s", err) + } +} + +func TestLoadWithoutFile(t *testing.T) { + var config Config + + err := config.Load("") + if err != nil { + t.Errorf("load config without file mustn't return an error: %s", err) + } +}