Skip to content

Commit

Permalink
fix tests for GCP cloud config, make output useful
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Jones committed May 11, 2019
1 parent 122d0b1 commit 0394cc1
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 242 deletions.
140 changes: 54 additions & 86 deletions bosh/internal/boshcli/gcp_test.go
Original file line number Diff line number Diff line change
@@ -1,105 +1,73 @@
package boshcli

import (
"fmt"
"github.com/EngineerBetter/control-tower/resource"
"github.com/onsi/gomega/format"
"io/ioutil"
"testing"
"text/template"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

func TestGCPEnvironment_ConfigureDirectorCloudConfig(t *testing.T) {
func getFixture(filename string) string {
contents, _ := ioutil.ReadFile(filename)
return string(contents)
}

fullTemplateParams := GCPEnvironment{
Zone: "zone",
PublicSubnetwork: "public_subnetwork",
PrivateSubnetwork: "private_subnetwork",
Spot: false,
Network: "network",
PublicCIDR: "public_cidr",
PublicCIDRGateway: "public_cidr_gateway",
PublicCIDRStatic: "public_cidr_static",
PublicCIDRReserved: "public_cidr_reserved",
PrivateCIDR: "private_cidr",
PrivateCIDRGateway: "private_cidr_gateway",
PrivateCIDRReserved: "private_cidr_reserved",
}
var _ = Describe("GCPEnvironment", func() {
Describe("ConfigureDirectorCloudConfig", func() {
var expected string
var environment GCPEnvironment

getFixture := func(f string) string {
contents, _ := ioutil.ReadFile(f)
return string(contents)
}
BeforeEach(func() {
environment = GCPEnvironment{
Zone: "zone",
PublicSubnetwork: "public_subnetwork",
PrivateSubnetwork: "private_subnetwork",
Spot: false,
Network: "network",
PublicCIDR: "public_cidr",
PublicCIDRGateway: "public_cidr_gateway",
PublicCIDRStatic: "public_cidr_static",
PublicCIDRReserved: "public_cidr_reserved",
PrivateCIDR: "private_cidr",
PrivateCIDRGateway: "private_cidr_gateway",
PrivateCIDRReserved: "private_cidr_reserved",
}

tests := []struct {
name string
fields GCPEnvironment
want string
wantErr bool
init func(GCPEnvironment) GCPEnvironment
validate func(string, string) (bool, string)
}{
{
name: "Success- template rendered",
fields: fullTemplateParams,
want: getFixture("../fixtures/gcp_cloud_config_full.yml"),
wantErr: false,
init: func(e GCPEnvironment) GCPEnvironment {
return e
},
validate: func(a, b string) (bool, string) {
return a == b, fmt.Sprintf("basic rendering expected to work")
},
},
{
name: "Success- spot instance rendered",
fields: fullTemplateParams,
want: getFixture("../fixtures/gcp_cloud_config_spot.yml"),
wantErr: false,
init: func(e GCPEnvironment) GCPEnvironment {
n := e
n.Spot = true
return n
},
validate: func(a, b string) (bool, string) {
return a == b, fmt.Sprintf("templating failed while rendering without spots")
},
},
format.TruncatedDiff = false
})

{
name: "Success- running with no spot",
fields: fullTemplateParams,
want: getFixture("../fixtures/gcp_cloud_config_no_spot.yml"),
wantErr: false,
init: func(e GCPEnvironment) GCPEnvironment {
n := e
n.Spot = false
return n
},
validate: func(a, b string) (bool, string) {
return a == b, fmt.Sprintf("templating failed while rendering without spots")
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
e := tt.init(tt.fields)
got, err := e.ConfigureDirectorCloudConfig()
if (err != nil) != tt.wantErr {
t.Errorf("Environment.ConfigureDirectorCloudConfig()\nerror expected: %v\nreceived error: %v", tt.wantErr, err)
return
}
passed, message := tt.validate(got, tt.want)
if !passed {
t.Errorf(message)
}
Context("when spot instances are not requested", func() {
BeforeEach(func() {
expected = getFixture("../fixtures/gcp_cloud_config_no_spot.yml")
})

It("renders the expected YAML", func() {
actual, err := environment.ConfigureDirectorCloudConfig()
Expect(err).ToNot(HaveOccurred())
Expect(actual).To(Equal(expected))
})
})
}
}

Context("when spot instances are requested", func() {
BeforeEach(func() {
expected = getFixture("../fixtures/gcp_cloud_config_spot.yml")
environment.Spot = true
})

It("renders the expected YAML", func() {
actual, err := environment.ConfigureDirectorCloudConfig()
Expect(err).ToNot(HaveOccurred())
Expect(actual).To(Equal(expected))
})
})
})
})

func TestGCPEnvironment_ConfigureConcourseStemcell(t *testing.T) {
type args struct {
versions string
}
tests := []struct {
name string
want string
Expand Down
130 changes: 0 additions & 130 deletions bosh/internal/fixtures/gcp_cloud_config_full.yml

This file was deleted.

28 changes: 15 additions & 13 deletions bosh/internal/fixtures/gcp_cloud_config_no_spot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,79 +9,81 @@ vm_types:
cloud_properties:
machine_type: n1-standard-1
root_disk_size_gb: 20
root_disk_type: pd-ssd
<< : &common_properties
service_scopes: [cloud-platform]
root_disk_type: pd-ssd

- name: concourse-web-medium
cloud_properties:
machine_type: n1-standard-2
root_disk_size_gb: 20
root_disk_type: pd-ssd
<< : *common_properties

- name: concourse-web-large
cloud_properties:
machine_type: n1-standard-4
root_disk_size_gb: 20
root_disk_type: pd-ssd
<< : *common_properties

- name: concourse-web-xlarge
cloud_properties:
machine_type: n1-standard-8
root_disk_size_gb: 20
root_disk_type: pd-ssd
<< : *common_properties

- name: concourse-web-2xlarge
cloud_properties:
machine_type: n1-standard-16
root_disk_size_gb: 20
root_disk_type: pd-ssd
<< : *common_properties

- name: concourse-medium
cloud_properties:
machine_type: n1-standard-1
root_disk_size_gb: 200
root_disk_type: pd-ssd
<< : *common_properties

- name: concourse-large
cloud_properties:
machine_type: n1-standard-2
root_disk_size_gb: 200
root_disk_type: pd-ssd
<< : *common_properties

- name: concourse-xlarge
cloud_properties:
machine_type: n1-standard-4
root_disk_size_gb: 200
root_disk_type: pd-ssd
<< : *common_properties

- name: concourse-2xlarge
cloud_properties:
machine_type: n1-standard-8
root_disk_size_gb: 200
root_disk_type: pd-ssd
<< : *common_properties

- name: concourse-4xlarge
cloud_properties:
machine_type: n1-standard-16
root_disk_size_gb: 200
root_disk_type: pd-ssd
<< : *common_properties

- name: concourse-10xlarge
cloud_properties:
machine_type: n1-standard-32
root_disk_size_gb: 200
root_disk_type: pd-ssd
<< : *common_properties

- name: concourse-16xlarge
cloud_properties:
machine_type: n1-standard-64
root_disk_size_gb: 200
root_disk_type: pd-ssd
<< : *common_properties

- name: compilation
cloud_properties:
machine_type: n1-standard-2
root_disk_size_gb: 5
root_disk_type: pd-ssd
<< : *common_properties

disk_types:
- name: default
Expand Down
Loading

0 comments on commit 0394cc1

Please sign in to comment.