summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gohadoopxml.go10
-rw-r--r--gohadoopxml_test.go19
2 files changed, 29 insertions, 0 deletions
diff --git a/gohadoopxml.go b/gohadoopxml.go
index d6d5721..336a673 100644
--- a/gohadoopxml.go
+++ b/gohadoopxml.go
@@ -2,6 +2,7 @@ package gohadoopxml
import (
"encoding/xml"
+ "errors"
"io/ioutil"
"log"
"os"
@@ -36,6 +37,15 @@ func ParseXML(filename string) (Configuration, error) {
return config, nil
}
+func GetPropertyValue(key string, config Configuration) (string, error) {
+ for _, p := range config.Properties {
+ if key == p.Name {
+ return p.Value, nil
+ }
+ }
+ return "", errors.New("Key not found")
+}
+
func MergeConfigurations(configs ...Configuration) Configuration {
var new_config Configuration
for _, config := range configs {
diff --git a/gohadoopxml_test.go b/gohadoopxml_test.go
index aa81010..ab6c36e 100644
--- a/gohadoopxml_test.go
+++ b/gohadoopxml_test.go
@@ -38,3 +38,22 @@ func TestMergeConfiguration(t *testing.T) {
t.Fail()
}
}
+
+func TestGetPropertyValue(t *testing.T) {
+ var config = Configuration{
+ Properties: []Property{
+ {
+ Name: "foo",
+ Value: "bar",
+ },
+ },
+ }
+ result, err := GetPropertyValue("foo", config)
+ if err != nil || result != "bar" {
+ t.Fail()
+ }
+ result, err = GetPropertyValue("fizz", config)
+ if err == nil {
+ t.Fail()
+ }
+}