2018-12-04 05:57:11 +00:00
|
|
|
// Statping
|
2018-08-16 06:22:20 +00:00
|
|
|
// Copyright (C) 2018. Hunter Long and the project contributors
|
|
|
|
// Written by Hunter Long <info@socialeck.com> and the project contributors
|
|
|
|
//
|
2018-12-04 04:17:29 +00:00
|
|
|
// https://github.com/hunterlong/statping
|
2018-08-16 06:22:20 +00:00
|
|
|
//
|
|
|
|
// The licenses for most software and other practical works are designed
|
|
|
|
// to take away your freedom to share and change the works. By contrast,
|
|
|
|
// the GNU General Public License is intended to guarantee your freedom to
|
|
|
|
// share and change all versions of a program--to make sure it remains free
|
|
|
|
// software for all its users.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2018-08-11 16:24:32 +00:00
|
|
|
package source
|
|
|
|
|
|
|
|
import (
|
2018-12-04 04:17:29 +00:00
|
|
|
"github.com/hunterlong/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
|
|
|
}
|