Move predicates and unstructpath to path
And rename unstructpath to selectors, since the package only contains selectors now. The name of types in the selectors package could be improved now that the package name is more specific.
This commit is contained in:
parent
3c97ce6d61
commit
81e47da354
|
|
@ -19,7 +19,7 @@ package predicates_test
|
|||
import (
|
||||
"testing"
|
||||
|
||||
. "k8s.io/kubectl/pkg/framework/predicates"
|
||||
. "k8s.io/kubectl/pkg/framework/path/predicates"
|
||||
)
|
||||
|
||||
type InterfaceTrue struct{}
|
||||
|
|
@ -19,7 +19,7 @@ package predicates_test
|
|||
import (
|
||||
"testing"
|
||||
|
||||
. "k8s.io/kubectl/pkg/framework/predicates"
|
||||
. "k8s.io/kubectl/pkg/framework/path/predicates"
|
||||
)
|
||||
|
||||
type MapTrue struct{}
|
||||
|
|
@ -20,7 +20,7 @@ import (
|
|||
"fmt"
|
||||
"testing"
|
||||
|
||||
. "k8s.io/kubectl/pkg/framework/predicates"
|
||||
. "k8s.io/kubectl/pkg/framework/path/predicates"
|
||||
)
|
||||
|
||||
// This example shows you how you can create a IntP, and how it's use to
|
||||
|
|
@ -19,7 +19,7 @@ package predicates_test
|
|||
import (
|
||||
"testing"
|
||||
|
||||
. "k8s.io/kubectl/pkg/framework/predicates"
|
||||
. "k8s.io/kubectl/pkg/framework/path/predicates"
|
||||
)
|
||||
|
||||
type SliceTrue struct{}
|
||||
|
|
@ -20,7 +20,7 @@ import (
|
|||
"regexp"
|
||||
"testing"
|
||||
|
||||
. "k8s.io/kubectl/pkg/framework/predicates"
|
||||
. "k8s.io/kubectl/pkg/framework/path/predicates"
|
||||
)
|
||||
|
||||
func TestStringEqual(t *testing.T) {
|
||||
|
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
// This package helps you find specific fields in your unstruct
|
||||
// This package helps you find specific fields in your interface{}
|
||||
// object. It is similar to what you can do with jsonpath, but reads the
|
||||
// path from strongly typed object, not strings.
|
||||
package unstructpath
|
||||
package selectors
|
||||
|
|
@ -14,12 +14,12 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
package unstructpath
|
||||
package selectors
|
||||
|
||||
import (
|
||||
"github.com/ghodss/yaml"
|
||||
|
||||
p "k8s.io/kubectl/pkg/framework/predicates"
|
||||
p "k8s.io/kubectl/pkg/framework/path/predicates"
|
||||
)
|
||||
|
||||
// This example is inspired from http://goessner.net/articles/JsonPath/#e3.
|
||||
|
|
@ -14,10 +14,10 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
package unstructpath
|
||||
package selectors
|
||||
|
||||
import (
|
||||
p "k8s.io/kubectl/pkg/framework/predicates"
|
||||
p "k8s.io/kubectl/pkg/framework/path/predicates"
|
||||
)
|
||||
|
||||
// A interfaceFilter allows us to chain InterfaceS to InterfaceS. None of this is
|
||||
|
|
@ -14,10 +14,10 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
package unstructpath
|
||||
package selectors
|
||||
|
||||
import (
|
||||
p "k8s.io/kubectl/pkg/framework/predicates"
|
||||
p "k8s.io/kubectl/pkg/framework/path/predicates"
|
||||
)
|
||||
|
||||
// InterfaceS is a "interface selector". It filters interfaces based on the
|
||||
|
|
@ -14,13 +14,13 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
package unstructpath_test
|
||||
package selectors_test
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"k8s.io/kubectl/pkg/framework/unstructpath"
|
||||
"k8s.io/kubectl/pkg/framework/path/selectors"
|
||||
)
|
||||
|
||||
func TestAll(t *testing.T) {
|
||||
|
|
@ -30,7 +30,7 @@ func TestAll(t *testing.T) {
|
|||
"key4": map[string]interface{}{"key5": 5.},
|
||||
}
|
||||
|
||||
numbers := unstructpath.All().Number().SelectFrom(u)
|
||||
numbers := selectors.All().Number().SelectFrom(u)
|
||||
expected := []float64{1., 2., 3., 4., 5.}
|
||||
if !reflect.DeepEqual(expected, numbers) {
|
||||
t.Fatalf("Expected to find all numbers (%v), got: %v", expected, numbers)
|
||||
|
|
@ -44,7 +44,7 @@ func TestChildren(t *testing.T) {
|
|||
"key4": 5.,
|
||||
}
|
||||
|
||||
numbers := unstructpath.Children().Number().SelectFrom(u)
|
||||
numbers := selectors.Children().Number().SelectFrom(u)
|
||||
expected := []float64{1., 5.}
|
||||
if !reflect.DeepEqual(expected, numbers) {
|
||||
t.Fatalf("Expected to find all numbers (%v), got: %v", expected, numbers)
|
||||
|
|
@ -60,14 +60,14 @@ func TestFilter(t *testing.T) {
|
|||
"string",
|
||||
}
|
||||
expected := []interface{}{us[1]}
|
||||
actual := unstructpath.Filter(unstructpath.Slice().At(3)).SelectFrom(us...)
|
||||
actual := selectors.Filter(selectors.Slice().At(3)).SelectFrom(us...)
|
||||
if !reflect.DeepEqual(expected, actual) {
|
||||
t.Fatalf("Expected to filter (%v), got: %v", expected, actual)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInterfaceSPredicate(t *testing.T) {
|
||||
if !unstructpath.Slice().Match([]interface{}{}) {
|
||||
if !selectors.Slice().Match([]interface{}{}) {
|
||||
t.Fatal("SelectFroming a slice from a slice should match.")
|
||||
}
|
||||
}
|
||||
|
|
@ -92,7 +92,7 @@ func TestInterfaceSMap(t *testing.T) {
|
|||
root,
|
||||
root["key4"].(map[string]interface{}),
|
||||
}
|
||||
actual := unstructpath.All().Map().SelectFrom(root)
|
||||
actual := selectors.All().Map().SelectFrom(root)
|
||||
if !reflect.DeepEqual(expected, actual) {
|
||||
t.Fatalf("Map should find maps %v, got %v", expected, actual)
|
||||
}
|
||||
|
|
@ -118,7 +118,7 @@ func TestInterfaceSSlice(t *testing.T) {
|
|||
root["key3"].([]interface{}),
|
||||
root["key4"].(map[string]interface{})["subkey"].([]interface{}),
|
||||
}
|
||||
actual := unstructpath.All().Slice().SelectFrom(root)
|
||||
actual := selectors.All().Slice().SelectFrom(root)
|
||||
if !reflect.DeepEqual(expected, actual) {
|
||||
t.Fatalf("Slice should find slices %#v, got %#v", expected, actual)
|
||||
}
|
||||
|
|
@ -144,7 +144,7 @@ func TestInterfaceSChildren(t *testing.T) {
|
|||
root["key3"].([]interface{})[0],
|
||||
root["key3"].([]interface{})[1],
|
||||
}
|
||||
actual := unstructpath.Map().Field("key3").Children().SelectFrom(root)
|
||||
actual := selectors.Map().Field("key3").Children().SelectFrom(root)
|
||||
if !reflect.DeepEqual(expected, actual) {
|
||||
t.Fatalf("Expected %v, got %v", expected, actual)
|
||||
}
|
||||
|
|
@ -153,7 +153,7 @@ func TestInterfaceSChildren(t *testing.T) {
|
|||
func TestInterfaceSNumber(t *testing.T) {
|
||||
u := []interface{}{1., 2., "three", 4., 5., []interface{}{}}
|
||||
|
||||
numbers := unstructpath.Children().Number().SelectFrom(u)
|
||||
numbers := selectors.Children().Number().SelectFrom(u)
|
||||
expected := []float64{1., 2., 4., 5.}
|
||||
if !reflect.DeepEqual(expected, numbers) {
|
||||
t.Fatalf("Children().Number() should select %v, got %v", expected, numbers)
|
||||
|
|
@ -182,7 +182,7 @@ func TestInterfaceSString(t *testing.T) {
|
|||
"other value",
|
||||
"string",
|
||||
}
|
||||
actual := unstructpath.All().String().SelectFrom(root)
|
||||
actual := selectors.All().String().SelectFrom(root)
|
||||
if !reflect.DeepEqual(expected, actual) {
|
||||
t.Fatalf("Expected %v, got %v", expected, actual)
|
||||
}
|
||||
|
|
@ -211,7 +211,7 @@ func TestInterfaceSAll(t *testing.T) {
|
|||
root["key4"].(map[string]interface{})["subkey"].([]interface{})[1],
|
||||
}
|
||||
|
||||
actual := unstructpath.Map().Field("key4").All().SelectFrom(root)
|
||||
actual := selectors.Map().Field("key4").All().SelectFrom(root)
|
||||
if !reflect.DeepEqual(expected, actual) {
|
||||
t.Fatalf("Expected %v, got %v", expected, actual)
|
||||
}
|
||||
|
|
@ -14,12 +14,12 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
package unstructpath
|
||||
package selectors
|
||||
|
||||
import (
|
||||
"sort"
|
||||
|
||||
p "k8s.io/kubectl/pkg/framework/predicates"
|
||||
p "k8s.io/kubectl/pkg/framework/path/predicates"
|
||||
)
|
||||
|
||||
// This is a Map-to-Interface filter.
|
||||
|
|
@ -14,10 +14,10 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
package unstructpath
|
||||
package selectors
|
||||
|
||||
import (
|
||||
p "k8s.io/kubectl/pkg/framework/predicates"
|
||||
p "k8s.io/kubectl/pkg/framework/path/predicates"
|
||||
)
|
||||
|
||||
// MapS is a "map selector". It selects interfaces as maps (if
|
||||
|
|
@ -14,10 +14,10 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
package unstructpath
|
||||
package selectors
|
||||
|
||||
import (
|
||||
p "k8s.io/kubectl/pkg/framework/predicates"
|
||||
p "k8s.io/kubectl/pkg/framework/path/predicates"
|
||||
)
|
||||
|
||||
// NumberS is a "number selector". It selects values as numbers (if
|
||||
|
|
@ -14,14 +14,14 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
package unstructpath_test
|
||||
package selectors_test
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
p "k8s.io/kubectl/pkg/framework/predicates"
|
||||
. "k8s.io/kubectl/pkg/framework/unstructpath"
|
||||
p "k8s.io/kubectl/pkg/framework/path/predicates"
|
||||
. "k8s.io/kubectl/pkg/framework/path/selectors"
|
||||
)
|
||||
|
||||
func TestNumberSSelectFrom(t *testing.T) {
|
||||
|
|
@ -14,10 +14,10 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
package unstructpath
|
||||
package selectors
|
||||
|
||||
import (
|
||||
p "k8s.io/kubectl/pkg/framework/predicates"
|
||||
p "k8s.io/kubectl/pkg/framework/path/predicates"
|
||||
)
|
||||
|
||||
func filterSlice(ss SliceS, sf sliceFilter) InterfaceS {
|
||||
|
|
@ -14,10 +14,10 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
package unstructpath
|
||||
package selectors
|
||||
|
||||
import (
|
||||
p "k8s.io/kubectl/pkg/framework/predicates"
|
||||
p "k8s.io/kubectl/pkg/framework/path/predicates"
|
||||
)
|
||||
|
||||
// SliceS is a "slice selector". It selects values as slices (if
|
||||
|
|
@ -14,10 +14,10 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
package unstructpath
|
||||
package selectors
|
||||
|
||||
import (
|
||||
p "k8s.io/kubectl/pkg/framework/predicates"
|
||||
p "k8s.io/kubectl/pkg/framework/path/predicates"
|
||||
)
|
||||
|
||||
// StringS is a "string selector". It selects values as strings (if
|
||||
|
|
@ -14,14 +14,14 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
package unstructpath_test
|
||||
package selectors_test
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
p "k8s.io/kubectl/pkg/framework/predicates"
|
||||
. "k8s.io/kubectl/pkg/framework/unstructpath"
|
||||
p "k8s.io/kubectl/pkg/framework/path/predicates"
|
||||
. "k8s.io/kubectl/pkg/framework/path/selectors"
|
||||
)
|
||||
|
||||
func TestStringSSelectFrom(t *testing.T) {
|
||||
Loading…
Reference in New Issue