Skip to content

Commit

Permalink
todos
Browse files Browse the repository at this point in the history
Signed-off-by: Pavel Okhlopkov <[email protected]>
  • Loading branch information
Pavel Okhlopkov committed Nov 2, 2024
1 parent bdd089e commit 67b0557
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 51 deletions.
2 changes: 2 additions & 0 deletions test/utils/directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
utils_file "github.com/flant/shell-operator/pkg/utils/file"
)

// TODO: remove useless code

// ChooseExistedDirectoryPath returns first non-empty existed directory path from arguments.
//
// Each argument is prefixed with current directory if is not started with /
Expand Down
104 changes: 53 additions & 51 deletions test/utils/jqmatcher.go
Original file line number Diff line number Diff line change
@@ -1,66 +1,68 @@
//go:build test
// +build test

// TODO: remove useless code

package utils

import (
"encoding/json"
"fmt"
// import (
// "encoding/json"
// "fmt"

"github.com/onsi/gomega/matchers"
"github.com/onsi/gomega/types"
// "github.com/onsi/gomega/matchers"
// "github.com/onsi/gomega/types"

. "github.com/flant/libjq-go"
)
// . "github.com/flant/libjq-go"
// )

// var _ = Ω(verBcs).To(MatchJq(`.[0] | has("objects")`, Equal(true)))
func MatchJq(jqExpression string, matcher interface{}) types.GomegaMatcher {
return &matchJq{
JqExpr: jqExpression,
Matcher: matcher,
}
}
// // var _ = Ω(verBcs).To(MatchJq(`.[0] | has("objects")`, Equal(true)))
// func MatchJq(jqExpression string, matcher interface{}) types.GomegaMatcher {
// return &matchJq{
// JqExpr: jqExpression,
// Matcher: matcher,
// }
// }

type matchJq struct {
JqExpr string
InputString string
Matcher interface{}
ResMatcher types.GomegaMatcher
}
// type matchJq struct {
// JqExpr string
// InputString string
// Matcher interface{}
// ResMatcher types.GomegaMatcher
// }

func (matcher *matchJq) Match(actual interface{}) (success bool, err error) {
switch v := actual.(type) {
case string:
matcher.InputString = v
case []byte:
matcher.InputString = string(v)
default:
inputBytes, err := json.Marshal(v)
if err != nil {
return false, fmt.Errorf("MatchJq marshal object to json: %s\n", err)
}
matcher.InputString = string(inputBytes)
}
// func (matcher *matchJq) Match(actual interface{}) (success bool, err error) {
// switch v := actual.(type) {
// case string:
// matcher.InputString = v
// case []byte:
// matcher.InputString = string(v)
// default:
// inputBytes, err := json.Marshal(v)
// if err != nil {
// return false, fmt.Errorf("MatchJq marshal object to json: %s\n", err)
// }
// matcher.InputString = string(inputBytes)
// }

//nolint:typecheck // Ignore false positive: undeclared name: `Jq`.
res, err := Jq().Program(matcher.JqExpr).Run(matcher.InputString)
if err != nil {
return false, fmt.Errorf("MatchJq apply jq expression: %s\n", err)
}
// //nolint:typecheck // Ignore false positive: undeclared name: `Jq`.
// res, err := Jq().Program(matcher.JqExpr).Run(matcher.InputString)
// if err != nil {
// return false, fmt.Errorf("MatchJq apply jq expression: %s\n", err)
// }

var isMatcher bool
matcher.ResMatcher, isMatcher = matcher.Matcher.(types.GomegaMatcher)
if !isMatcher {
matcher.ResMatcher = &matchers.EqualMatcher{Expected: res}
}
// var isMatcher bool
// matcher.ResMatcher, isMatcher = matcher.Matcher.(types.GomegaMatcher)
// if !isMatcher {
// matcher.ResMatcher = &matchers.EqualMatcher{Expected: res}
// }

return matcher.ResMatcher.Match(res)
}
// return matcher.ResMatcher.Match(res)
// }

func (matcher *matchJq) FailureMessage(actual interface{}) (message string) {
return fmt.Sprintf("Jq expression `%s` applied to '%s' not match: %v", matcher.JqExpr, matcher.InputString, matcher.ResMatcher.FailureMessage(actual))
}
// func (matcher *matchJq) FailureMessage(actual interface{}) (message string) {
// return fmt.Sprintf("Jq expression `%s` applied to '%s' not match: %v", matcher.JqExpr, matcher.InputString, matcher.ResMatcher.FailureMessage(actual))
// }

func (matcher *matchJq) NegatedFailureMessage(actual interface{}) (message string) {
return fmt.Sprintf("Jq expression `%s` applied to '%s' should not match: %s", matcher.JqExpr, matcher.InputString, matcher.ResMatcher.NegatedFailureMessage(actual))
}
// func (matcher *matchJq) NegatedFailureMessage(actual interface{}) (message string) {
// return fmt.Sprintf("Jq expression `%s` applied to '%s' should not match: %s", matcher.JqExpr, matcher.InputString, matcher.ResMatcher.NegatedFailureMessage(actual))
// }
2 changes: 2 additions & 0 deletions test/utils/kubectl.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//go:build test
// +build test

// TODO: remove useless code

package utils

import (
Expand Down
2 changes: 2 additions & 0 deletions test/utils/shell-operator.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//go:build test
// +build test

// TODO: remove useless code

package utils

import (
Expand Down
2 changes: 2 additions & 0 deletions test/utils/streamedexec.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//go:build test
// +build test

// TODO: remove useless code

package utils

import (
Expand Down

0 comments on commit 67b0557

Please sign in to comment.