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:
Antoine Pelisse 2018-03-19 10:53:04 -07:00
parent 3c97ce6d61
commit 81e47da354
23 changed files with 43 additions and 43 deletions

View File

@ -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{}

View File

@ -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{}

View File

@ -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

View File

@ -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{}

View File

@ -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) {

View File

@ -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

View File

@ -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.

View File

@ -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

View File

@ -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

View File

@ -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)
}

View File

@ -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.

View File

@ -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

View File

@ -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

View File

@ -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) {

View File

@ -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 {

View File

@ -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

View File

@ -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

View File

@ -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) {