Skip to content

Commit

Permalink
Merge pull request #785 from spencerhance/composite-updates
Browse files Browse the repository at this point in the history
Composite updates for integration
  • Loading branch information
k8s-ci-robot authored Jun 27, 2019
2 parents 1a4ff08 + 5062f56 commit f15a1f4
Show file tree
Hide file tree
Showing 9 changed files with 1,745 additions and 201 deletions.
8 changes: 4 additions & 4 deletions pkg/backends/backends.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (b *Backends) Create(sp utils.ServicePort, hcLink string) (*composite.Backe
HealthChecks: []string{hcLink},
}
ensureDescription(be, &sp)
if err := composite.CreateBackendService(be, b.cloud, meta.GlobalKey(be.Name)); err != nil {
if err := composite.CreateBackendService(b.cloud, meta.GlobalKey(be.Name), be); err != nil {
return nil, err
}
// Note: We need to perform a GCE call to re-fetch the object we just created
Expand All @@ -87,15 +87,15 @@ func (b *Backends) Create(sp utils.ServicePort, hcLink string) (*composite.Backe
func (b *Backends) Update(be *composite.BackendService) error {
// Ensure the backend service has the proper version before updating.
be.Version = features.VersionFromDescription(be.Description)
if err := composite.UpdateBackendService(be, b.cloud, meta.GlobalKey(be.Name)); err != nil {
if err := composite.UpdateBackendService(b.cloud, meta.GlobalKey(be.Name), be); err != nil {
return err
}
return nil
}

// Get implements Pool.
func (b *Backends) Get(name string, version meta.Version) (*composite.BackendService, error) {
be, err := composite.GetBackendService(version, b.cloud, meta.GlobalKey(name))
be, err := composite.GetBackendService(b.cloud, meta.GlobalKey(name), version)
if err != nil {
return nil, err
}
Expand All @@ -104,7 +104,7 @@ func (b *Backends) Get(name string, version meta.Version) (*composite.BackendSer
// the existing backend service.
versionRequired := features.VersionFromDescription(be.Description)
if features.IsLowerVersion(versionRequired, version) {
be, err = composite.GetBackendService(versionRequired, b.cloud, meta.GlobalKey(name))
be, err = composite.GetBackendService(b.cloud, meta.GlobalKey(name), versionRequired)
if err != nil {
return nil, err
}
Expand Down
1,062 changes: 947 additions & 115 deletions pkg/composite/composite.go

Large diffs are not rendered by default.

115 changes: 115 additions & 0 deletions pkg/composite/composite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,121 @@ func TestServiceAccountJwtAccessCredentials(t *testing.T) {
t.Fatal(err)
}
}
func TestSslCertificate(t *testing.T) {
// Use reflection to verify that our composite type contains all the
// same fields as the alpha type.
compositeType := reflect.TypeOf(SslCertificate{})
alphaType := reflect.TypeOf(computealpha.SslCertificate{})
betaType := reflect.TypeOf(computebeta.SslCertificate{})
gaType := reflect.TypeOf(compute.SslCertificate{})

// For the composite type, remove the Version field from consideration
compositeTypeNumFields := compositeType.NumField() - 2
if compositeTypeNumFields != alphaType.NumField() {
t.Fatalf("%v should contain %v fields. Got %v", alphaType.Name(), alphaType.NumField(), compositeTypeNumFields)
}

// Compare all the fields by doing a lookup since we can't guarantee that they'll be in the same order
// Make sure that composite type is strictly alpha fields + internal bookkeeping
for i := 2; i < compositeType.NumField(); i++ {
lookupField, found := alphaType.FieldByName(compositeType.Field(i).Name)
if !found {
t.Fatal(fmt.Errorf("Field %v not present in alpha type %v", compositeType.Field(i), alphaType))
}
if err := compareFields(compositeType.Field(i), lookupField); err != nil {
t.Fatal(err)
}
}

// Verify that all beta fields are in composite type
if err := typeEquality(betaType, compositeType, false); err != nil {
t.Fatal(err)
}

// Verify that all GA fields are in composite type
if err := typeEquality(gaType, compositeType, false); err != nil {
t.Fatal(err)
}
}

func TestToSslCertificate(t *testing.T) {
testCases := []struct {
input interface{}
expected *SslCertificate
}{
{
computealpha.SslCertificate{},
&SslCertificate{},
},
{
computebeta.SslCertificate{},
&SslCertificate{},
},
{
compute.SslCertificate{},
&SslCertificate{},
},
}
for _, testCase := range testCases {
result, _ := ToSslCertificate(testCase.input)
if !reflect.DeepEqual(result, testCase.expected) {
t.Fatalf("ToSslCertificate(input) = \ninput = %s\n%s\nwant = \n%s", pretty.Sprint(testCase.input), pretty.Sprint(result), pretty.Sprint(testCase.expected))
}
}
}

func TestSslCertificateToAlpha(t *testing.T) {
composite := SslCertificate{}
expected := &computealpha.SslCertificate{}
result, err := composite.ToAlpha()
if err != nil {
t.Fatalf("SslCertificate.ToAlpha() error: %v", err)
}

if !reflect.DeepEqual(result, expected) {
t.Fatalf("SslCertificate.ToAlpha() = \ninput = %s\n%s\nwant = \n%s", pretty.Sprint(composite), pretty.Sprint(result), pretty.Sprint(expected))
}
}
func TestSslCertificateToBeta(t *testing.T) {
composite := SslCertificate{}
expected := &computebeta.SslCertificate{}
result, err := composite.ToBeta()
if err != nil {
t.Fatalf("SslCertificate.ToBeta() error: %v", err)
}

if !reflect.DeepEqual(result, expected) {
t.Fatalf("SslCertificate.ToBeta() = \ninput = %s\n%s\nwant = \n%s", pretty.Sprint(composite), pretty.Sprint(result), pretty.Sprint(expected))
}
}
func TestSslCertificateToGA(t *testing.T) {
composite := SslCertificate{}
expected := &compute.SslCertificate{}
result, err := composite.ToGA()
if err != nil {
t.Fatalf("SslCertificate.ToGA() error: %v", err)
}

if !reflect.DeepEqual(result, expected) {
t.Fatalf("SslCertificate.ToGA() = \ninput = %s\n%s\nwant = \n%s", pretty.Sprint(composite), pretty.Sprint(result), pretty.Sprint(expected))
}
}

func TestSslCertificateManagedSslCertificate(t *testing.T) {
compositeType := reflect.TypeOf(SslCertificateManagedSslCertificate{})
alphaType := reflect.TypeOf(computealpha.SslCertificateManagedSslCertificate{})
if err := typeEquality(compositeType, alphaType, true); err != nil {
t.Fatal(err)
}
}

func TestSslCertificateSelfManagedSslCertificate(t *testing.T) {
compositeType := reflect.TypeOf(SslCertificateSelfManagedSslCertificate{})
alphaType := reflect.TypeOf(computealpha.SslCertificateSelfManagedSslCertificate{})
if err := typeEquality(compositeType, alphaType, true); err != nil {
t.Fatal(err)
}
}

func TestTCPHealthCheck(t *testing.T) {
compositeType := reflect.TypeOf(TCPHealthCheck{})
Expand Down
Loading

0 comments on commit f15a1f4

Please sign in to comment.