func TestOthers(t *testing.T) { t.Logf("UUID: %s", ks.Uuid()) if buf, err := ks.RandomBytes(16); err == nil { t.Logf("Random bytes %v", buf) bs := ks.ToBase64(buf) t.Logf("Base encode %s", bs) if buf1, err := ks.FromBase64(bs); err == nil && ks.Equal(buf, buf1) { t.Logf("Base64 Decode: %s", buf1) } else { t.Errorf("Decode base64 error! %v", err) } } else { t.Errorf("Random bytes error! %v", err) } if err := ks.Shell("/usr/bin/uname", "-a"); err != nil { t.Errorf("Run script error! %v", err) } }
func init() { cmd.Register(cli.Command{ Name: "database", Aliases: []string{"db"}, Usage: "database operations", Flags: []cli.Flag{cmd.FLAG_ENV}, Subcommands: []cli.Command{ { Name: "console", Aliases: []string{"c"}, Usage: "database console", Flags: []cli.Flag{cmd.FLAG_ENV}, Action: cli_cfg(func(cfg *Configuration) error { c, a := cfg.Connect() return utils.Shell(c, a...) }), }, { Name: "create", Aliases: []string{"n"}, Usage: "create database", Flags: []cli.Flag{cmd.FLAG_ENV}, Action: cli_cfg(func(cfg *Configuration) error { c, a := cfg.Create() return utils.Shell(c, a...) }), }, { Name: "drop", Aliases: []string{"d"}, Usage: "drop database", Flags: []cli.Flag{cmd.FLAG_ENV}, Action: cli_cfg(func(cfg *Configuration) error { c, a := cfg.Drop() return utils.Shell(c, a...) }), }, { Name: "seed", Aliases: []string{"s"}, Usage: "load the seed data into database", Flags: []cli.Flag{cmd.FLAG_ENV}, Action: cli_db(func(db *Db) error { //todo return nil }), }, { Name: "migrate", Aliases: []string{"m"}, Usage: "migrate the database", Flags: []cli.Flag{cmd.FLAG_ENV}, Action: cli_db(func(db *Db) error { return db.Migrate() }), }, { Name: "rollback", Aliases: []string{"r"}, Usage: "rollback the database", Flags: []cli.Flag{cmd.FLAG_ENV}, Action: cli_db(func(db *Db) error { return db.Rollback() }), }, { Name: "backup", Aliases: []string{"b"}, Usage: "backup the database", Flags: []cli.Flag{cmd.FLAG_ENV}, Action: cli_cfg(func(cfg *Configuration) error { c, a := cfg.Backup() return utils.Shell(c, a...) }), }, }, }) }