Skip to content

Commit

Permalink
required sass files to render in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hunterlong committed Aug 3, 2020
1 parent ae25e84 commit f089364
Show file tree
Hide file tree
Showing 14 changed files with 156 additions and 98 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ install: build
install-local: build
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:
cd source && go generate

Expand Down Expand Up @@ -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 "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
7 changes: 4 additions & 3 deletions cmd/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/statping/statping/utils"
"io/ioutil"
"os"
"path/filepath"
"strings"
"time"
)
Expand Down Expand Up @@ -67,8 +68,8 @@ After=network-online.target
[Service]
Type=simple
Restart=always
Environment=STATPING_DIR=` + dir + `
Environment=ALLOW_REPORTS=true
Environment="STATPING_DIR=` + dir + `"
Environment="ALLOW_REPORTS=true"
ExecStart=` + binPath + ` --port=` + utils.ToString(port) + `
WorkingDirectory=` + dir + `
Expand Down Expand Up @@ -97,7 +98,7 @@ WantedBy=multi-user.target"
}

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 {
filename = fmt.Sprintf("%s/%s", utils.Directory, args)
}
Expand Down
39 changes: 28 additions & 11 deletions cmd/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package main

import (
"bytes"
"github.com/statping/statping/source"
"github.com/statping/statping/utils"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"io/ioutil"
"os"
"testing"
)

Expand All @@ -18,16 +20,15 @@ func init() {
}

func TestStatpingDirectory(t *testing.T) {
dir := utils.Directory
require.NotContains(t, dir, "/cmd")
require.NotEmpty(t, dir)

dir = utils.Params.GetString("STATPING_DIR")
require.NotContains(t, dir, "/cmd")
require.NotEmpty(t, dir)
}

func TestEnvCLI(t *testing.T) {
os.Setenv("API_SECRET", "demoapisecret123")
os.Setenv("SASS", "/usr/local/bin/sass")

cmd := rootCmd
b := bytes.NewBufferString("")
cmd.SetOut(b)
Expand All @@ -39,6 +40,12 @@ func TestEnvCLI(t *testing.T) {
assert.Contains(t, string(out), VERSION)
assert.Contains(t, utils.Directory, 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) {
Expand All @@ -58,16 +65,26 @@ func TestAssetsCLI(t *testing.T) {
b := bytes.NewBufferString("")
cmd.SetOut(b)
cmd.SetArgs([]string{"assets"})
cmd.Execute()
err := cmd.Execute()
require.Nil(t, err)
out, err := ioutil.ReadAll(b)
assert.Nil(t, err)
assert.Contains(t, string(out), VERSION)
assert.FileExists(t, utils.Directory+"/assets/css/main.css")
assert.FileExists(t, utils.Directory+"/assets/css/style.css")
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")
for _, f := range source.RequiredFiles {
assert.FileExists(t, utils.Directory+"/assets/"+f)
}
}

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) {
Expand Down
55 changes: 33 additions & 22 deletions cmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@ import (
)

var rootCmd = &cobra.Command{
Use: "statping",
Short: "A simple Application Status Monitor that is opensource and lightweight.",
Use: "statping",
Version: VERSION,
Short: "A simple Application Status Monitor that is opensource and lightweight.",
Run: func(cmd *cobra.Command, args []string) {
start()
},
}

var updateCmd = &cobra.Command{
Use: "update",
Short: "Update to the latest version",
Use: "update",
Example: "statping update",
Short: "Update to the latest version",
RunE: func(cmd *cobra.Command, args []string) error {
log.Infoln("Updating Statping to the latest version...")
curl, err := exec.LookPath("curl")
Expand Down Expand Up @@ -59,8 +61,9 @@ var updateCmd = &cobra.Command{
}

var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the version number of Statping",
Use: "version",
Example: "statping version",
Short: "Print the version number of Statping",
Run: func(cmd *cobra.Command, args []string) {
if COMMIT != "" {
fmt.Printf("%s (%s)\n", VERSION, COMMIT)
Expand All @@ -72,8 +75,9 @@ var versionCmd = &cobra.Command{
}

var systemctlCmd = &cobra.Command{
Use: "systemctl [install/uninstall]",
Short: "Install or Uninstall systemctl services",
Use: "systemctl [install/uninstall]",
Example: "statping systemctl install",
Short: "Install or Uninstall systemctl services",
RunE: func(cmd *cobra.Command, args []string) error {
if args[1] == "install" {
if len(args) < 3 {
Expand All @@ -99,8 +103,9 @@ var systemctlCmd = &cobra.Command{
}

var assetsCmd = &cobra.Command{
Use: "assets",
Short: "Dump all assets used locally to be edited",
Use: "assets",
Example: "statping assets",
Short: "Dump all assets used locally to be edited",
RunE: func(cmd *cobra.Command, args []string) error {
if err := assetsCli(); err != nil {
return err
Expand All @@ -111,8 +116,9 @@ var assetsCmd = &cobra.Command{
}

var exportCmd = &cobra.Command{
Use: "export",
Short: "Exports your Statping settings to a 'statping-export.json' file.",
Use: "export",
Example: "statping export",
Short: "Exports your Statping settings to a 'statping-export.json' file.",
RunE: func(cmd *cobra.Command, args []string) error {
if err := exportCli(args); err != nil {
return err
Expand All @@ -123,8 +129,9 @@ var exportCmd = &cobra.Command{
}

var sassCmd = &cobra.Command{
Use: "sass",
Short: "Compile .scss files into the css directory",
Use: "sass",
Example: "statping sass",
Short: "Compile .scss files into the css directory",
RunE: func(cmd *cobra.Command, args []string) error {
if err := sassCli(); err != nil {
return err
Expand All @@ -135,8 +142,9 @@ var sassCmd = &cobra.Command{
}

var envCmd = &cobra.Command{
Use: "env",
Short: "Return the configs that will be ran",
Use: "env",
Example: "statping env",
Short: "Return the configs that will be ran",
RunE: func(cmd *cobra.Command, args []string) error {
if err := envCli(); err != nil {
return err
Expand All @@ -147,8 +155,9 @@ var envCmd = &cobra.Command{
}

var resetCmd = &cobra.Command{
Use: "reset",
Short: "Start a fresh copy of Statping",
Use: "reset",
Example: "statping reset",
Short: "Start a fresh copy of Statping",
RunE: func(cmd *cobra.Command, args []string) error {
if err := resetCli(); err != nil {
return err
Expand All @@ -159,8 +168,9 @@ var resetCmd = &cobra.Command{
}

var onceCmd = &cobra.Command{
Use: "once",
Short: "Check all services 1 time and then quit",
Use: "once",
Example: "statping once",
Short: "Check all services 1 time and then quit",
RunE: func(cmd *cobra.Command, args []string) error {
if err := onceCli(); err != nil {
return err
Expand All @@ -171,8 +181,9 @@ var onceCmd = &cobra.Command{
}

var importCmd = &cobra.Command{
Use: "import [.json file]",
Short: "Imports settings from a previously saved JSON file.",
Use: "import [.json file]",
Example: "statping import backup.json",
Short: "Imports settings from a previously saved JSON file.",
RunE: func(cmd *cobra.Command, args []string) error {
if err := importCli(args); err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/assets/scss/forms.scss
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

.form-control[readonly] {
background-color: lighten($background-color, 12%) !important;
color: lighten($input-color, 40%) !important;
color: lighten($input-color, 30%) !important;
}

/* The slider itself */
Expand Down
2 changes: 0 additions & 2 deletions frontend/src/pages/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

<h6 class="mt-4 text-muted">Notifiers</h6>

{{notifiers}}

<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">
<font-awesome-icon :icon="iconName(notifier.icon)" class="mr-2"/> {{notifier.title}}
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require (
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/getsentry/sentry-go v0.5.1
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/hako/durafmt v0.0.0-20200605151348-3a43fc422dd9
github.com/jinzhu/gorm v1.9.12
Expand Down
7 changes: 4 additions & 3 deletions handlers/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ type testNotificationReq struct {

func testNotificationHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
n, err := notifications.Find(vars["notifier"])
if err != nil {
sendErrorJson(err, w, r)
n := services.FindNotifier(vars["notifier"])
if n == nil {
sendErrorJson(errors.New("unknown notifier"), w, r)
return
}

Expand All @@ -82,6 +82,7 @@ func testNotificationHandler(w http.ResponseWriter, r *http.Request) {
notif := services.ReturnNotifier(n.Method)

var out string
var err error
if req.Method == "success" {
out, err = notif.OnSuccess(services.Example(true))
} else {
Expand Down
23 changes: 21 additions & 2 deletions source/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,27 @@ import (
)

var (
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'
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'
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.
Expand Down
Loading

0 comments on commit f089364

Please sign in to comment.