Skip to content

Commit

Permalink
Refactor examples_test.walkJSONFiles
Browse files Browse the repository at this point in the history
  • Loading branch information
tmrts committed Mar 14, 2015
1 parent efcde72 commit 1799736
Showing 1 changed file with 13 additions and 15 deletions.
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

0 comments on commit 1799736

Please sign in to comment.