github.com/ChainSafe/chainbridge-core@v1.4.2/chains/evm/cli/logger/logger_test.go (about) 1 package logger_test 2 3 import ( 4 "os" 5 "regexp" 6 "strings" 7 "testing" 8 9 "github.com/ChainSafe/chainbridge-core/chains/evm/cli" 10 "github.com/ChainSafe/chainbridge-core/chains/evm/cli/logger" 11 "github.com/spf13/cobra" 12 "github.com/stretchr/testify/suite" 13 ) 14 15 type LoggerTestSuite struct { 16 suite.Suite 17 EvmRootCLI *cobra.Command 18 } 19 20 func TestLoggerWriteToFile(t *testing.T) { 21 suite.Run(t, new(LoggerTestSuite)) 22 } 23 24 func (s *LoggerTestSuite) SetupSuite() { 25 } 26 func (s *LoggerTestSuite) TearDownSuite() {} 27 28 func (s *LoggerTestSuite) TearDownTest() {} 29 30 func (s *LoggerTestSuite) TestWriteCliDataToFile() { 31 expectedLog := "Called evm-cli with args: --gas-limit=\"7000000\" --gas-price=\"25000000000\" --help=\"false\" --json-wallet=\"test-wallet\" --json-wallet-password=\"test-wallet-password\" --network=\"0\" --prepare=\"false\" --private-key=\"test-private-key\" --url=\"test-url\" =>\n" 32 33 rootCmdArgs := []string{ 34 "--url", "test-url", 35 "--gas-limit", "7000000", 36 "--gas-price", "25000000000", 37 "--network", "0x0", 38 "--private-key", "test-private-key", 39 "--json-wallet", "test-wallet", 40 "--json-wallet-password", "test-wallet-password", 41 } 42 43 cli.EvmRootCLI.SetArgs(rootCmdArgs) 44 _ = cli.EvmRootCLI.Execute() 45 46 data, _ := os.ReadFile(logger.CliLogsFilename) 47 logParts := strings.SplitN(string(data), " ", 2) 48 s.Equal(expectedLog, logParts[1]) 49 s.True(regexp.Match("[0-9]{2}-[0-9]{2}|[0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{3}", []byte(logParts[0]))) 50 51 err := os.Remove(logger.CliLogsFilename) 52 s.Nil(err) 53 }