From 10d8b03957475721206e0a228d879f6a7def5729 Mon Sep 17 00:00:00 2001
From: Volker Schukai <volker.schukai@schukai.com>
Date: Wed, 18 Sep 2024 14:38:49 +0200
Subject: [PATCH] chore: add new test for boolValue

---
 go.sum             | 23 -----------------
 issue-17_test.go   | 63 ++++++++++++++++++++++++++++++++++++++++++++++
 value-bool_test.go | 29 +++++++++++++++++++++
 3 files changed, 92 insertions(+), 23 deletions(-)
 create mode 100644 issue-17_test.go

diff --git a/go.sum b/go.sum
index 21693bc..5f87219 100644
--- a/go.sum
+++ b/go.sum
@@ -11,10 +11,6 @@ github.com/kinbiko/jsonassert v1.1.1 h1:DB12divY+YB+cVpHULLuKePSi6+ui4M/shHSzJIS
 github.com/kinbiko/jsonassert v1.1.1/go.mod h1:NO4lzrogohtIdNUNzx8sdzB55M4R4Q1bsrWVdqQ7C+A=
 github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
 github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
-github.com/pelletier/go-toml/v2 v2.1.1 h1:LWAJwfNvjQZCFIDKWYQaM62NcYeYViCmWIwmOStowAI=
-github.com/pelletier/go-toml/v2 v2.1.1/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
-github.com/pelletier/go-toml/v2 v2.2.1 h1:9TA9+T8+8CUCO2+WYnDLCgrYi9+omqKXyjDtosvtEhg=
-github.com/pelletier/go-toml/v2 v2.2.1/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
 github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M=
 github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc=
 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
@@ -22,14 +18,7 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
 github.com/r3labs/diff/v3 v3.0.1 h1:CBKqf3XmNRHXKmdU7mZP1w7TV0pDyVCis1AUHtA4Xtg=
 github.com/r3labs/diff/v3 v3.0.1/go.mod h1:f1S9bourRbiM66NskseyUdo0fTmEE0qKrikYJX63dgo=
 github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
-github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
-github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
-github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
 github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
-github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
-github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
-github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
-github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
 github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
 github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
 github.com/vmihailenco/msgpack/v5 v5.3.5/go.mod h1:7xyJ9e+0+9SaZT0Wt1RGleJXzli6Q/V5KbhBonMG9jc=
@@ -43,20 +32,8 @@ gitlab.schukai.com/oss/libraries/go/utilities/pathfinder v0.9.2 h1:cbrnohA6SyqH6
 gitlab.schukai.com/oss/libraries/go/utilities/pathfinder v0.9.2/go.mod h1:MqCBFv7DXKoBE2rZDc51LGvl2QI7Kz0D+XkQ0izj+ws=
 gitlab.schukai.com/oss/libraries/go/utilities/watch v0.4.0 h1:5jwbpUbE721pinIAgzQCfBEnjMjqd/rDQl6gNplpz1M=
 gitlab.schukai.com/oss/libraries/go/utilities/watch v0.4.0/go.mod h1:1pP8q6sEYUXs8rRSXOBCshjGqg6JtVTx8NPkTBNZHwk=
-golang.org/x/exp v0.0.0-20231214170342-aacd6d4b4611 h1:qCEDpW1G+vcj3Y7Fy52pEM1AWm3abj8WimGYejI3SC4=
-golang.org/x/exp v0.0.0-20231214170342-aacd6d4b4611/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI=
-golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc h1:ao2WRsKSzW6KuUY9IWPwWahcHCgR0s52IfwutMfEbdM=
-golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI=
-golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f h1:99ci1mjWVBWwJiEKYY6jWa4d2nTQVIEhZIptnrVb1XY=
-golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f/go.mod h1:/lliqkxwWAhPjf5oSOIJup2XcqJaw8RGS6k3TGEc7GI=
 golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 h1:e66Fs6Z+fZTbFBAxKfP3PALWBtpfqks2bwGcexMxgtk=
 golang.org/x/exp v0.0.0-20240909161429-701f63a606c0/go.mod h1:2TbTHSBQa924w8M6Xs1QcRcFwyucIwBGpK1p2f1YFFY=
-golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
-golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
-golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
-golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
-golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
-golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
 golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
 golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
 gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
diff --git a/issue-17_test.go b/issue-17_test.go
new file mode 100644
index 0000000..5cbd6a4
--- /dev/null
+++ b/issue-17_test.go
@@ -0,0 +1,63 @@
+// Copyright 2022 schukai GmbH
+// SPDX-License-Identifier: AGPL-3.0
+
+package configuration
+
+import (
+	"github.com/stretchr/testify/assert"
+	"os"
+	"testing"
+)
+
+type Issue17Struct struct {
+	P1 *BoolValue `json:"p1" yaml:"p1"`
+	P2 *BoolValue `json:"p2" yaml:"p2"`
+}
+
+func createIssue17TempFile(content string) (string, error) {
+	file, err := os.CreateTemp("", "tempfile")
+	if err != nil {
+		return "", err
+	}
+	defer func() {
+		_ = file.Close()
+	}()
+
+	_, err = file.WriteString(content)
+	if err != nil {
+		return "", err
+	}
+
+	return file.Name(), nil
+}
+
+func TestIssue17LoadBool(t *testing.T) {
+
+	c := New(Issue17Struct{})
+
+	n, err := createIssue17TempFile(`
+p1: true
+p2: off
+`)
+
+	if err != nil {
+		t.Fatal(err)
+	}
+
+	c.SetMnemonic("my-app")
+	c.AddFile(n)
+	c.Import()
+
+	_ = os.Remove(n)
+
+	if c.errors != nil {
+		t.Fatal(c.errors)
+	}
+
+	assert.Equal(t, "true", c.Config().P1.String())
+	assert.Equal(t, true, c.Config().P1.IsTrue())
+
+	assert.Equal(t, "false", c.Config().P2.String())
+	assert.Equal(t, false, c.Config().P2.IsTrue())
+
+}
diff --git a/value-bool_test.go b/value-bool_test.go
index 20dbc04..ff61217 100644
--- a/value-bool_test.go
+++ b/value-bool_test.go
@@ -222,6 +222,35 @@ func TestBoolValueJsonDecode(t *testing.T) {
 	}
 }
 
+func TestBoolValueYamlDecode2(t *testing.T) {
+	yamlContent := `
+value1: true
+value2: false
+value3: on
+value4: 1
+`
+	var unmarshal map[string]BoolValue
+	data := []byte(yamlContent)
+	err := yaml.Unmarshal(data, &unmarshal)
+	if err != nil {
+		t.Errorf("Unmarshaling failed when it should not have: %v", err)
+		return
+	}
+	if unmarshal["value1"].String() != "true" {
+		t.Errorf("Unmarshaled value %v does not match original %v", unmarshal, "true")
+	}
+	if unmarshal["value2"].String() != "false" {
+		t.Errorf("Unmarshaled value %v does not match original %v", unmarshal, "false")
+	}
+	if unmarshal["value3"].String() != "true" {
+		t.Errorf("Unmarshaled value %v does not match original %v", unmarshal, "true")
+	}
+	if unmarshal["value4"].String() != "true" {
+		t.Errorf("Unmarshaled value %v does not match original %v", unmarshal, "true")
+	}
+
+}
+
 func TestBoolValueYamlDecode(t *testing.T) {
 
 	cases := []struct {
-- 
GitLab