Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor examples_test.walkJSONFiles #5469

Merged
merged 1 commit into from
Mar 16, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 13 additions & 15 deletions examples/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"os"
"path/filepath"
"regexp"
"strings"
"testing"

"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
Expand Down Expand Up @@ -70,30 +71,27 @@ func validateObject(obj runtime.Object) (errors []error) {
}

func walkJSONFiles(inDir string, fn func(name, path string, data []byte)) error {
err := filepath.Walk(inDir, func(path string, info os.FileInfo, err error) error {
return filepath.Walk(inDir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}

if info.IsDir() && path != inDir {
return filepath.SkipDir
}
name := filepath.Base(path)
ext := filepath.Ext(name)
if ext != "" {
name = name[:len(name)-len(ext)]
}
if !(ext == ".json" || ext == ".yaml") {
return nil
}
glog.Infof("Testing %s", path)
data, err := ioutil.ReadFile(path)
if err != nil {
return err

file := filepath.Base(path)
if ext := filepath.Ext(file); ext == ".json" || ext == ".yaml" {
glog.Infof("Testing %s", path)
data, err := ioutil.ReadFile(path)
if err != nil {
return err
}
name := strings.TrimSuffix(file, ext)
fn(name, path, data)
}
fn(name, path, data)
return nil
})
return err
}

func TestExampleObjectSchemas(t *testing.T) {
Expand Down