Skip to content

Commit 8174b9f

Browse files
committed
fix(tests): fixed failling backend test
1 parent fb9e91e commit 8174b9f

File tree

5 files changed

+33
-20
lines changed

5 files changed

+33
-20
lines changed

main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,16 @@ func main() {
6969
}
7070

7171
func initRuntime() {
72-
setting.NewConfigContext(&setting.CommandLineArgs{
72+
err := setting.NewConfigContext(&setting.CommandLineArgs{
7373
Config: *configFile,
7474
HomePath: *homePath,
7575
Args: flag.Args(),
7676
})
7777

78+
if err != nil {
79+
log.Fatal(3, err.Error())
80+
}
81+
7882
log.Info("Starting Grafana")
7983
log.Info("Version: %v, Commit: %v, Build date: %v", setting.BuildVersion, setting.BuildCommit, time.Unix(setting.BuildStamp, 0))
8084
setting.LogConfigurationInfo()

pkg/setting/setting.go

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package setting
66
import (
77
"bytes"
88
"encoding/json"
9+
"errors"
910
"fmt"
1011
"net/url"
1112
"os"
@@ -355,24 +356,26 @@ func setHomePath(args *CommandLineArgs) {
355356
}
356357
}
357358

358-
func getStaticRootPath(configValue string) string {
359-
if configValue != "public" {
360-
return configValue
359+
var skipStaticRootValidation bool = false
360+
361+
func validateStaticRootPath() error {
362+
if skipStaticRootValidation {
363+
return nil
361364
}
362365

363-
if _, err := os.Stat(path.Join(HomePath, configValue, "css")); err == nil {
364-
return configValue
366+
if _, err := os.Stat(path.Join(StaticRootPath, "css")); err == nil {
367+
return nil
365368
}
366369

367-
if _, err := os.Stat(path.Join(HomePath, "public_gen", "css")); err == nil {
368-
return "public_gen"
370+
if _, err := os.Stat(StaticRootPath + "_gen/css"); err == nil {
371+
StaticRootPath = StaticRootPath + "_gen"
372+
return nil
369373
}
370374

371-
log.Fatal(3, "Failed to detect generated css or javascript files in static root (%s), have you executed default grunt task?", configValue)
372-
return ""
375+
return errors.New("Failed to detect generated css or javascript files in static root (%s), have you executed default grunt task?")
373376
}
374377

375-
func NewConfigContext(args *CommandLineArgs) {
378+
func NewConfigContext(args *CommandLineArgs) error {
376379
setHomePath(args)
377380
loadConfiguration(args)
378381

@@ -391,10 +394,14 @@ func NewConfigContext(args *CommandLineArgs) {
391394
Domain = server.Key("domain").MustString("localhost")
392395
HttpAddr = server.Key("http_addr").MustString("0.0.0.0")
393396
HttpPort = server.Key("http_port").MustString("3000")
394-
StaticRootPath = makeAbsolute(getStaticRootPath(server.Key("static_root_path").String()), HomePath)
395397
RouterLogging = server.Key("router_logging").MustBool(false)
396398
EnableGzip = server.Key("enable_gzip").MustBool(false)
397399
EnforceDomain = server.Key("enforce_domain").MustBool(false)
400+
StaticRootPath = makeAbsolute(server.Key("static_root_path").String(), HomePath)
401+
402+
if err := validateStaticRootPath(); err != nil {
403+
return err
404+
}
398405

399406
// read security settings
400407
security := Cfg.Section("security")
@@ -455,6 +462,8 @@ func NewConfigContext(args *CommandLineArgs) {
455462
if VerifyEmailEnabled && !Smtp.Enabled {
456463
log.Warn("require_email_validation is enabled but smpt is disabled")
457464
}
465+
466+
return nil
458467
}
459468

460469
func readSessionConfig() {

pkg/setting/setting_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ import (
1111
func TestLoadingSettings(t *testing.T) {
1212

1313
Convey("Testing loading settings from ini file", t, func() {
14+
skipStaticRootValidation = true
1415

1516
Convey("Given the default ini files", func() {
16-
NewConfigContext(&CommandLineArgs{HomePath: "../../"})
17+
err := NewConfigContext(&CommandLineArgs{HomePath: "../../"})
18+
So(err, ShouldBeNil)
1719

1820
So(AdminUser, ShouldEqual, "admin")
1921
})

public/app/controllers/signupCtrl.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
///<reference path="../headers/require/require.d.ts" />
2-
///<reference path="../headers/angularjs/angularjs.d.ts" />
3-
///<amd-dependency path="angular"/>
4-
///<amd-dependency path="config"/>
1+
///<reference path="../headers/common.d.ts" />
2+
///<amd-dependency path="config" name="config" />
53

6-
var angular = require('angular');
7-
var config = require('config');
4+
import angular = require('angular');
5+
declare var config : any;
86

97
var module = angular.module('grafana.controllers');
108

public/app/core/filters/filters.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
///<reference path="../../headers/common.d.ts" />
2-
//
2+
33
import angular = require('angular');
44
import jquery = require('jquery');
55
import moment = require('moment');

0 commit comments

Comments
 (0)