Skip to content

Commit

Permalink
gofumpt
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Jan 20, 2025
1 parent d81df4a commit 6ddd15c
Show file tree
Hide file tree
Showing 16 changed files with 84 additions and 89 deletions.
1 change: 0 additions & 1 deletion pkg/kube/labels/selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,6 @@ func (p *Parser) parseRequirement() (*Requirement, error) {
return nil, err
}
return NewRequirement(key, operator, values.List(), field.WithPath(p.path))

}

// parseKeyAndInferOperator parses literals.
Expand Down
97 changes: 52 additions & 45 deletions pkg/kube/labels/selector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ import (
"k8s.io/apimachinery/pkg/util/validation/field"
)

var (
ignoreDetail = cmpopts.IgnoreFields(field.Error{}, "Detail")
)
var ignoreDetail = cmpopts.IgnoreFields(field.Error{}, "Detail")

func expectNoMatch(selector string, ls Set) {
lq, err := Parse(selector)
Expand Down Expand Up @@ -90,20 +88,17 @@ var _ = ginkgo.Describe("Selectors", func() {
})
}

var _ = ginkgo.It("Deterministic match", func() {
_ = ginkgo.It("Deterministic match", func() {
s1, err := Parse("x=a,a=x")
Expect(err).ToNot(HaveOccurred())
s2, err2 := Parse("a=x,x=a")
Expect(err2).ToNot(HaveOccurred())
Expect(s1.String()).To(Equal(s2.String()))

})

ginkgo.It("Everything", func() {

Expect(Everything().Matches(Set{"x": "y"})).To(BeTrue())
Expect(Everything().Empty()).To(BeTrue())

})

ginkgo.It("SelectorMatches", func() {
Expand Down Expand Up @@ -135,11 +130,9 @@ var _ = ginkgo.Describe("Selectors", func() {
expectNoMatch("foo=blah", labelset)
expectNoMatch("baz=bar", labelset)
expectNoMatch("foo=bar,foobar=bar,baz=blah", labelset)

})

ginkgo.It("Set matches", func() {

labelset := Set{
"foo": "bar",
"baz": "blah",
Expand All @@ -149,10 +142,10 @@ var _ = ginkgo.Describe("Selectors", func() {
expectMatchDirect(Set{"baz": "blah"}, labelset)
expectMatchDirect(Set{"foo": "bar", "baz": "blah"}, labelset)

//TODO: bad values not handled for the moment in SelectorFromSet
//expectNoMatchDirect( Set{"foo": "=blah"}, labelset)
//expectNoMatchDirect( Set{"baz": "=bar"}, labelset)
//expectNoMatchDirect( Set{"foo": "=bar", "foobar": "bar", "baz": "blah"}, labelset)
// TODO: bad values not handled for the moment in SelectorFromSet
// expectNoMatchDirect( Set{"foo": "=blah"}, labelset)
// expectNoMatchDirect( Set{"baz": "=bar"}, labelset)
// expectNoMatchDirect( Set{"foo": "=bar", "foobar": "bar", "baz": "blah"}, labelset)
})

ginkgo.It("NilMapIsValid", func() {
Expand All @@ -170,7 +163,6 @@ var _ = ginkgo.Describe("Selectors", func() {

nilSelector := NewSelector()
Expect(nilSelector.Empty()).To(BeTrue())

})

ginkgo.Describe("Lexer", func() {
Expand All @@ -186,12 +178,12 @@ var _ = ginkgo.Describe("Selectors", func() {
{"==", DoubleEqualsToken},
{">", GreaterThanToken},
{"<", LessThanToken},
//Note that Lex returns the longest valid token found
// Note that Lex returns the longest valid token found
{"!", DoesNotExistToken},
{"!=", NotEqualsToken},
{"(", OpenParToken},
{")", ClosedParToken},
//Non-"special" characters are considered part of an identifier
// Non-"special" characters are considered part of an identifier
{"~", IdentifierToken},
{"||", IdentifierToken},
}
Expand Down Expand Up @@ -252,6 +244,7 @@ var _ = ginkgo.Describe("Lexer", func() {
})
}
})

var _ = ginkgo.Describe("Parser", func() {
testcases := []struct {
s string
Expand Down Expand Up @@ -485,37 +478,52 @@ var _ = ginkgo.Describe("ToString", func() {
Out string
Valid bool
}{

{&internalSelector{
getRequirement("x", selection.In, sets.NewString("abc", "def")),
getRequirement("y", selection.NotIn, sets.NewString("jkl")),
getRequirement("z", selection.Exists, nil)},
"x in (abc,def),y notin (jkl),z", true},
{&internalSelector{
getRequirement("x", selection.NotIn, sets.NewString("abc", "def")),
getRequirement("y", selection.NotEquals, sets.NewString("jkl")),
getRequirement("z", selection.DoesNotExist, nil)},
"x notin (abc,def),y!=jkl,!z", true},
{
&internalSelector{
getRequirement("x", selection.In, sets.NewString("abc", "def")),
getRequirement("y", selection.NotIn, sets.NewString("jkl")),
getRequirement("z", selection.Exists, nil),
},
"x in (abc,def),y notin (jkl),z", true,
},
{
&internalSelector{
getRequirement("x", selection.NotIn, sets.NewString("abc", "def")),
getRequirement("y", selection.NotEquals, sets.NewString("jkl")),
getRequirement("z", selection.DoesNotExist, nil),
},
"x notin (abc,def),y!=jkl,!z", true,
},
{&internalSelector{
getRequirement("x", selection.In, sets.NewString("abc", "def")),
req}, // adding empty req for the trailing ','
req,
}, // adding empty req for the trailing ','
"x in (abc,def),", false},
{&internalSelector{
getRequirement("x", selection.NotIn, sets.NewString("abc")),
getRequirement("y", selection.In, sets.NewString("jkl", "mno")),
getRequirement("z", selection.NotIn, sets.NewString(""))},
"x notin (abc),y in (jkl,mno),z notin ()", true},
{&internalSelector{
getRequirement("x", selection.Equals, sets.NewString("abc")),
getRequirement("y", selection.DoubleEquals, sets.NewString("jkl")),
getRequirement("z", selection.NotEquals, sets.NewString("a")),
getRequirement("z", selection.Exists, nil)},
"x=abc,y==jkl,z!=a,z", true},
{&internalSelector{
getRequirement("x", selection.GreaterThan, sets.NewString("2")),
getRequirement("y", selection.LessThan, sets.NewString("8")),
getRequirement("z", selection.Exists, nil)},
"x>2,y<8,z", true},
{
&internalSelector{
getRequirement("x", selection.NotIn, sets.NewString("abc")),
getRequirement("y", selection.In, sets.NewString("jkl", "mno")),
getRequirement("z", selection.NotIn, sets.NewString("")),
},
"x notin (abc),y in (jkl,mno),z notin ()", true,
},
{
&internalSelector{
getRequirement("x", selection.Equals, sets.NewString("abc")),
getRequirement("y", selection.DoubleEquals, sets.NewString("jkl")),
getRequirement("z", selection.NotEquals, sets.NewString("a")),
getRequirement("z", selection.Exists, nil),
},
"x=abc,y==jkl,z!=a,z", true,
},
{
&internalSelector{
getRequirement("x", selection.GreaterThan, sets.NewString("2")),
getRequirement("y", selection.LessThan, sets.NewString("8")),
getRequirement("z", selection.Exists, nil),
},
"x>2,y<8,z", true,
},
}
for _, ts := range toStringTests {
ts := ts // capture range variable
Expand Down Expand Up @@ -682,7 +690,6 @@ var _ = ginkgo.Describe("SetSelectorParser", func() {
} else {
Expect(sel).To(Equal(ssp.Out))
}

}
})
}
Expand Down
6 changes: 2 additions & 4 deletions query/check_details.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ import (
"github.com/samber/lo"
)

var (
// Default search window
DefaultCheckQueryWindow = "1h"
)
// Default search window
var DefaultCheckQueryWindow = "1h"

type Timeseries struct {
Key string `json:"key,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion query/check_summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func CheckSummary(ctx context.Context, opts ...CheckSummaryOptions) ([]models.Ch

query := fmt.Sprintf(`SELECT json_agg(%s) FROM check_summary AS result WHERE deleted_at is null`, selectField)

var args = pgx.NamedArgs{}
args := pgx.NamedArgs{}
if opt.DeleteFrom != nil {
query += " OR deleted_at > @from"
args["from"] = *opt.DeleteFrom
Expand Down
7 changes: 2 additions & 5 deletions query/commons.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ func postgrestValues(val []any) string {
}

func (query FilteringQuery) AppendPostgrest(key string,
queryParam url.Values) {

queryParam url.Values,
) {
if len(query.In) > 0 {
queryParam.Add(key, fmt.Sprintf("in.(%s)", postgrestValues(query.In)))
}
Expand All @@ -46,11 +46,9 @@ func (query FilteringQuery) AppendPostgrest(key string,
for _, p := range query.Suffix {
queryParam.Add(key, fmt.Sprintf("like.*%s", p))
}

}

func (e expressions) ToExpression(field string) []clause.Expression {

var clauses []clause.Expression
if len(e.In) > 0 {
clauses = append(clauses, clause.IN{Column: clause.Column{Name: field}, Values: e.In})
Expand Down Expand Up @@ -94,7 +92,6 @@ func ParseFilteringQuery(query string, decodeURL bool) (in []interface{}, notIN
}

q, err := types.ParseFilteringQueryV2(query, decodeURL)

if err != nil {
return nil, nil, nil, nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions query/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ type ConfigSummaryRequestChanges struct {
sinceParsed time.Duration
}

type ConfigSummaryRequestAnalysis struct {
}
type ConfigSummaryRequestAnalysis struct{}

type ConfigSummaryRequest struct {
Changes ConfigSummaryRequestChanges `json:"changes"`
Expand Down
10 changes: 6 additions & 4 deletions query/config_changes.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func formSeverityQuery(severity string) string {
return severity
}

var severities = []models.Severity{
severities := []models.Severity{
models.SeverityCritical,
models.SeverityHigh,
models.SeverityMedium,
Expand Down Expand Up @@ -375,9 +375,11 @@ func FindCatalogChanges(ctx context.Context, req CatalogChangesSearchRequest) (*

if req.SortBy != "" {
clauses = append(clauses,
clause.OrderBy{Columns: []clause.OrderByColumn{{
Column: clause.Column{Name: req.SortBy},
Desc: req.sortOrder == "desc"},
clause.OrderBy{Columns: []clause.OrderByColumn{
{
Column: clause.Column{Name: req.SortBy},
Desc: req.sortOrder == "desc",
},
}})
}

Expand Down
1 change: 0 additions & 1 deletion query/config_relations.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,4 @@ func GetRelatedConfigs(ctx context.Context, query RelationQuery) ([]RelatedConfi
query.Outgoing).Find(&relatedConfigs).Error

return relatedConfigs, err

}
2 changes: 0 additions & 2 deletions query/gitops.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ func gitopsSourceCELFunction() func(ctx context.Context) cel.EnvOption {
[]*cel.Type{cel.DynType},
cel.DynType,
cel.UnaryBinding(func(arg ref.Val) ref.Val {

id, err := getConfigId(arg.Value())
if err != nil {
ctx.Errorf("could not find id: %v", err)
Expand Down Expand Up @@ -186,7 +185,6 @@ func getConfigId(id any) (uuid.UUID, error) {
func gitopsSourceTemplateFunction() func(ctx context.Context) any {
return func(ctx context.Context) any {
return func(args ...any) map[string]any {

var source GitOpsSource
if len(args) < 1 {
return source.AsMap()
Expand Down
3 changes: 1 addition & 2 deletions query/grammar/grammar_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type Source struct {
}

type NumberUnit struct {
Number interface{} `json:"number,omitempty"` //int64/float64
Number interface{} `json:"number,omitempty"` // int64/float64
Units string `json:"units,omitempty"`
}

Expand Down Expand Up @@ -95,7 +95,6 @@ func makeQuery(a, b interface{}) (*types.QueryField, error) {
}

func makeAndQuery(a any, b any) (*types.QueryField, error) {

q := &types.QueryField{Op: "and"}

switch v := a.(type) {
Expand Down
1 change: 0 additions & 1 deletion query/grammar/grammar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
)

var _ = Describe("grammar", func() {

It("parses", func() {
result, err := ParsePEG("metadata.name=bob metadata.name!=harry spec.status.reason!=\"failed reson\" -jane johnny type!=pod type!=replicaset namespace!=\"a,b,c\"")
Expect(err).To(BeNil())
Expand Down
8 changes: 3 additions & 5 deletions query/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,9 @@ func GetModelFromTable(table string) (QueryModel, error) {
}
}

var (
// QueryModel.Apply will ignore these fields when converting to clauses
// as we modify the tx directly for them
ignoreFieldsForClauses = []string{"sort", "offset", "limit", "labels", "config", "tags"}
)
// QueryModel.Apply will ignore these fields when converting to clauses
// as we modify the tx directly for them
var ignoreFieldsForClauses = []string{"sort", "offset", "limit", "labels", "config", "tags"}

func (qm QueryModel) Apply(ctx context.Context, q types.QueryField, tx *gorm.DB) (*gorm.DB, []clause.Expression, error) {
if tx == nil {
Expand Down
16 changes: 7 additions & 9 deletions types/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@ const (
ComponentStatusInfo ComponentStatus = "info"
)

var (
ComponentStatusOrder = map[ComponentStatus]int{
ComponentStatusInfo: 0,
ComponentStatusHealthy: 1,
ComponentStatusUnhealthy: 2,
ComponentStatusWarning: 3,
ComponentStatusError: 4,
}
)
var ComponentStatusOrder = map[ComponentStatus]int{
ComponentStatusInfo: 0,
ComponentStatusHealthy: 1,
ComponentStatusUnhealthy: 2,
ComponentStatusWarning: 3,
ComponentStatusError: 4,
}

func (status ComponentStatus) Compare(other ComponentStatus) int {
if status == other {
Expand Down
12 changes: 8 additions & 4 deletions types/envvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ func (e *EnvVar) Scan(value any) error {
},
Key: strings.Split(v, "/")[3],
},
}}
},
}
return nil
}

Expand All @@ -192,7 +193,8 @@ func (e *EnvVar) Scan(value any) error {
},
Key: strings.Split(v, "/")[3],
},
}}
},
}
return nil
}

Expand All @@ -208,7 +210,8 @@ func (e *EnvVar) Scan(value any) error {
},
Key: strings.Split(v, "/")[3],
},
}}
},
}
return nil
}

Expand All @@ -220,7 +223,8 @@ func (e *EnvVar) Scan(value any) error {
*e = EnvVar{
ValueFrom: &EnvVarSource{
ServiceAccount: &segments[2],
}}
},
}
return nil
}

Expand Down
Loading

0 comments on commit 6ddd15c

Please sign in to comment.