Skip to content

Commit

Permalink
upgrae codebase to go1.18 (#794)
Browse files Browse the repository at this point in the history
This updates to go 1.18 as base since some dependencies now
only support go 1.18 as latest.  Updates all the dependencies.

Move to any{} over interface{}{} and updates travis

Signed-off-by: R.I.Pienaar <[email protected]>

Signed-off-by: R.I.Pienaar <[email protected]>
  • Loading branch information
ripienaar authored Jan 1, 2023
1 parent a157ea3 commit ba8d39e
Show file tree
Hide file tree
Showing 20 changed files with 214 additions and 645 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ env:
language: go

go:
- 1.17.x
- 1.18.x

os:
- osx
Expand Down
51 changes: 37 additions & 14 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,33 +1,56 @@
module github.com/goss-org/goss

go 1.18

require (
github.com/Masterminds/sprig/v3 v3.2.3
github.com/achanda/go-sysctl v0.0.0-20160222034550-6be7678c45d2
github.com/blang/semver/v4 v4.0.0
github.com/cheekybits/genny v1.0.0
github.com/fatih/color v1.13.0
github.com/google/go-cmp v0.5.9 // indirect
github.com/goss-org/GOnetstat v0.0.0-20220505220511-31d79a98d9f2
github.com/goss-org/go-ps v0.0.0-20201009164808-61c449472dcf
github.com/huandu/xstrings v1.4.0 // indirect
github.com/imdario/mergo v0.3.13 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/goss-org/GOnetstat v0.0.0-20230101144325-22be0bd9e64d
github.com/goss-org/go-ps v0.0.0-20230101144351-953ade48a71b
github.com/miekg/dns v1.1.50
github.com/moby/sys/mountinfo v0.6.2
github.com/oleiade/reflections v1.0.1
github.com/onsi/ginkgo/v2 v2.1.4 // indirect
github.com/onsi/gomega v1.19.0
github.com/onsi/gomega v1.24.2
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/prometheus/client_golang v1.14.0
github.com/prometheus/common v0.37.0
github.com/prometheus/common v0.39.0
github.com/stretchr/testify v1.8.1
github.com/urfave/cli v1.22.10
gopkg.in/yaml.v2 v2.4.0
)

require (
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.2.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/huandu/xstrings v1.4.0 // indirect
github.com/imdario/mergo v0.3.13 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/shopspring/decimal v1.3.1 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/stretchr/testify v1.7.1
github.com/urfave/cli v1.22.9
golang.org/x/crypto v0.4.0 // indirect
golang.org/x/mod v0.7.0 // indirect
golang.org/x/net v0.4.0 // indirect
golang.org/x/sys v0.3.0 // indirect
golang.org/x/text v0.5.0 // indirect
golang.org/x/tools v0.4.0 // indirect
gopkg.in/yaml.v2 v2.4.0
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

go 1.16
522 changes: 34 additions & 488 deletions go.sum

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions goss_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,21 +140,21 @@ func (c *GossConfig) Resources() []resource.Resource {
return tests
}

func genericConcatMaps(maps ...interface{}) (ret []map[string]interface{}) {
func genericConcatMaps(maps ...any) (ret []map[string]any) {
for _, slice := range maps {
im := interfaceMap(slice)
ret = append(ret, im)
}
return ret
}

func interfaceMap(slice interface{}) map[string]interface{} {
func interfaceMap(slice any) map[string]any {
m := reflect.ValueOf(slice)
if m.Kind() != reflect.Map {
panic("InterfaceSlice() given a non-slice type")
}

ret := make(map[string]interface{})
ret := make(map[string]any)

for _, k := range m.MapKeys() {
ret[k.Interface().(string)] = m.MapIndex(k).Interface()
Expand Down
2 changes: 1 addition & 1 deletion goss_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/goss-org/goss/util"
)

func checkErr(t *testing.T, err error, format string, a ...interface{}) {
func checkErr(t *testing.T, err error, format string, a ...any) {
t.Helper()
if err == nil {
return
Expand Down
18 changes: 9 additions & 9 deletions matchers/semver_constraint.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ import (
"github.com/onsi/gomega/types"
)

func BeSemverConstraint(constraint interface{}) types.GomegaMatcher {
func BeSemverConstraint(constraint any) types.GomegaMatcher {
return &BeSemverConstraintMatcher{
Constraint: constraint,
}
}

type BeSemverConstraintMatcher struct {
Constraint interface{}
Constraint any
}

func (matcher *BeSemverConstraintMatcher) Match(actual interface{}) (success bool, err error) {
func (matcher *BeSemverConstraintMatcher) Match(actual any) (success bool, err error) {
constraint, ok := toConstraint(matcher.Constraint)
if !ok {
return false, fmt.Errorf("Expected a valid semver constraint. Got:\n%s", format.Object(matcher.Constraint, 1))
Expand All @@ -39,15 +39,15 @@ func (matcher *BeSemverConstraintMatcher) Match(actual interface{}) (success boo
return true, nil
}

func (matcher *BeSemverConstraintMatcher) FailureMessage(actual interface{}) (message string) {
func (matcher *BeSemverConstraintMatcher) FailureMessage(actual any) (message string) {
return format.Message(actual, fmt.Sprintf("to be %s", matcher.Constraint))
}

func (matcher *BeSemverConstraintMatcher) NegatedFailureMessage(actual interface{}) (message string) {
func (matcher *BeSemverConstraintMatcher) NegatedFailureMessage(actual any) (message string) {
return format.Message(actual, fmt.Sprintf("not to be %s", matcher.Constraint))
}

func toConstraint(in interface{}) (semver.Range, bool) {
func toConstraint(in any) (semver.Range, bool) {
str, ok := in.(string)
if !ok {
return nil, false
Expand All @@ -57,7 +57,7 @@ func toConstraint(in interface{}) (semver.Range, bool) {
return out, err == nil
}

func toVersion(in interface{}) (*semver.Version, bool) {
func toVersion(in any) (*semver.Version, bool) {
str, ok := in.(string)
if !ok {
return nil, false
Expand All @@ -71,7 +71,7 @@ func toVersion(in interface{}) (*semver.Version, bool) {
return &v, true
}

func toVersions(in interface{}) ([]*semver.Version, bool) {
func toVersions(in any) ([]*semver.Version, bool) {
if v, ok := toVersion(in); ok {
return []*semver.Version{v}, ok
}
Expand All @@ -82,7 +82,7 @@ func toVersions(in interface{}) ([]*semver.Version, bool) {

out := make([]*semver.Version, 0)

if slice, ok := in.([]interface{}); ok {
if slice, ok := in.([]any); ok {
for _, ele := range slice {
if v, ok := toVersion(ele); ok {
out = append(out, v)
Expand Down
26 changes: 13 additions & 13 deletions matchers/semver_constraint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

func TestBeSemverConstraint(t *testing.T) {
type args struct {
Constraint interface{}
Constraint any
}
tests := []struct {
name string
Expand All @@ -36,10 +36,10 @@ func TestBeSemverConstraint(t *testing.T) {

func TestBeSemverConstraintMatcher_FailureMessage(t *testing.T) {
type fields struct {
Constraint interface{}
Constraint any
}
type args struct {
actual interface{}
actual any
}
tests := []struct {
name string
Expand Down Expand Up @@ -73,10 +73,10 @@ func TestBeSemverConstraintMatcher_FailureMessage(t *testing.T) {

func TestBeSemverConstraintMatcher_Match(t *testing.T) {
type fields struct {
Constraint interface{}
Constraint any
}
type args struct {
actual interface{}
actual any
}
type want struct {
success bool
Expand Down Expand Up @@ -165,10 +165,10 @@ func TestBeSemverConstraintMatcher_Match(t *testing.T) {

func TestBeSemverConstraintMatcher_NegatedFailureMessage(t *testing.T) {
type fields struct {
Constraint interface{}
Constraint any
}
type args struct {
actual interface{}
actual any
}
tests := []struct {
name string
Expand Down Expand Up @@ -203,7 +203,7 @@ func TestBeSemverConstraintMatcher_NegatedFailureMessage(t *testing.T) {

func Test_toConstraint(t *testing.T) {
type args struct {
in interface{}
in any
}
type want struct {
ok bool
Expand Down Expand Up @@ -254,7 +254,7 @@ func Test_toConstraint(t *testing.T) {

func Test_toVersion(t *testing.T) {
type args struct {
in interface{}
in any
}
type want struct {
ok bool
Expand Down Expand Up @@ -303,7 +303,7 @@ func Test_toVersion(t *testing.T) {

func Test_toVersions(t *testing.T) {
type args struct {
in interface{}
in any
}
type want struct {
ok bool
Expand All @@ -325,7 +325,7 @@ func Test_toVersions(t *testing.T) {
},
{
name: "slice_interfaces",
args: args{in: []interface{}{"1.0.0"}},
args: args{in: []any{"1.0.0"}},
want: want{ok: true},
},
{
Expand All @@ -335,7 +335,7 @@ func Test_toVersions(t *testing.T) {
},
{
name: "invalid_object_in_slice",
args: args{in: []interface{}{want{}}},
args: args{in: []any{want{}}},
want: want{ok: false},
},
}
Expand All @@ -351,7 +351,7 @@ func Test_toVersions(t *testing.T) {
for i, version := range gotVersions {
if versions, ok := tt.args.in.([]string); ok {
assert.Equal(t, fmt.Sprint(versions[i]), version.String())
} else if versions, ok := tt.args.in.([]interface{}); ok {
} else if versions, ok := tt.args.in.([]any); ok {
assert.Equal(t, fmt.Sprint(versions[i]), version.String())
} else {
assert.Equal(t, fmt.Sprint(tt.args.in), version.String())
Expand Down
10 changes: 5 additions & 5 deletions outputs/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (r Json) Output(w io.Writer, results <-chan []resource.TestResult,
color.NoColor = true
testCount := 0
failed := 0
var resultsOut []map[string]interface{}
var resultsOut []map[string]any
for resultGroup := range results {
for _, testResult := range resultGroup {
if !testResult.Successful {
Expand All @@ -42,14 +42,14 @@ func (r Json) Output(w io.Writer, results <-chan []resource.TestResult,
}
}

summary := make(map[string]interface{})
summary := make(map[string]any)
duration := time.Since(startTime)
summary["test-count"] = testCount
summary["failed-count"] = failed
summary["total-duration"] = duration
summary["summary-line"] = fmt.Sprintf("Count: %d, Failed: %d, Duration: %.3fs", testCount, failed, duration.Seconds())

out := make(map[string]interface{})
out := make(map[string]any)
out["results"] = resultsOut
out["summary"] = summary

Expand All @@ -69,8 +69,8 @@ func (r Json) Output(w io.Writer, results <-chan []resource.TestResult,
return 0
}

func struct2map(i interface{}) map[string]interface{} {
out := make(map[string]interface{})
func struct2map(i any) map[string]any {
out := make(map[string]any)
j, _ := json.Marshal(i)
json.Unmarshal(j, &out)
return out
Expand Down
6 changes: 3 additions & 3 deletions outputs/json_oneline.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (r JsonOneline) Output(w io.Writer, results <-chan []resource.TestResult,
color.NoColor = true
testCount := 0
failed := 0
var resultsOut []map[string]interface{}
var resultsOut []map[string]any
for resultGroup := range results {
for _, testResult := range resultGroup {
if !testResult.Successful {
Expand All @@ -37,14 +37,14 @@ func (r JsonOneline) Output(w io.Writer, results <-chan []resource.TestResult,
}
}

summary := make(map[string]interface{})
summary := make(map[string]any)
duration := time.Since(startTime)
summary["test-count"] = testCount
summary["failed-count"] = failed
summary["total-duration"] = duration
summary["summary-line"] = fmt.Sprintf("Count: %d, Failed: %d, Duration: %.3fs", testCount, failed, duration.Seconds())

out := make(map[string]interface{})
out := make(map[string]any)
out["results"] = resultsOut
out["summary"] = summary

Expand Down
Loading

0 comments on commit ba8d39e

Please sign in to comment.