github.com/hungdoo/bot@v0.0.0-20240325145135-dd1f386f7b81/src/__test__/factory_test.go (about)

     1  package test
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     6  	"testing"
     7  	"time"
     8  
     9  	command "github.com/hungdoo/bot/src/packages/command/common"
    10  	"github.com/hungdoo/bot/src/packages/command/contract"
    11  	"github.com/hungdoo/bot/src/services/telecommands"
    12  )
    13  
    14  func TestFactoryAddJob(t *testing.T) {
    15  	f := telecommands.NewCommandFactory()
    16  	ret := f.Add(command.Balance, []string{"Balance", "url", "wallet1", "wallet2"})
    17  	t.Log(ret)
    18  	ret = f.Add(command.ContractCall, []string{"ContractCall", "url", "address", "funcSelect", "params", "0", "1", "18"})
    19  	t.Log(ret)
    20  	ret = f.Add(command.Tomb, []string{"Tomb", "rpc", "contract", "false", "0", "key"})
    21  	t.Log(ret)
    22  	// jobs, err := f.GetJobs()
    23  	// if err != nil {
    24  	// 	fmt.Print(err)
    25  	// }
    26  	// t.Log(jobs)
    27  }
    28  func TestFactoryGetJobs(t *testing.T) {
    29  	f := telecommands.NewCommandFactory()
    30  	jobs, err := f.GetJobs()
    31  	if err != nil {
    32  		fmt.Print(err)
    33  	}
    34  
    35  	res, err := json.MarshalIndent(jobs, "", "")
    36  	if err != nil {
    37  		fmt.Print(err)
    38  	}
    39  	fmt.Print(string(res))
    40  }
    41  func TestCommandMap(t *testing.T) {
    42  	m := telecommands.CommandMap{
    43  		"a": &contract.ContractCommand{
    44  			Command: command.Command{
    45  				Name:     "name_111",
    46  				Enabled:  true,
    47  				IdleTime: time.Second * 60,
    48  			},
    49  		},
    50  		"b": &contract.ContractCommand{
    51  			Command: command.Command{
    52  				Name:     "name_222",
    53  				Enabled:  false,
    54  				IdleTime: time.Second * 60,
    55  			},
    56  		},
    57  	}
    58  
    59  	testSearchs := []string{"11", "22", "name"}
    60  	for _, s := range testSearchs {
    61  		res, err := json.MarshalIndent(m.Search(s), "", "")
    62  		if err != nil {
    63  			fmt.Print(err)
    64  		}
    65  		fmt.Printf("Test [%v]", s)
    66  		fmt.Print(string(res))
    67  	}
    68  }