diff --git a/app/frontend/src/elements/Variables.svelte b/app/frontend/src/elements/Variables.svelte index f17ecd70b..fab3f7059 100644 --- a/app/frontend/src/elements/Variables.svelte +++ b/app/frontend/src/elements/Variables.svelte @@ -1,7 +1,6 @@ {#if variables && variables.length && values} @@ -29,6 +43,7 @@

- 💡 You must refresh the plugin for changes to take effect. + 💡 You must refresh the plugin for changes to take effect.

{/if} diff --git a/pkg/plugins/plugin.go b/pkg/plugins/plugin.go index c387b4066..92aba9832 100644 --- a/pkg/plugins/plugin.go +++ b/pkg/plugins/plugin.go @@ -321,7 +321,7 @@ func (p *Plugin) loadVariablesFromJSONFile() ([]string, error) { f, err := os.Open(variablesJSONFilename) if err != nil && os.IsNotExist(err) { // no .vars.json file - no probs - p.Debugf("%s, no such file:", variablesJSONFilename) + p.Debugf("(skipping) no variable file: %s", variablesJSONFilename) return nil, nil } else if err != nil { p.Debugf("ERR: %s", variablesJSONFilename, err) @@ -332,7 +332,7 @@ func (p *Plugin) loadVariablesFromJSONFile() ([]string, error) { if err != nil { return nil, err } - p.Debugf("vars json: %s", string(b)) + p.Debugf("%s: %s", variablesJSONFilename, string(b)) var varmap map[string]interface{} if err := json.Unmarshal(b, &varmap); err != nil { return nil, errors.Wrap(err, "json.Unmarshal") diff --git a/pkg/plugins/plugin_test.go b/pkg/plugins/plugin_test.go index 5527fb1c9..c18d85905 100644 --- a/pkg/plugins/plugin_test.go +++ b/pkg/plugins/plugin_test.go @@ -2,8 +2,6 @@ package plugins import ( "context" - "log" - "os" "path/filepath" "strings" "sync" @@ -265,38 +263,6 @@ It also contains a very long line which should be wrapped, because otherwise it is.Equal(len(p.Items.ExpandedItems), 3) } - -func TestEnvironmentVariables(t *testing.T) { - is := is.New(t) - - err := os.Setenv("XBAR_TEST_EXPLICIT_VAR", "explicit") - is.NoErr(err) - t.Cleanup(func() { - err := os.Unsetenv("XBAR_TEST_EXPLICIT_VAR") - is.NoErr(err) - }) - - ctx := context.Background() - ctx, cancel := context.WithTimeout(ctx, 1*time.Second) - defer cancel() - - p := &Plugin{ - Command: filepath.Join("testdata", "vars-test", "plugin.sh"), - Debugf: DebugfNoop, - Timeout: 1 * time.Second, - RefreshInterval: RefreshInterval{N: 250, Unit: "milliseconds"}, - CycleInterval: 500 * time.Millisecond, - } - p.Run(ctx) - - log.Printf("%+v\n", p.Items.ExpandedItems) - - is.Equal(len(p.Items.CycleItems), 2) - is.Equal(p.Items.CycleItems[0].Text, `XBAR_TEST_EXPLICIT_VAR=explicit`) - is.Equal(p.Items.CycleItems[1].Text, `XBAR_TEST_SET_IN_VARS_JSON=json`) - -} - func TestCleanFilename(t *testing.T) { is := is.New(t) diff --git a/pkg/plugins/variables_test.go b/pkg/plugins/variables_test.go index 164a6a2e7..057dc2d83 100644 --- a/pkg/plugins/variables_test.go +++ b/pkg/plugins/variables_test.go @@ -1,13 +1,45 @@ package plugins import ( + "context" "io/ioutil" "os" + "path/filepath" "testing" + "time" "github.com/matryer/is" ) +func TestEnvironmentVariables(t *testing.T) { + is := is.New(t) + + err := os.Setenv("XBAR_TEST_EXPLICIT_VAR", "explicit") + is.NoErr(err) + t.Cleanup(func() { + err := os.Unsetenv("XBAR_TEST_EXPLICIT_VAR") + is.NoErr(err) + }) + + ctx := context.Background() + ctx, cancel := context.WithTimeout(ctx, 1*time.Second) + defer cancel() + + p := &Plugin{ + Command: filepath.Join("testdata", "vars-test", "plugin.sh"), + Debugf: DebugfNoop, + Timeout: 1 * time.Second, + RefreshInterval: RefreshInterval{N: 250, Unit: "milliseconds"}, + CycleInterval: 500 * time.Millisecond, + } + p.Run(ctx) + + is.Equal(len(p.Items.CycleItems), 2) + is.Equal(p.Items.CycleItems[0].Text, `XBAR_TEST_EXPLICIT_VAR=explicit`) // inherited + is.Equal(p.Items.CycleItems[1].Text, `XBAR_TEST_SET_IN_VARS_JSON=json`) // in vars.json file + +} + func TestVariablesPersistence(t *testing.T) { is := is.New(t)