Skip to content

Replace spring-core/util/assert with lvan100/go-assert #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ go.work.sum
# IDE files
.idea/

/conf/remote/app-online.properties
/conf/remote/

gs/examples/bookman/conf/
gs/examples/bookman/log/*.log
Expand Down
2 changes: 1 addition & 1 deletion conf/bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"time"

"github.com/go-spring/spring-core/conf"
"github.com/go-spring/spring-core/util/assert"
"github.com/lvan100/go-assert"
"github.com/spf13/cast"
)

Expand Down
2 changes: 1 addition & 1 deletion conf/conf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"testing"

"github.com/go-spring/spring-core/conf"
"github.com/go-spring/spring-core/util/assert"
"github.com/lvan100/go-assert"
)

func TestProperties_Load(t *testing.T) {
Expand Down
13 changes: 1 addition & 12 deletions conf/expr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"testing"

"github.com/go-spring/spring-core/conf"
"github.com/go-spring/spring-core/util/assert"
"github.com/lvan100/go-assert"
)

func TestExpr(t *testing.T) {
Expand Down Expand Up @@ -51,17 +51,6 @@ func TestExpr(t *testing.T) {
assert.Error(t, err, "validate failed on .* for value 14")
})

t.Run("syntax error", func(t *testing.T) {
var v struct {
A int `value:"${a}" expr:"checkInt($2)"`
}
p := conf.Map(map[string]interface{}{
"a": 4,
})
err := p.Bind(&v)
assert.Error(t, err, "eval .* returns error")
})

t.Run("return not bool", func(t *testing.T) {
var v struct {
A int `value:"${a}" expr:"$+$"`
Expand Down
2 changes: 1 addition & 1 deletion conf/reader/json/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package json
import (
"testing"

"github.com/go-spring/spring-core/util/assert"
"github.com/lvan100/go-assert"
)

func TestRead(t *testing.T) {
Expand Down
8 changes: 4 additions & 4 deletions conf/reader/prop/prop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package prop
import (
"testing"

"github.com/go-spring/spring-core/util/assert"
"github.com/lvan100/go-assert"
)

func TestRead(t *testing.T) {
Expand All @@ -46,7 +46,7 @@ func TestRead(t *testing.T) {
})
})

t.Run("map", func(t *testing.T) {
t.Run("simple map", func(t *testing.T) {
r, err := Read([]byte(`
map.bool=false
map.int=3
Expand All @@ -62,7 +62,7 @@ func TestRead(t *testing.T) {
})
})

t.Run("array struct", func(t *testing.T) {
t.Run("array with struct", func(t *testing.T) {
r, err := Read([]byte(`
array[0].bool=false
array[0].int=3
Expand All @@ -86,7 +86,7 @@ func TestRead(t *testing.T) {
})
})

t.Run("map struct", func(t *testing.T) {
t.Run("map with struct", func(t *testing.T) {

r, err := Read([]byte(`
map.k1.bool=false
Expand Down
8 changes: 4 additions & 4 deletions conf/reader/toml/toml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package toml
import (
"testing"

"github.com/go-spring/spring-core/util/assert"
"github.com/lvan100/go-assert"
)

func TestRead(t *testing.T) {
Expand Down Expand Up @@ -53,7 +53,7 @@ func TestRead(t *testing.T) {
})
})

t.Run("map", func(t *testing.T) {
t.Run("simple map", func(t *testing.T) {
r, err := Read([]byte(`
[map]
bool=false
Expand All @@ -72,7 +72,7 @@ func TestRead(t *testing.T) {
})
})

t.Run("array struct", func(t *testing.T) {
t.Run("array with struct", func(t *testing.T) {
r, err := Read([]byte(`
[[array]]
bool=false
Expand Down Expand Up @@ -105,7 +105,7 @@ func TestRead(t *testing.T) {
})
})

t.Run("map struct", func(t *testing.T) {
t.Run("map with struct", func(t *testing.T) {
r, err := Read([]byte(`
[map.k1]
bool=false
Expand Down
8 changes: 4 additions & 4 deletions conf/reader/yaml/yaml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"strings"
"testing"

"github.com/go-spring/spring-core/util/assert"
"github.com/lvan100/go-assert"
)

func TestRead(t *testing.T) {
Expand Down Expand Up @@ -56,7 +56,7 @@ func TestRead(t *testing.T) {
})
})

t.Run("map", func(t *testing.T) {
t.Run("simple map", func(t *testing.T) {
str := `
map:
bool: false
Expand All @@ -77,7 +77,7 @@ func TestRead(t *testing.T) {
})
})

t.Run("array struct", func(t *testing.T) {
t.Run("array with struct", func(t *testing.T) {
str := `
array:
-
Expand Down Expand Up @@ -112,7 +112,7 @@ func TestRead(t *testing.T) {
})
})

t.Run("map struct", func(t *testing.T) {
t.Run("map with struct", func(t *testing.T) {
str := `
map:
k1:
Expand Down
2 changes: 1 addition & 1 deletion conf/storage/path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"fmt"
"testing"

"github.com/go-spring/spring-core/util/assert"
"github.com/lvan100/go-assert"
)

func TestSplitPath(t *testing.T) {
Expand Down
38 changes: 21 additions & 17 deletions conf/storage/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,27 @@
* limitations under the License.
*/

// Package storage provides structured configuration storage, and `ConfigPath` represents
// the hierarchical path of a configuration item.
//
// Each configuration item must have a well-defined type. The key of a configuration item
// (its `path`) can be split into components that form a tree structure, where each node
// corresponds to a part of the configuration hierarchy.
//
// The `path` serves both as the unique identifier (key) of the configuration item and
// as its location within the configuration tree. This design mirrors the structure of
// typical configuration file formats such as JSON, YAML, and TOML.
//
// A `path` is composed of only two types of elements:
// - Key: Represents a map key in the configuration tree.
// - Index: Represents an array index in the configuration tree.
//
// This approach ensures consistency, type safety, and compatibility with structured
// configuration formats.
/*
Package storage provides hierarchical configuration storage and path parsing utilities.

Features:
- Storage manages key-value pairs with support for nested paths, subkey lookup, and conflict detection.
- Path represents structured access paths with support for parsing (SplitPath) and construction (JoinPath).
- Supports two path types:
- Key (e.g., "user.name") for map access
- Index (e.g., "[0]") for array access

- Maintains a tree structure (treeNode) for consistent and type-safe hierarchy management.

Use cases:
- Accessing values in JSON/YAML/TOML-like configs
- Managing nested config data (CRUD)
- Validating structure and detecting conflicts

Notes:
- Path syntax follows common config patterns (e.g., "users[0].profile.age")
- Type-safe path handling (keys vs. indices)
*/
package storage

import (
Expand Down
10 changes: 2 additions & 8 deletions conf/storage/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package storage
import (
"testing"

"github.com/go-spring/spring-core/util/assert"
"github.com/lvan100/go-assert"
)

func TestStorage(t *testing.T) {
Expand Down Expand Up @@ -102,8 +102,6 @@ func TestStorage(t *testing.T) {
assert.False(t, s.Has("m[0]"))
assert.False(t, s.Has("m.x[0]"))

//err = s.Set("m", "")
//assert.Error(t, err, "key or value is empty")
err = s.Set("m", "a")
assert.Error(t, err, "property conflict at path m")
err = s.Set("m.x.z", "w")
Expand Down Expand Up @@ -155,8 +153,6 @@ func TestStorage(t *testing.T) {
"[0]": "p",
})

//err = s.Set("[0]", "")
//assert.Error(t, err, "key or value is empty")
err = s.Set("[0]x", "f")
assert.Error(t, err, "invalid key '\\[0]x'")
err = s.Set("[0].x", "f")
Expand Down Expand Up @@ -210,15 +206,13 @@ func TestStorage(t *testing.T) {
assert.Nil(t, err)
assert.Equal(t, subKeys, []string{"0", "1"})

//err = s.Set("s", "")
//assert.Error(t, err, "key or value is empty")
err = s.Set("s", "w")
assert.Error(t, err, "property conflict at path s")
err = s.Set("s.x", "f")
assert.Error(t, err, "property conflict at path s.x")
})

t.Run("complex", func(t *testing.T) {
t.Run("map && array", func(t *testing.T) {
s := NewStorage()

err := s.Set("a.b[0].c", "123")
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ module github.com/go-spring/spring-core
go 1.24

require (
github.com/expr-lang/expr v1.16.9
github.com/expr-lang/expr v1.17.2
github.com/lvan100/go-assert v0.0.1
github.com/magiconair/properties v1.8.9
github.com/pelletier/go-toml v1.9.5
github.com/spf13/cast v1.7.1
go.uber.org/mock v0.5.0
go.uber.org/mock v0.5.1
gopkg.in/yaml.v2 v2.4.0
)
10 changes: 6 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/expr-lang/expr v1.16.9 h1:WUAzmR0JNI9JCiF0/ewwHB1gmcGw5wW7nWt8gc6PpCI=
github.com/expr-lang/expr v1.16.9/go.mod h1:8/vRC7+7HBzESEqt5kKpYXxrxkr31SaO8r40VO/1IT4=
github.com/expr-lang/expr v1.17.2 h1:o0A99O/Px+/DTjEnQiodAgOIK9PPxL8DtXhBRKC+Iso=
github.com/expr-lang/expr v1.17.2/go.mod h1:8/vRC7+7HBzESEqt5kKpYXxrxkr31SaO8r40VO/1IT4=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
Expand All @@ -8,6 +8,8 @@ github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/lvan100/go-assert v0.0.1 h1:qBYQ8zOvRl7u5+8YnTxKBaRnqYoADOS6XRyxecLFJnU=
github.com/lvan100/go-assert v0.0.1/go.mod h1:osFFuU9zt4/SdTaJ9uU3y9qabAFDYlaH4Yte/ndDAj4=
github.com/magiconair/properties v1.8.9 h1:nWcCbLq1N2v/cpNsy5WvQ37Fb+YElfq20WJ/a8RkpQM=
github.com/magiconair/properties v1.8.9/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8=
Expand All @@ -16,8 +18,8 @@ github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZV
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/spf13/cast v1.7.1 h1:cuNEagBQEHWN1FnbGEjCXL2szYEXqfJPbP2HNUaca9Y=
github.com/spf13/cast v1.7.1/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
go.uber.org/mock v0.5.0 h1:KAMbZvZPyBPWgD14IrIQ38QCyjwpvVVV6K/bHl1IwQU=
go.uber.org/mock v0.5.0/go.mod h1:ge71pBPLYDk7QIi1LupWxdAykm7KIEFchiOqd6z7qMM=
go.uber.org/mock v0.5.1 h1:ASgazW/qBmR+A32MYFDB6E2POoTgOwT509VP0CT/fjs=
go.uber.org/mock v0.5.1/go.mod h1:ge71pBPLYDk7QIi1LupWxdAykm7KIEFchiOqd6z7qMM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
Expand Down
Loading