diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:36:04 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:36:04 +0000 |
commit | b09c6d56832eb1718c07d74abf3bc6ae3fe4e030 (patch) | |
tree | d2caec2610d4ea887803ec9e9c3cd77136c448ba /dependencies/pkg/mod/github.com/jmoiron/sqlx@v1.3.5/types/types_test.go | |
parent | Initial commit. (diff) | |
download | icingadb-b09c6d56832eb1718c07d74abf3bc6ae3fe4e030.tar.xz icingadb-b09c6d56832eb1718c07d74abf3bc6ae3fe4e030.zip |
Adding upstream version 1.1.0.upstream/1.1.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | dependencies/pkg/mod/github.com/jmoiron/sqlx@v1.3.5/types/types_test.go | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/dependencies/pkg/mod/github.com/jmoiron/sqlx@v1.3.5/types/types_test.go b/dependencies/pkg/mod/github.com/jmoiron/sqlx@v1.3.5/types/types_test.go new file mode 100644 index 0000000..29813d1 --- /dev/null +++ b/dependencies/pkg/mod/github.com/jmoiron/sqlx@v1.3.5/types/types_test.go @@ -0,0 +1,127 @@ +package types + +import "testing" + +func TestGzipText(t *testing.T) { + g := GzippedText("Hello, world") + v, err := g.Value() + if err != nil { + t.Errorf("Was not expecting an error") + } + err = (&g).Scan(v) + if err != nil { + t.Errorf("Was not expecting an error") + } + if string(g) != "Hello, world" { + t.Errorf("Was expecting the string we sent in (Hello World), got %s", string(g)) + } +} + +func TestJSONText(t *testing.T) { + j := JSONText(`{"foo": 1, "bar": 2}`) + v, err := j.Value() + if err != nil { + t.Errorf("Was not expecting an error") + } + err = (&j).Scan(v) + if err != nil { + t.Errorf("Was not expecting an error") + } + m := map[string]interface{}{} + j.Unmarshal(&m) + + if m["foo"].(float64) != 1 || m["bar"].(float64) != 2 { + t.Errorf("Expected valid json but got some garbage instead? %#v", m) + } + + j = JSONText(`{"foo": 1, invalid, false}`) + v, err = j.Value() + if err == nil { + t.Errorf("Was expecting invalid json to fail!") + } + + j = JSONText("") + v, err = j.Value() + if err != nil { + t.Errorf("Was not expecting an error") + } + + err = (&j).Scan(v) + if err != nil { + t.Errorf("Was not expecting an error") + } + + j = JSONText(nil) + v, err = j.Value() + if err != nil { + t.Errorf("Was not expecting an error") + } + + err = (&j).Scan(v) + if err != nil { + t.Errorf("Was not expecting an error") + } +} + +func TestNullJSONText(t *testing.T) { + j := NullJSONText{} + err := j.Scan(`{"foo": 1, "bar": 2}`) + if err != nil { + t.Errorf("Was not expecting an error") + } + v, err := j.Value() + if err != nil { + t.Errorf("Was not expecting an error") + } + err = (&j).Scan(v) + if err != nil { + t.Errorf("Was not expecting an error") + } + m := map[string]interface{}{} + j.Unmarshal(&m) + + if m["foo"].(float64) != 1 || m["bar"].(float64) != 2 { + t.Errorf("Expected valid json but got some garbage instead? %#v", m) + } + + j = NullJSONText{} + err = j.Scan(nil) + if err != nil { + t.Errorf("Was not expecting an error") + } + if j.Valid != false { + t.Errorf("Expected valid to be false, but got true") + } +} + +func TestBitBool(t *testing.T) { + // Test true value + var b BitBool = true + + v, err := b.Value() + if err != nil { + t.Errorf("Cannot return error") + } + err = (&b).Scan(v) + if err != nil { + t.Errorf("Was not expecting an error") + } + if !b { + t.Errorf("Was expecting the bool we sent in (true), got %v", b) + } + + // Test false value + b = false + + v, err = b.Value() + if err != nil { + t.Errorf("Cannot return error") + } + err = (&b).Scan(v) + if err != nil { + t.Errorf("Was not expecting an error") + } + if b { + t.Errorf("Was expecting the bool we sent in (false), got %v", b) + } +} |