Skip to content

Commit

Permalink
Update generator tests to passing
Browse files Browse the repository at this point in the history
  • Loading branch information
smarterclayton committed Jul 30, 2015
1 parent 0f9fdca commit 532e1ca
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
18 changes: 12 additions & 6 deletions pkg/runtime/conversion_generation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,37 @@ import (
"io"
"io/ioutil"
"os"
"path"
"testing"

"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/testapi"
_ "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"

"github.com/golang/glog"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
)

func generateConversions(t *testing.T, version string) bytes.Buffer {
g := runtime.NewConversionGenerator(api.Scheme.Raw())
g := runtime.NewConversionGenerator(api.Scheme.Raw(), path.Join("github.com/GoogleCloudPlatform/kubernetes/pkg/api", version))
apiShort := g.AddImport("github.com/GoogleCloudPlatform/kubernetes/pkg/api")
g.AddImport("github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource")
// TODO(wojtek-t): Change the overwrites to a flag.
g.OverwritePackage(version, "")
for _, knownType := range api.Scheme.KnownTypes(version) {
if err := g.GenerateConversionsForType(version, knownType); err != nil {
glog.Errorf("error while generating conversion functions for %v: %v", knownType, err)
t.Fatalf("error while generating conversion functions for %v: %v", knownType, err)
}
}

g.RepackImports(util.NewStringSet())
var functions bytes.Buffer
functionsWriter := bufio.NewWriter(&functions)
if err := g.WriteImports(functionsWriter); err != nil {
t.Fatalf("error while writing imports: %v", err)
}
if err := g.WriteConversionFunctions(functionsWriter); err != nil {
t.Fatalf("couldn't generate conversion functions: %v", err)
}
if err := g.RegisterConversionFunctions(functionsWriter); err != nil {
if err := g.RegisterConversionFunctions(functionsWriter, fmt.Sprintf("%s.Scheme", apiShort)); err != nil {
t.Fatalf("couldn't generate conversion function names: %v", err)
}
if err := functionsWriter.Flush(); err != nil {
Expand Down
18 changes: 13 additions & 5 deletions pkg/runtime/deep_copy_generation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,30 @@ import (
"fmt"
"io/ioutil"
"os"
"path"
"testing"

"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/testapi"
_ "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"

"github.com/golang/glog"
)

func generateDeepCopies(t *testing.T, version string) bytes.Buffer {
g := runtime.NewDeepCopyGenerator(api.Scheme.Raw())
g.OverwritePackage(version, "")
testedVersion := version
if version == "api" {
registerTo := "api.Scheme"
if testedVersion == "api" {
testedVersion = api.Scheme.Raw().InternalVersion
registerTo = "Scheme"
}

g := runtime.NewDeepCopyGenerator(api.Scheme.Raw(), path.Join("github.com/GoogleCloudPlatform/kubernetes/pkg/api", testedVersion), util.NewStringSet("github.com/GoogleCloudPlatform/kubernetes"))
g.AddImport("github.com/GoogleCloudPlatform/kubernetes/pkg/api")
g.OverwritePackage(version, "")

for _, knownType := range api.Scheme.KnownTypes(testedVersion) {
if err := g.AddType(knownType); err != nil {
glog.Errorf("error while generating deep-copy functions for %v: %v", knownType, err)
Expand All @@ -47,13 +54,14 @@ func generateDeepCopies(t *testing.T, version string) bytes.Buffer {

var functions bytes.Buffer
functionsWriter := bufio.NewWriter(&functions)
if err := g.WriteImports(functionsWriter, version); err != nil {
g.RepackImports()
if err := g.WriteImports(functionsWriter); err != nil {
t.Fatalf("couldn't generate deep-copy function imports: %v", err)
}
if err := g.WriteDeepCopyFunctions(functionsWriter); err != nil {
t.Fatalf("couldn't generate deep-copy functions: %v", err)
}
if err := g.RegisterDeepCopyFunctions(functionsWriter, version); err != nil {
if err := g.RegisterDeepCopyFunctions(functionsWriter, registerTo); err != nil {
t.Fatalf("couldn't generate deep-copy function names: %v", err)
}
if err := functionsWriter.Flush(); err != nil {
Expand Down

0 comments on commit 532e1ca

Please sign in to comment.