package model

import (
	"sparrow/pkg/mysql"
	"testing"

	"github.com/jinzhu/gorm"
)

func TestGetAppCount(t *testing.T) {

	key := "aab1f679672380cf8cc79816bac4256809d0820473bc958e4c4eac91fd97e27b"

	app := getApplication(t)
	a, err := app.GetAppInfo(uint(1), key)
	if err != nil {
		t.Fatal(err)
	}
	t.Log(a)
}

func getApplication(t *testing.T) *Application {
	db, err := getAppDB()
	if err != nil {
		t.Fatal(err)
	}
	app := new(Application).Init(db)
	return app
}

func getAppDB() (*gorm.DB, error) {
	db, err := mysql.GetClient("192.168.175.60", "3306", "SparrowCloud", "SparrowCloud", "123456")
	if err != nil {
		return nil, err
	}
	gormdb, err := gorm.Open("mysql", db)
	if err != nil {
		return nil, err
	}
	gormdb.SingularTable(true)
	gormdb.LogMode(true)
	return gormdb, nil
}
