github.com/mysteriumnetwork/node@v0.0.0-20240516044423-365054f76801/cmd/commands/reset/command_test.go (about) 1 /* 2 * Copyright (C) 2020 The "MysteriumNetwork/node" Authors. 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 package reset 19 20 import ( 21 "bytes" 22 "os" 23 "testing" 24 25 "github.com/mysteriumnetwork/node/config" 26 "github.com/mysteriumnetwork/node/config/remote" 27 "github.com/mysteriumnetwork/node/core/auth" 28 "github.com/stretchr/testify/assert" 29 ) 30 31 func TestActionRun(t *testing.T) { 32 tempDir, err := os.MkdirTemp("", "") 33 assert.NoError(t, err) 34 defer os.RemoveAll(tempDir) 35 36 cmdOutput := bytes.NewBufferString("") 37 38 mockusr := "musr" 39 mockpass := "mpsw" 40 41 cfg, err := remote.NewConfig(&cfgFether{ 42 map[string]interface{}{ 43 config.FlagDataDir.Name: tempDir, 44 config.FlagTequilapiUsername.Name: mockusr, 45 config.FlagTequilapiPassword.Name: mockpass, 46 }, 47 }) 48 assert.NoError(t, err) 49 50 // when 51 cmd := resetAction{ 52 writer: cmdOutput, 53 cfg: cfg, 54 } 55 56 t.Run("test reseting tequila credentials", func(t *testing.T) { 57 cmd.resetTequilapi() 58 59 // then 60 assert.NoError(t, err) 61 assert.Contains(t, cmdOutput.String(), `user password changed successfully`) 62 63 config.FlagTequilapiUsername.Value = mockusr 64 err = auth. 65 NewCredentialsManager(tempDir). 66 Validate(mockusr, mockpass) 67 assert.NoError(t, err) 68 }) 69 } 70 71 type cfgFether struct { 72 cfg map[string]interface{} 73 } 74 75 func (c *cfgFether) FetchConfig() (map[string]interface{}, error) { 76 cfg := config.NewConfig() 77 for k, v := range c.cfg { 78 cfg.SetDefault(k, v) 79 } 80 81 return cfg.GetConfig(), nil 82 }