示例#1
0
文件: main.go 项目: soygul/titan
func startExtTest(addr string) {
	log.Printf("-ext flag is provided, starting external client test case.")
	titan.InitConf("test")

	now := time.Now().Unix()
	t := jwt.New(jwt.SigningMethodHS256)
	t.Claims["userid"] = "1"
	t.Claims["created"] = now
	ts, err := t.SignedString([]byte(titan.Conf.App.JWTPass()))
	if err != nil {
		log.Fatalf("failed to sign JWT token: %v", err)
	}
	log.Printf("Sample valid user JWT token for testing: %v", ts)

	startServer(addr)
}
示例#2
0
// NewServerHelper creates a new server helper object.
// Titan server instance is initialized and ready to accept connection after this function return.
func NewServerHelper(t *testing.T) *ServerHelper {
	if testing.Short() {
		t.Skip("Skipping integration test in short testing mode")
	}

	if (titan.Conf == titan.Config{}) {
		titan.InitConf("test")
	}

	url := "127.0.0.1:" + titan.Conf.App.Port
	s, err := titan.NewServer(url)
	if err != nil {
		t.Fatal("Failed to create server:", err)
	}

	var db data.DB
	if *awsFlag {
		db = aws.NewDynamoDB("", "")
		if err := db.Seed(true, titan.Conf.App.JWTPass()); err != nil {
			t.Fatal("Failed to set seed DynamoDB:", err)
		}
	} else {
		db = inmem.NewDB()
	}
	if err := s.SetDB(db); err != nil {
		t.Fatal("Failed to set server database instance:", err)
	}

	h := ServerHelper{
		db:           db,
		server:       s,
		testing:      t,
		serverClosed: make(chan bool),
	}

	return &h
}