~hristoast/obpmg

eee3136c02d7094b8c758dfe77596cdc1eca911b — Hristos N. Triantafillou 2 years ago b82d5fe
Resolve env vars
3 files changed, 10 insertions(+), 7 deletions(-)

M obpmg.go
M obpmg_test.go
M sample.yml
M obpmg.go => obpmg.go +3 -3
@@ 84,10 84,10 @@ func yamlDataToX(x *xmlOpenboxPipeMenu, y []yamlData) *xmlOpenboxPipeMenu {
				xmlAction{
					xml.Name{},
					"Execute",
					data.Exe,
					os.ExpandEnv(data.Exe),
				},
				data.Label,
				data.Icon,
				os.ExpandEnv(data.Label),
				os.ExpandEnv(data.Icon),
			},
			)
		}

M obpmg_test.go => obpmg_test.go +6 -4
@@ 17,10 17,12 @@
package main

import (
	"os"
	"testing"
)

func TestGetYamlData(t *testing.T) {
	os.Setenv("OBPMG_TEST", "testing value")
	y, _ := getYamlData("sample.yml", false)
	x := yamlDataToX(&xmlOpenboxPipeMenu{}, y)



@@ 32,8 34,8 @@ func TestGetYamlData(t *testing.T) {
		t.Errorf("Expected: %s, Got: %s", "/usr/bin/eduke32", y[0].Label)
	}

	if y[0].Icon != "" {
		t.Errorf("Expected: %s, Got: %s", "", y[0].Label)
	if y[0].Icon != "$OBPMG_TEST" {
		t.Errorf("Expected: %s, Got: %s", "", y[0].Icon)
	}

	if y[1].Label != "FTL: Faster Than Light" {


@@ 102,7 104,7 @@ func TestToXml(t *testing.T) {
	x := yamlDataToX(&xmlOpenboxPipeMenu{}, y)
	xb := toXML(x)

	expected := "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<openbox_pipe_menu>\n  <item label=\"Eduke32\" icon=\"\">\n    <action name=\"Execute\">\n      <execute>/usr/bin/eduke32</execute>\n    </action>\n  </item>\n  <item label=\"FTL: Faster Than Light\" icon=\"/home/hristos/games/FTL/data/exe_icon.bmp\">\n    <action name=\"Execute\">\n      <execute>/home/hristos/games/FTL/FTL</execute>\n    </action>\n  </item>\n  <item label=\"MultiMC\" icon=\"/usr/share/pixmaps/multimc.svg\">\n    <action name=\"Execute\">\n      <execute>/usr/bin/MultiMC</execute>\n    </action>\n  </item>\n  <item label=\"OpenMW\" icon=\"/opt/build-openmw/openmw/share/pixmaps/openmw.png\">\n    <action name=\"Execute\">\n      <execute>/opt/build-openmw/openmw/bin/openmw-launcher</execute>\n    </action>\n  </item>\n</openbox_pipe_menu>\n"
	expected := "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<openbox_pipe_menu>\n  <item label=\"Eduke32\" icon=\"testing value\">\n    <action name=\"Execute\">\n      <execute>/usr/bin/eduke32</execute>\n    </action>\n  </item>\n  <item label=\"FTL: Faster Than Light\" icon=\"/home/hristos/games/FTL/data/exe_icon.bmp\">\n    <action name=\"Execute\">\n      <execute>/home/hristos/games/FTL/FTL</execute>\n    </action>\n  </item>\n  <item label=\"MultiMC\" icon=\"/usr/share/pixmaps/multimc.svg\">\n    <action name=\"Execute\">\n      <execute>/usr/bin/MultiMC</execute>\n    </action>\n  </item>\n  <item label=\"OpenMW\" icon=\"/opt/build-openmw/openmw/share/pixmaps/openmw.png\">\n    <action name=\"Execute\">\n      <execute>/opt/build-openmw/openmw/bin/openmw-launcher</execute>\n    </action>\n  </item>\n</openbox_pipe_menu>\n"

	if string(xb) != expected {
		t.Errorf("Expected: %s, Got: %s", expected, string(xb))


@@ 114,7 116,7 @@ func TestToXmlNoSort(t *testing.T) {
	x := yamlDataToX(&xmlOpenboxPipeMenu{}, y)
	xb := toXML(x)

	expected := "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<openbox_pipe_menu>\n  <item label=\"OpenMW\" icon=\"/opt/build-openmw/openmw/share/pixmaps/openmw.png\">\n    <action name=\"Execute\">\n      <execute>/opt/build-openmw/openmw/bin/openmw-launcher</execute>\n    </action>\n  </item>\n  <item label=\"FTL: Faster Than Light\" icon=\"/home/hristos/games/FTL/data/exe_icon.bmp\">\n    <action name=\"Execute\">\n      <execute>/home/hristos/games/FTL/FTL</execute>\n    </action>\n  </item>\n  <item label=\"MultiMC\" icon=\"/usr/share/pixmaps/multimc.svg\">\n    <action name=\"Execute\">\n      <execute>/usr/bin/MultiMC</execute>\n    </action>\n  </item>\n  <item label=\"Eduke32\" icon=\"\">\n    <action name=\"Execute\">\n      <execute>/usr/bin/eduke32</execute>\n    </action>\n  </item>\n</openbox_pipe_menu>\n"
	expected := "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<openbox_pipe_menu>\n  <item label=\"OpenMW\" icon=\"/opt/build-openmw/openmw/share/pixmaps/openmw.png\">\n    <action name=\"Execute\">\n      <execute>/opt/build-openmw/openmw/bin/openmw-launcher</execute>\n    </action>\n  </item>\n  <item label=\"FTL: Faster Than Light\" icon=\"/home/hristos/games/FTL/data/exe_icon.bmp\">\n    <action name=\"Execute\">\n      <execute>/home/hristos/games/FTL/FTL</execute>\n    </action>\n  </item>\n  <item label=\"MultiMC\" icon=\"/usr/share/pixmaps/multimc.svg\">\n    <action name=\"Execute\">\n      <execute>/usr/bin/MultiMC</execute>\n    </action>\n  </item>\n  <item label=\"Eduke32\" icon=\"testing value\">\n    <action name=\"Execute\">\n      <execute>/usr/bin/eduke32</execute>\n    </action>\n  </item>\n</openbox_pipe_menu>\n"

	if string(xb) != expected {
		t.Errorf("Expected: %s, Got: %s", expected, string(xb))

M sample.yml => sample.yml +1 -0
@@ 10,3 10,4 @@
  icon: /usr/share/pixmaps/multimc.svg
- label: Eduke32
  exe: /usr/bin/eduke32
  icon: $OBPMG_TEST