Skip to content
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

Update to go 1.22 & fix linting #85

Merged
merged 2 commits into from
Jun 28, 2024
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
17 changes: 6 additions & 11 deletions conflate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package conflate
import (
gocontext "context"
"net/http"
"os"
"sync"
"testing"
"time"
Expand Down Expand Up @@ -56,14 +55,12 @@ func TestAddData_Expand(t *testing.T) {
c := New()
c.Expand(true)

err := os.Setenv("X", "123")
assert.Nil(t, err)
err = os.Setenv("Y", "str")
assert.Nil(t, err)
t.Setenv("X", "123")
t.Setenv("Y", "str")

inJSON := []byte(`{ "x": $X, "y": "$Y", "z": "$Z"}`)

err = c.AddData(inJSON)
err := c.AddData(inJSON)
assert.Nil(t, err)
outJSON, err := c.MarshalJSON()
assert.Nil(t, err)
Expand All @@ -79,14 +76,12 @@ func TestAddData_NoExpand(t *testing.T) {
c := New()
c.Expand(false)

err := os.Setenv("X", "123")
assert.Nil(t, err)
err = os.Setenv("Y", "str")
assert.Nil(t, err)
t.Setenv("X", "123")
t.Setenv("Y", "str")

inJSON := []byte(`{ "x": "$X" }`)

err = c.AddData(inJSON)
err := c.AddData(inJSON)
assert.Nil(t, err)

outJSON, err := c.MarshalJSON()
Expand Down
4 changes: 2 additions & 2 deletions error.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import (

type context string

type errWithContext struct {
type contextError struct {
msg string
context context
}

func (e errWithContext) Error() string {
func (e contextError) Error() string {
return fmt.Sprintf("%v (%v)", e.msg, e.context)
}
2 changes: 1 addition & 1 deletion filedata.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func recursiveExpand(b []byte) []byte {

var c int

for i := 0; i < maxExpansions; i++ {
for range maxExpansions {
b, c = expand(b)
if c == 0 {
return b
Expand Down
33 changes: 8 additions & 25 deletions filedata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package conflate
import (
"errors"
pkgurl "net/url"
"os"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -12,13 +11,17 @@ import (
var errTest = errors.New("my error")

func testFiledataNew(t *testing.T, data []byte, path string) (filedata, error) {
t.Helper()

url, err := pkgurl.Parse(path)
assert.Nil(t, err)

return newFiledata(data, url)
}

func testFiledataNewAssert(t *testing.T, data []byte, path string) filedata {
t.Helper()

fd, err := testFiledataNew(t, data, path)
assert.Nil(t, err)

Expand Down Expand Up @@ -188,30 +191,10 @@ func TestFiledata_IncludesError(t *testing.T) {
}

func TestFiledata_Expand(t *testing.T) {
w := os.Getenv("W")
x := os.Getenv("X")
y := os.Getenv("Y")
z := os.Getenv("Z")

err := os.Setenv("W", "$W")
assert.Nil(t, err)
err = os.Setenv("X", `"x"`)
assert.Nil(t, err)
err = os.Setenv("Y", `y`)
assert.Nil(t, err)
err = os.Setenv("Z", `$Y`)
assert.Nil(t, err)

defer func() {
err = os.Setenv("W", w)
assert.Nil(t, err)
err = os.Setenv("X", x)
assert.Nil(t, err)
err = os.Setenv("Y", y)
assert.Nil(t, err)
err = os.Setenv("Z", z)
assert.Nil(t, err)
}()
t.Setenv("W", "$W")
t.Setenv("X", `"x"`)
t.Setenv("Y", `y`)
t.Setenv("Z", `$Y`)

b := recursiveExpand([]byte(`{"W":"$W","X":$X,"Y":"$Y","Z":"$Z"}`))
assert.Equal(t, string(b), string(`{"W":"$W","X":"x","Y":"y","Z":"y"}`))
Expand Down
2 changes: 1 addition & 1 deletion format.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (f xmlTemplateFormatChecker) IsFormat(input interface{}) bool {

if s, ok := input.(string); ok {
s = f.tags.ReplaceAllString(s, "")
if len(s) > 0 {
if s != "" {
var v interface{}
if err := xml.Unmarshal([]byte(s), &v); err != nil {
ferr = fmt.Errorf("failed to parse xml: %w", err)
Expand Down
6 changes: 6 additions & 0 deletions format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ func TestHtmlFormatCheckerIsFormat_NotValid(t *testing.T) {
// --------

func testCryptoFormatCheckerIsFormatNotString(t *testing.T, cryptoType cryptoType) {
t.Helper()

givenName := cryptoName
givenValue := 1

Expand Down Expand Up @@ -243,6 +245,8 @@ func TestCryptoFormatCheckerIsFormat_NotString(t *testing.T) {
}

func testCryptoFormatCheckerIsFormatNotValid(t *testing.T, cryptoType cryptoType) {
t.Helper()

givenName := cryptoName
givenValue := "dGhpcyBpcyBub3QgYSB2YWxpZCBjZXJ0aWZpY2F0ZQo="

Expand Down Expand Up @@ -270,6 +274,8 @@ func TestCryptoFormatCheckerIsFormat_NotValid(t *testing.T) {
}

func testCryptoFormatCheckerIsFormatValid(t *testing.T, cryptoType cryptoType, givenValue string) {
t.Helper()

givenName := cryptoName

formatErrs.clear()
Expand Down
64 changes: 36 additions & 28 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,45 +1,53 @@
module github.com/miracl/conflate

go 1.21
go 1.22

require (
cloud.google.com/go/storage v1.33.0
github.com/BurntSushi/toml v0.3.1
cloud.google.com/go/storage v1.42.0
github.com/BurntSushi/toml v1.4.0
github.com/ghodss/yaml v1.0.0
github.com/stretchr/testify v1.8.1
github.com/stretchr/testify v1.9.0
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415
github.com/xeipuuv/gojsonschema v1.2.0
golang.org/x/net v0.12.0
golang.org/x/net v0.26.0
)

require (
cloud.google.com/go v0.110.4 // indirect
cloud.google.com/go/compute v1.20.1 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v1.1.0 // indirect
cloud.google.com/go v0.115.0 // indirect
cloud.google.com/go/auth v0.6.0 // indirect
cloud.google.com/go/auth/oauth2adapt v0.2.2 // indirect
cloud.google.com/go/compute/metadata v0.3.0 // indirect
cloud.google.com/go/iam v1.1.8 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/s2a-go v0.1.4 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.5 // indirect
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.5 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
go.opencensus.io v0.24.0 // indirect
golang.org/x/crypto v0.11.0 // indirect
golang.org/x/oauth2 v0.10.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/api v0.132.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230706204954-ccb25ca9f130 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230706204954-ccb25ca9f130 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect
google.golang.org/grpc v1.56.2 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/yaml.v2 v2.2.7 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.52.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.52.0 // indirect
go.opentelemetry.io/otel v1.27.0 // indirect
go.opentelemetry.io/otel/metric v1.27.0 // indirect
go.opentelemetry.io/otel/trace v1.27.0 // indirect
golang.org/x/crypto v0.24.0 // indirect
golang.org/x/oauth2 v0.21.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/api v0.186.0 // indirect
google.golang.org/genproto v0.0.0-20240624140628-dc46fd24d27d // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240624140628-dc46fd24d27d // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240624140628-dc46fd24d27d // indirect
google.golang.org/grpc v1.64.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading
Loading