2018-08-11 16:24:32 +00:00
|
|
|
package source
|
|
|
|
|
|
|
|
import (
|
2020-03-09 18:17:55 +00:00
|
|
|
"github.com/statping/statping/utils"
|
2018-08-11 16:24:32 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
2020-02-19 04:07:22 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2018-08-11 16:24:32 +00:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
dir string
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
dir = utils.Directory
|
|
|
|
utils.InitLogs()
|
|
|
|
Assets()
|
2019-12-30 03:34:49 +00:00
|
|
|
utils.DeleteDirectory(dir + "/assets")
|
2018-08-11 16:24:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCore_UsingAssets(t *testing.T) {
|
2018-08-16 20:55:30 +00:00
|
|
|
assert.False(t, UsingAssets(dir))
|
2018-08-11 16:24:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCreateAssets(t *testing.T) {
|
|
|
|
assert.Nil(t, CreateAllAssets(dir))
|
2018-08-16 20:55:30 +00:00
|
|
|
assert.True(t, UsingAssets(dir))
|
2020-03-02 07:53:46 +00:00
|
|
|
assert.Nil(t, CompileSASS(DefaultScss...))
|
|
|
|
assert.FileExists(t, dir+"/assets/css/main.css")
|
|
|
|
assert.FileExists(t, dir+"/assets/css/style.css")
|
|
|
|
assert.FileExists(t, dir+"/assets/css/vendor.css")
|
2019-01-17 04:59:07 +00:00
|
|
|
assert.FileExists(t, dir+"/assets/scss/base.scss")
|
2020-03-02 07:53:46 +00:00
|
|
|
assert.FileExists(t, dir+"/assets/scss/mobile.scss")
|
|
|
|
assert.FileExists(t, dir+"/assets/scss/variables.scss")
|
2020-02-19 04:07:22 +00:00
|
|
|
}
|
2018-08-11 16:24:32 +00:00
|
|
|
|
2020-03-02 07:53:46 +00:00
|
|
|
//func TestCopyAllToPublic(t *testing.T) {
|
|
|
|
// err := CopyAllToPublic(TmplBox)
|
|
|
|
// require.Nil(t, err)
|
|
|
|
//}
|
|
|
|
|
2018-08-11 16:24:32 +00:00
|
|
|
func TestCompileSASS(t *testing.T) {
|
2020-03-02 07:53:46 +00:00
|
|
|
err := CompileSASS(DefaultScss...)
|
2020-02-19 04:07:22 +00:00
|
|
|
require.Nil(t, err)
|
2018-08-16 20:55:30 +00:00
|
|
|
assert.True(t, UsingAssets(dir))
|
2018-08-11 16:24:32 +00:00
|
|
|
}
|
|
|
|
|
2020-03-02 07:53:46 +00:00
|
|
|
func TestSaveAndCompileAsset(t *testing.T) {
|
|
|
|
scssData := "$bodycolor: #333; BODY { color: $bodycolor; }"
|
|
|
|
|
|
|
|
err := SaveAsset([]byte(scssData), "scss/theme.scss")
|
|
|
|
require.Nil(t, err)
|
2018-08-16 02:22:10 +00:00
|
|
|
assert.FileExists(t, dir+"/assets/scss/theme.scss")
|
2020-03-02 07:53:46 +00:00
|
|
|
|
|
|
|
asset := OpenAsset("scss/theme.scss")
|
|
|
|
assert.NotEmpty(t, asset)
|
|
|
|
assert.Equal(t, scssData, asset)
|
|
|
|
|
|
|
|
err = CompileSASS("scss/theme.scss")
|
|
|
|
require.Nil(t, err)
|
|
|
|
assert.FileExists(t, dir+"/assets/css/theme.css")
|
|
|
|
|
|
|
|
themeCSS, err := utils.OpenFile(dir + "/assets/css/theme.css")
|
|
|
|
require.Nil(t, err)
|
|
|
|
|
2020-03-03 06:42:37 +00:00
|
|
|
assert.Contains(t, themeCSS, `color: #333;`)
|
2018-08-16 02:22:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestOpenAsset(t *testing.T) {
|
2020-02-19 04:07:22 +00:00
|
|
|
asset := OpenAsset("scss/theme.scss")
|
2018-08-16 02:22:10 +00:00
|
|
|
assert.NotEmpty(t, asset)
|
|
|
|
}
|
|
|
|
|
2018-08-11 16:24:32 +00:00
|
|
|
func TestDeleteAssets(t *testing.T) {
|
2020-02-19 04:07:22 +00:00
|
|
|
assert.True(t, UsingAssets(dir))
|
2020-03-03 06:42:37 +00:00
|
|
|
assert.Nil(t, DeleteAllAssets(dir))
|
2018-08-16 20:55:30 +00:00
|
|
|
assert.False(t, UsingAssets(dir))
|
2018-08-16 02:22:10 +00:00
|
|
|
}
|
2018-10-06 06:38:33 +00:00
|
|
|
|
|
|
|
func ExampleSaveAsset() {
|
|
|
|
data := []byte("alert('helloooo')")
|
2020-02-19 04:07:22 +00:00
|
|
|
SaveAsset(data, "js/test.js")
|
2018-10-06 06:38:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func ExampleOpenAsset() {
|
2020-02-19 04:07:22 +00:00
|
|
|
OpenAsset("js/main.js")
|
2018-10-06 06:38:33 +00:00
|
|
|
}
|