mirror of https://github.com/statping/statping
required sass files to render in tests
parent
ae25e84128
commit
f089364884
6
Makefile
6
Makefile
|
@ -164,6 +164,10 @@ install: build
|
||||||
install-local: build
|
install-local: build
|
||||||
mv $(BINARY_NAME) /usr/local/bin/$(BINARY_NAME)
|
mv $(BINARY_NAME) /usr/local/bin/$(BINARY_NAME)
|
||||||
|
|
||||||
|
install-darwin:
|
||||||
|
go build -a -ldflags "-X main.VERSION=${VERSION}" -o statping --tags "netgo darwin" ./cmd
|
||||||
|
mv $(BINARY_NAME) /usr/local/bin/$(BINARY_NAME)
|
||||||
|
|
||||||
generate:
|
generate:
|
||||||
cd source && go generate
|
cd source && go generate
|
||||||
|
|
||||||
|
@ -399,5 +403,5 @@ check:
|
||||||
@echo "yarn: $(shell yarn --version) - $(shell which yarn)" && yarn --version >/dev/null 2>&1 || (echo "ERROR: yarn is required."; exit 1)
|
@echo "yarn: $(shell yarn --version) - $(shell which yarn)" && yarn --version >/dev/null 2>&1 || (echo "ERROR: yarn is required."; exit 1)
|
||||||
@echo "All required programs are installed!"
|
@echo "All required programs are installed!"
|
||||||
|
|
||||||
.PHONY: all check build certs multiarch go-build build-all buildx-base buildx-dev buildx-latest build-alpine test-all test test-api docker frontend up down print_details lite sentry-release snapcraft build-linux build-mac build-win build-all postman
|
.PHONY: all check build certs multiarch install-darwin go-build build-all buildx-base buildx-dev buildx-latest build-alpine test-all test test-api docker frontend up down print_details lite sentry-release snapcraft build-linux build-mac build-win build-all postman
|
||||||
.SILENT: travis_s3_creds
|
.SILENT: travis_s3_creds
|
||||||
|
|
|
@ -16,6 +16,7 @@ import (
|
||||||
"github.com/statping/statping/utils"
|
"github.com/statping/statping/utils"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
@ -67,8 +68,8 @@ After=network-online.target
|
||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=simple
|
||||||
Restart=always
|
Restart=always
|
||||||
Environment=STATPING_DIR=` + dir + `
|
Environment="STATPING_DIR=` + dir + `"
|
||||||
Environment=ALLOW_REPORTS=true
|
Environment="ALLOW_REPORTS=true"
|
||||||
ExecStart=` + binPath + ` --port=` + utils.ToString(port) + `
|
ExecStart=` + binPath + ` --port=` + utils.ToString(port) + `
|
||||||
WorkingDirectory=` + dir + `
|
WorkingDirectory=` + dir + `
|
||||||
|
|
||||||
|
@ -97,7 +98,7 @@ WantedBy=multi-user.target"
|
||||||
}
|
}
|
||||||
|
|
||||||
func exportCli(args []string) error {
|
func exportCli(args []string) error {
|
||||||
filename := fmt.Sprintf("%s/statping-%s.json", utils.Directory, time.Now().Format("01-02-2006-1504"))
|
filename := filepath.Join(utils.Directory, time.Now().Format("01-02-2006-1504")+".json")
|
||||||
if len(args) == 1 {
|
if len(args) == 1 {
|
||||||
filename = fmt.Sprintf("%s/%s", utils.Directory, args)
|
filename = fmt.Sprintf("%s/%s", utils.Directory, args)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,10 +2,12 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"github.com/statping/statping/source"
|
||||||
"github.com/statping/statping/utils"
|
"github.com/statping/statping/utils"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -18,16 +20,15 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStatpingDirectory(t *testing.T) {
|
func TestStatpingDirectory(t *testing.T) {
|
||||||
dir := utils.Directory
|
|
||||||
require.NotContains(t, dir, "/cmd")
|
|
||||||
require.NotEmpty(t, dir)
|
|
||||||
|
|
||||||
dir = utils.Params.GetString("STATPING_DIR")
|
dir = utils.Params.GetString("STATPING_DIR")
|
||||||
require.NotContains(t, dir, "/cmd")
|
require.NotContains(t, dir, "/cmd")
|
||||||
require.NotEmpty(t, dir)
|
require.NotEmpty(t, dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEnvCLI(t *testing.T) {
|
func TestEnvCLI(t *testing.T) {
|
||||||
|
os.Setenv("API_SECRET", "demoapisecret123")
|
||||||
|
os.Setenv("SASS", "/usr/local/bin/sass")
|
||||||
|
|
||||||
cmd := rootCmd
|
cmd := rootCmd
|
||||||
b := bytes.NewBufferString("")
|
b := bytes.NewBufferString("")
|
||||||
cmd.SetOut(b)
|
cmd.SetOut(b)
|
||||||
|
@ -39,6 +40,12 @@ func TestEnvCLI(t *testing.T) {
|
||||||
assert.Contains(t, string(out), VERSION)
|
assert.Contains(t, string(out), VERSION)
|
||||||
assert.Contains(t, utils.Directory, string(out))
|
assert.Contains(t, utils.Directory, string(out))
|
||||||
assert.Contains(t, "SAMPLE_DATA=true", string(out))
|
assert.Contains(t, "SAMPLE_DATA=true", string(out))
|
||||||
|
assert.Contains(t, "API_SECRET=demoapisecret123", string(out))
|
||||||
|
assert.Contains(t, "STATPING_DIR="+dir, string(out))
|
||||||
|
assert.Contains(t, "SASS=/usr/local/bin/sass", string(out))
|
||||||
|
|
||||||
|
os.Unsetenv("API_SECRET")
|
||||||
|
os.Unsetenv("SASS")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestVersionCLI(t *testing.T) {
|
func TestVersionCLI(t *testing.T) {
|
||||||
|
@ -58,16 +65,26 @@ func TestAssetsCLI(t *testing.T) {
|
||||||
b := bytes.NewBufferString("")
|
b := bytes.NewBufferString("")
|
||||||
cmd.SetOut(b)
|
cmd.SetOut(b)
|
||||||
cmd.SetArgs([]string{"assets"})
|
cmd.SetArgs([]string{"assets"})
|
||||||
cmd.Execute()
|
err := cmd.Execute()
|
||||||
|
require.Nil(t, err)
|
||||||
out, err := ioutil.ReadAll(b)
|
out, err := ioutil.ReadAll(b)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Contains(t, string(out), VERSION)
|
assert.Contains(t, string(out), VERSION)
|
||||||
assert.FileExists(t, utils.Directory+"/assets/css/main.css")
|
for _, f := range source.RequiredFiles {
|
||||||
assert.FileExists(t, utils.Directory+"/assets/css/style.css")
|
assert.FileExists(t, utils.Directory+"/assets/"+f)
|
||||||
assert.FileExists(t, utils.Directory+"/assets/css/vendor.css")
|
}
|
||||||
assert.FileExists(t, utils.Directory+"/assets/scss/base.scss")
|
}
|
||||||
assert.FileExists(t, utils.Directory+"/assets/scss/mobile.scss")
|
|
||||||
assert.FileExists(t, utils.Directory+"/assets/scss/variables.scss")
|
func TestUpdateCLI(t *testing.T) {
|
||||||
|
cmd := rootCmd
|
||||||
|
b := bytes.NewBufferString("")
|
||||||
|
cmd.SetOut(b)
|
||||||
|
cmd.SetArgs([]string{"update"})
|
||||||
|
err := cmd.Execute()
|
||||||
|
require.Nil(t, err)
|
||||||
|
out, err := ioutil.ReadAll(b)
|
||||||
|
require.Nil(t, err)
|
||||||
|
assert.Contains(t, string(out), VERSION)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHelpCLI(t *testing.T) {
|
func TestHelpCLI(t *testing.T) {
|
||||||
|
|
|
@ -12,16 +12,18 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var rootCmd = &cobra.Command{
|
var rootCmd = &cobra.Command{
|
||||||
Use: "statping",
|
Use: "statping",
|
||||||
Short: "A simple Application Status Monitor that is opensource and lightweight.",
|
Version: VERSION,
|
||||||
|
Short: "A simple Application Status Monitor that is opensource and lightweight.",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
start()
|
start()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
var updateCmd = &cobra.Command{
|
var updateCmd = &cobra.Command{
|
||||||
Use: "update",
|
Use: "update",
|
||||||
Short: "Update to the latest version",
|
Example: "statping update",
|
||||||
|
Short: "Update to the latest version",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
log.Infoln("Updating Statping to the latest version...")
|
log.Infoln("Updating Statping to the latest version...")
|
||||||
curl, err := exec.LookPath("curl")
|
curl, err := exec.LookPath("curl")
|
||||||
|
@ -59,8 +61,9 @@ var updateCmd = &cobra.Command{
|
||||||
}
|
}
|
||||||
|
|
||||||
var versionCmd = &cobra.Command{
|
var versionCmd = &cobra.Command{
|
||||||
Use: "version",
|
Use: "version",
|
||||||
Short: "Print the version number of Statping",
|
Example: "statping version",
|
||||||
|
Short: "Print the version number of Statping",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
if COMMIT != "" {
|
if COMMIT != "" {
|
||||||
fmt.Printf("%s (%s)\n", VERSION, COMMIT)
|
fmt.Printf("%s (%s)\n", VERSION, COMMIT)
|
||||||
|
@ -72,8 +75,9 @@ var versionCmd = &cobra.Command{
|
||||||
}
|
}
|
||||||
|
|
||||||
var systemctlCmd = &cobra.Command{
|
var systemctlCmd = &cobra.Command{
|
||||||
Use: "systemctl [install/uninstall]",
|
Use: "systemctl [install/uninstall]",
|
||||||
Short: "Install or Uninstall systemctl services",
|
Example: "statping systemctl install",
|
||||||
|
Short: "Install or Uninstall systemctl services",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
if args[1] == "install" {
|
if args[1] == "install" {
|
||||||
if len(args) < 3 {
|
if len(args) < 3 {
|
||||||
|
@ -99,8 +103,9 @@ var systemctlCmd = &cobra.Command{
|
||||||
}
|
}
|
||||||
|
|
||||||
var assetsCmd = &cobra.Command{
|
var assetsCmd = &cobra.Command{
|
||||||
Use: "assets",
|
Use: "assets",
|
||||||
Short: "Dump all assets used locally to be edited",
|
Example: "statping assets",
|
||||||
|
Short: "Dump all assets used locally to be edited",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
if err := assetsCli(); err != nil {
|
if err := assetsCli(); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -111,8 +116,9 @@ var assetsCmd = &cobra.Command{
|
||||||
}
|
}
|
||||||
|
|
||||||
var exportCmd = &cobra.Command{
|
var exportCmd = &cobra.Command{
|
||||||
Use: "export",
|
Use: "export",
|
||||||
Short: "Exports your Statping settings to a 'statping-export.json' file.",
|
Example: "statping export",
|
||||||
|
Short: "Exports your Statping settings to a 'statping-export.json' file.",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
if err := exportCli(args); err != nil {
|
if err := exportCli(args); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -123,8 +129,9 @@ var exportCmd = &cobra.Command{
|
||||||
}
|
}
|
||||||
|
|
||||||
var sassCmd = &cobra.Command{
|
var sassCmd = &cobra.Command{
|
||||||
Use: "sass",
|
Use: "sass",
|
||||||
Short: "Compile .scss files into the css directory",
|
Example: "statping sass",
|
||||||
|
Short: "Compile .scss files into the css directory",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
if err := sassCli(); err != nil {
|
if err := sassCli(); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -135,8 +142,9 @@ var sassCmd = &cobra.Command{
|
||||||
}
|
}
|
||||||
|
|
||||||
var envCmd = &cobra.Command{
|
var envCmd = &cobra.Command{
|
||||||
Use: "env",
|
Use: "env",
|
||||||
Short: "Return the configs that will be ran",
|
Example: "statping env",
|
||||||
|
Short: "Return the configs that will be ran",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
if err := envCli(); err != nil {
|
if err := envCli(); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -147,8 +155,9 @@ var envCmd = &cobra.Command{
|
||||||
}
|
}
|
||||||
|
|
||||||
var resetCmd = &cobra.Command{
|
var resetCmd = &cobra.Command{
|
||||||
Use: "reset",
|
Use: "reset",
|
||||||
Short: "Start a fresh copy of Statping",
|
Example: "statping reset",
|
||||||
|
Short: "Start a fresh copy of Statping",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
if err := resetCli(); err != nil {
|
if err := resetCli(); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -159,8 +168,9 @@ var resetCmd = &cobra.Command{
|
||||||
}
|
}
|
||||||
|
|
||||||
var onceCmd = &cobra.Command{
|
var onceCmd = &cobra.Command{
|
||||||
Use: "once",
|
Use: "once",
|
||||||
Short: "Check all services 1 time and then quit",
|
Example: "statping once",
|
||||||
|
Short: "Check all services 1 time and then quit",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
if err := onceCli(); err != nil {
|
if err := onceCli(); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -171,8 +181,9 @@ var onceCmd = &cobra.Command{
|
||||||
}
|
}
|
||||||
|
|
||||||
var importCmd = &cobra.Command{
|
var importCmd = &cobra.Command{
|
||||||
Use: "import [.json file]",
|
Use: "import [.json file]",
|
||||||
Short: "Imports settings from a previously saved JSON file.",
|
Example: "statping import backup.json",
|
||||||
|
Short: "Imports settings from a previously saved JSON file.",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
if err := importCli(args); err != nil {
|
if err := importCli(args); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
|
|
||||||
.form-control[readonly] {
|
.form-control[readonly] {
|
||||||
background-color: lighten($background-color, 12%) !important;
|
background-color: lighten($background-color, 12%) !important;
|
||||||
color: lighten($input-color, 40%) !important;
|
color: lighten($input-color, 30%) !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The slider itself */
|
/* The slider itself */
|
||||||
|
|
|
@ -20,8 +20,6 @@
|
||||||
|
|
||||||
<h6 class="mt-4 text-muted">Notifiers</h6>
|
<h6 class="mt-4 text-muted">Notifiers</h6>
|
||||||
|
|
||||||
{{notifiers}}
|
|
||||||
|
|
||||||
<div id="notifiers_tabs">
|
<div id="notifiers_tabs">
|
||||||
<a v-for="(notifier, index) in notifiers" v-bind:key="`${notifier.method}`" @click.prevent="changeTab" class="nav-link text-capitalize" v-bind:class="{active: liClass(`v-pills-${notifier.method.toLowerCase()}-tab`)}" v-bind:id="`v-pills-${notifier.method.toLowerCase()}-tab`" data-toggle="pill" v-bind:href="`#v-pills-${notifier.method.toLowerCase()}`" role="tab" v-bind:aria-controls="`v-pills-${notifier.method.toLowerCase()}`" aria-selected="false">
|
<a v-for="(notifier, index) in notifiers" v-bind:key="`${notifier.method}`" @click.prevent="changeTab" class="nav-link text-capitalize" v-bind:class="{active: liClass(`v-pills-${notifier.method.toLowerCase()}-tab`)}" v-bind:id="`v-pills-${notifier.method.toLowerCase()}-tab`" data-toggle="pill" v-bind:href="`#v-pills-${notifier.method.toLowerCase()}`" role="tab" v-bind:aria-controls="`v-pills-${notifier.method.toLowerCase()}`" aria-selected="false">
|
||||||
<font-awesome-icon :icon="iconName(notifier.icon)" class="mr-2"/> {{notifier.title}}
|
<font-awesome-icon :icon="iconName(notifier.icon)" class="mr-2"/> {{notifier.title}}
|
||||||
|
|
1
go.mod
1
go.mod
|
@ -12,6 +12,7 @@ require (
|
||||||
github.com/fsnotify/fsnotify v1.4.9 // indirect
|
github.com/fsnotify/fsnotify v1.4.9 // indirect
|
||||||
github.com/getsentry/sentry-go v0.5.1
|
github.com/getsentry/sentry-go v0.5.1
|
||||||
github.com/go-mail/mail v2.3.1+incompatible
|
github.com/go-mail/mail v2.3.1+incompatible
|
||||||
|
github.com/golang/protobuf v1.4.0
|
||||||
github.com/gorilla/mux v1.7.4
|
github.com/gorilla/mux v1.7.4
|
||||||
github.com/hako/durafmt v0.0.0-20200605151348-3a43fc422dd9
|
github.com/hako/durafmt v0.0.0-20200605151348-3a43fc422dd9
|
||||||
github.com/jinzhu/gorm v1.9.12
|
github.com/jinzhu/gorm v1.9.12
|
||||||
|
|
|
@ -67,9 +67,9 @@ type testNotificationReq struct {
|
||||||
|
|
||||||
func testNotificationHandler(w http.ResponseWriter, r *http.Request) {
|
func testNotificationHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
n, err := notifications.Find(vars["notifier"])
|
n := services.FindNotifier(vars["notifier"])
|
||||||
if err != nil {
|
if n == nil {
|
||||||
sendErrorJson(err, w, r)
|
sendErrorJson(errors.New("unknown notifier"), w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,6 +82,7 @@ func testNotificationHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
notif := services.ReturnNotifier(n.Method)
|
notif := services.ReturnNotifier(n.Method)
|
||||||
|
|
||||||
var out string
|
var out string
|
||||||
|
var err error
|
||||||
if req.Method == "success" {
|
if req.Method == "success" {
|
||||||
out, err = notif.OnSuccess(services.Example(true))
|
out, err = notif.OnSuccess(services.Example(true))
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -14,8 +14,27 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
log = utils.Log.WithField("type", "source")
|
log = utils.Log.WithField("type", "source")
|
||||||
TmplBox *rice.Box // HTML and other small files from the 'source/tmpl' directory, this will be loaded into '/assets'
|
TmplBox *rice.Box // HTML and other small files from the 'source/tmpl' directory, this will be loaded into '/assets'
|
||||||
|
RequiredFiles = []string{
|
||||||
|
"css/style.css",
|
||||||
|
"css/style.css.gz",
|
||||||
|
"css/main.css",
|
||||||
|
"scss/main.scss",
|
||||||
|
"scss/base.scss",
|
||||||
|
"scss/forms.scss",
|
||||||
|
"scss/layout.scss",
|
||||||
|
"scss/mixin.scss",
|
||||||
|
"scss/mobile.scss",
|
||||||
|
"scss/variables.scss",
|
||||||
|
"js/bundle.js",
|
||||||
|
"js/main.chunk.js",
|
||||||
|
"js/polyfill.chunk.js",
|
||||||
|
"js/style.chunk.js",
|
||||||
|
"banner.png",
|
||||||
|
"favicon.ico",
|
||||||
|
"robots.txt",
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
// Assets will load the Rice boxes containing the CSS, SCSS, JS, and HTML files.
|
// Assets will load the Rice boxes containing the CSS, SCSS, JS, and HTML files.
|
||||||
|
|
|
@ -8,26 +8,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
dir string
|
dir string
|
||||||
requiredFiles = []string{
|
|
||||||
"css/style.css",
|
|
||||||
"css/style.css.gz",
|
|
||||||
"css/main.css",
|
|
||||||
"scss/main.scss",
|
|
||||||
"scss/base.scss",
|
|
||||||
"scss/forms.scss",
|
|
||||||
"scss/layout.scss",
|
|
||||||
"scss/mixin.scss",
|
|
||||||
"scss/mobile.scss",
|
|
||||||
"scss/variables.scss",
|
|
||||||
"js/bundle.js",
|
|
||||||
"js/main.chunk.js",
|
|
||||||
"js/polyfill.chunk.js",
|
|
||||||
"js/style.chunk.js",
|
|
||||||
"banner.png",
|
|
||||||
"favicon.ico",
|
|
||||||
"robots.txt",
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -38,8 +19,8 @@ func init() {
|
||||||
dir = utils.Params.GetString("STATPING_DIR")
|
dir = utils.Params.GetString("STATPING_DIR")
|
||||||
}
|
}
|
||||||
|
|
||||||
func assetFiles(t *testing.T, exist bool) {
|
func assertFiles(t *testing.T, exist bool) {
|
||||||
for _, f := range requiredFiles {
|
for _, f := range RequiredFiles {
|
||||||
if exist {
|
if exist {
|
||||||
assert.FileExists(t, dir+"/assets/"+f)
|
assert.FileExists(t, dir+"/assets/"+f)
|
||||||
} else {
|
} else {
|
||||||
|
@ -50,54 +31,65 @@ func assetFiles(t *testing.T, exist bool) {
|
||||||
|
|
||||||
func TestCore_UsingAssets(t *testing.T) {
|
func TestCore_UsingAssets(t *testing.T) {
|
||||||
assert.False(t, UsingAssets(dir))
|
assert.False(t, UsingAssets(dir))
|
||||||
assetFiles(t, false)
|
assertFiles(t, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCreateAssets(t *testing.T) {
|
func TestCreateAssets(t *testing.T) {
|
||||||
assert.Nil(t, CreateAllAssets(dir))
|
assert.Nil(t, CreateAllAssets(dir))
|
||||||
assert.True(t, UsingAssets(dir))
|
assert.True(t, UsingAssets(dir))
|
||||||
assert.Nil(t, CompileSASS())
|
assert.Nil(t, CompileSASS())
|
||||||
assetFiles(t, true)
|
assertFiles(t, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCopyAllToPublic(t *testing.T) {
|
func TestCopyAllToPublic(t *testing.T) {
|
||||||
err := CopyAllToPublic(TmplBox)
|
err := CopyAllToPublic(TmplBox)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
assetFiles(t, true)
|
assertFiles(t, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCompileSASS(t *testing.T) {
|
func TestCompileSASS(t *testing.T) {
|
||||||
err := CompileSASS()
|
err := CompileSASS()
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
assert.True(t, UsingAssets(dir))
|
assert.True(t, UsingAssets(dir))
|
||||||
assetFiles(t, true)
|
assertFiles(t, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSaveAndCompileAsset(t *testing.T) {
|
func TestSaveAndCompileAsset(t *testing.T) {
|
||||||
scssData := "$bodycolor: #333; BODY { color: $bodycolor; }"
|
vars := OpenAsset("scss/variables.scss")
|
||||||
|
vars += "$testingcolor: #b1b2b3;"
|
||||||
|
|
||||||
err := SaveAsset([]byte(scssData), "scss/base.scss")
|
err := SaveAsset([]byte(vars), "scss/variables.scss")
|
||||||
|
require.Nil(t, err)
|
||||||
|
assert.FileExists(t, dir+"/assets/scss/variables.scss")
|
||||||
|
|
||||||
|
scssData := OpenAsset("scss/base.scss")
|
||||||
|
scssData += "BODY { color: $testingcolor; }"
|
||||||
|
err = SaveAsset([]byte(scssData), "scss/base.scss")
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
assert.FileExists(t, dir+"/assets/scss/base.scss")
|
assert.FileExists(t, dir+"/assets/scss/base.scss")
|
||||||
|
|
||||||
asset := OpenAsset("scss/base.scss")
|
asset := OpenAsset("scss/variables.scss")
|
||||||
|
assert.NotEmpty(t, asset)
|
||||||
|
assert.Equal(t, vars, asset)
|
||||||
|
|
||||||
|
asset = OpenAsset("scss/base.scss")
|
||||||
assert.NotEmpty(t, asset)
|
assert.NotEmpty(t, asset)
|
||||||
assert.Equal(t, scssData, asset)
|
assert.Equal(t, scssData, asset)
|
||||||
|
|
||||||
err = CompileSASS()
|
err = CompileSASS()
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
assert.FileExists(t, dir+"/assets/css/main.css")
|
assertFiles(t, true)
|
||||||
|
|
||||||
themeCSS, err := utils.OpenFile(dir + "/assets/css/main.css")
|
themeCSS, err := utils.OpenFile(dir + "/assets/css/main.css")
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
assert.Contains(t, themeCSS, `color: #333;`)
|
assert.Contains(t, themeCSS, `color: #b1b2b3;`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestOpenAsset(t *testing.T) {
|
func TestOpenAsset(t *testing.T) {
|
||||||
for _, f := range requiredFiles {
|
for _, f := range RequiredFiles {
|
||||||
asset := OpenAsset(f)
|
assert.FileExists(t, dir+"/assets/"+f)
|
||||||
assert.NotEmpty(t, asset)
|
assert.NotEmpty(t, OpenAsset(f))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,6 +97,7 @@ func TestDeleteAssets(t *testing.T) {
|
||||||
assert.True(t, UsingAssets(dir))
|
assert.True(t, UsingAssets(dir))
|
||||||
assert.Nil(t, DeleteAllAssets(dir))
|
assert.Nil(t, DeleteAllAssets(dir))
|
||||||
assert.False(t, UsingAssets(dir))
|
assert.False(t, UsingAssets(dir))
|
||||||
|
assertFiles(t, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExampleSaveAsset() {
|
func ExampleSaveAsset() {
|
||||||
|
|
|
@ -20,6 +20,19 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func initModels(db database.Database) {
|
||||||
|
core.SetDB(db)
|
||||||
|
services.SetDB(db)
|
||||||
|
hits.SetDB(db)
|
||||||
|
failures.SetDB(db)
|
||||||
|
checkins.SetDB(db)
|
||||||
|
notifications.SetDB(db)
|
||||||
|
incidents.SetDB(db)
|
||||||
|
users.SetDB(db)
|
||||||
|
messages.SetDB(db)
|
||||||
|
groups.SetDB(db)
|
||||||
|
}
|
||||||
|
|
||||||
// Connect will attempt to connect to the sqlite, postgres, or mysql database
|
// Connect will attempt to connect to the sqlite, postgres, or mysql database
|
||||||
func Connect(configs *DbConfig, retry bool) error {
|
func Connect(configs *DbConfig, retry bool) error {
|
||||||
conn := configs.ConnectionString()
|
conn := configs.ConnectionString()
|
||||||
|
@ -61,19 +74,6 @@ func Connect(configs *DbConfig, retry bool) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func initModels(db database.Database) {
|
|
||||||
core.SetDB(db)
|
|
||||||
services.SetDB(db)
|
|
||||||
hits.SetDB(db)
|
|
||||||
failures.SetDB(db)
|
|
||||||
checkins.SetDB(db)
|
|
||||||
notifications.SetDB(db)
|
|
||||||
incidents.SetDB(db)
|
|
||||||
users.SetDB(db)
|
|
||||||
messages.SetDB(db)
|
|
||||||
groups.SetDB(db)
|
|
||||||
}
|
|
||||||
|
|
||||||
func CreateAdminUser(c *DbConfig) error {
|
func CreateAdminUser(c *DbConfig) error {
|
||||||
adminUser := utils.Params.GetString("ADMIN_USER")
|
adminUser := utils.Params.GetString("ADMIN_USER")
|
||||||
adminPass := utils.Params.GetString("ADMIN_PASSWORD")
|
adminPass := utils.Params.GetString("ADMIN_PASSWORD")
|
||||||
|
|
|
@ -53,7 +53,7 @@ func LoadConfigs(cfgFile string) (*DbConfig, error) {
|
||||||
if db.Location != "" {
|
if db.Location != "" {
|
||||||
p.Set("LOCATION", db.Location)
|
p.Set("LOCATION", db.Location)
|
||||||
}
|
}
|
||||||
if db.ApiSecret != "" {
|
if db.ApiSecret != "" && p.GetString("API_SECRET") == "" {
|
||||||
p.Set("API_SECRET", db.ApiSecret)
|
p.Set("API_SECRET", db.ApiSecret)
|
||||||
}
|
}
|
||||||
if db.Language != "" {
|
if db.Language != "" {
|
||||||
|
@ -90,10 +90,9 @@ func LoadConfigs(cfgFile string) (*DbConfig, error) {
|
||||||
Language: p.GetString("LANGUAGE"),
|
Language: p.GetString("LANGUAGE"),
|
||||||
SendReports: p.GetBool("ALLOW_REPORTS"),
|
SendReports: p.GetBool("ALLOW_REPORTS"),
|
||||||
LetsEncryptEnable: p.GetBool("LETSENCRYPT_ENABLE"),
|
LetsEncryptEnable: p.GetBool("LETSENCRYPT_ENABLE"),
|
||||||
}
|
LetsEncryptHost: p.GetString("LETSENCRYPT_HOST"),
|
||||||
if configs.LetsEncryptEnable {
|
LetsEncryptEmail: p.GetString("LETSENCRYPT_EMAIL"),
|
||||||
configs.LetsEncryptHost = p.GetString("LETSENCRYPT_HOST")
|
ApiSecret: p.GetString("API_SECRET"),
|
||||||
configs.LetsEncryptEmail = p.GetString("LETSENCRYPT_EMAIL")
|
|
||||||
}
|
}
|
||||||
log.WithFields(utils.ToFields(configs)).Debugln("read config file: " + cfgFile)
|
log.WithFields(utils.ToFields(configs)).Debugln("read config file: " + cfgFile)
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,6 @@ type DbConfig struct {
|
||||||
LetsEncryptEmail string `yaml:"letsencrypt_email,omitempty" json:"letsencrypt_email"`
|
LetsEncryptEmail string `yaml:"letsencrypt_email,omitempty" json:"letsencrypt_email"`
|
||||||
LetsEncryptEnable bool `yaml:"letsencrypt_enable" json:"letsencrypt_enable"`
|
LetsEncryptEnable bool `yaml:"letsencrypt_enable" json:"letsencrypt_enable"`
|
||||||
LocalIP string `yaml:"-" json:"-"`
|
LocalIP string `yaml:"-" json:"-"`
|
||||||
filename string `yaml:"-" json:"-"`
|
|
||||||
|
|
||||||
Db database.Database `yaml:"-" json:"-"`
|
Db database.Database `yaml:"-" json:"-"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,18 @@ var db database.Database
|
||||||
|
|
||||||
func SetDB(database database.Database) {
|
func SetDB(database database.Database) {
|
||||||
db = database.Model(&Core{})
|
db = database.Model(&Core{})
|
||||||
|
c, err := Select()
|
||||||
|
if err != nil {
|
||||||
|
utils.Log.Errorln(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
apiEnv := utils.Params.GetString("API_SECRET")
|
||||||
|
if c.ApiSecret != apiEnv && apiEnv != "" {
|
||||||
|
c.ApiSecret = apiEnv
|
||||||
|
if err := c.Update(); err != nil {
|
||||||
|
utils.Log.Errorln(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Core) AfterFind() {
|
func (c *Core) AfterFind() {
|
||||||
|
@ -42,6 +54,9 @@ func Select() (*Core, error) {
|
||||||
if utils.Params.GetString("LANGUAGE") != "" {
|
if utils.Params.GetString("LANGUAGE") != "" {
|
||||||
App.Language = utils.Params.GetString("LANGUAGE")
|
App.Language = utils.Params.GetString("LANGUAGE")
|
||||||
}
|
}
|
||||||
|
if utils.Params.GetString("API_SECRET") != "" {
|
||||||
|
App.ApiSecret = utils.Params.GetString("API_SECRET")
|
||||||
|
}
|
||||||
return App, q.Error()
|
return App, q.Error()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue