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

Config test backfill #697

Merged
merged 6 commits into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions helpers/config/config_struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,10 @@ func validateCredHubSettings(config *config) error {
}

func validateVolumeServices(config *config) error {
if config.IncludeVolumeServices == nil {
return nil
}

if !config.GetIncludeVolumeServices() {
ctlong marked this conversation as resolved.
Show resolved Hide resolved
return nil
}
Expand Down
187 changes: 167 additions & 20 deletions helpers/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,7 @@ type requiredConfig struct {

type testConfig struct {
// required
ApiEndpoint *string `json:"api"`
AdminUser *string `json:"admin_user"`
AdminPassword *string `json:"admin_password"`
SkipSSLValidation *bool `json:"skip_ssl_validation"`
AppsDomain *string `json:"apps_domain"`
UseHttp *bool `json:"use_http,omitempty"`
requiredConfig

// timeouts
DefaultTimeout *int `json:"default_timeout,omitempty"`
Expand All @@ -43,38 +38,70 @@ type testConfig struct {
TimeoutScale *float64 `json:"timeout_scale,omitempty"`

// optional
IncludePrivateDockerRegistry *bool `json:"include_private_docker_registry,omitempty"`
PrivateDockerRegistryImage *string `json:"private_docker_registry_image,omitempty"`
PrivateDockerRegistryUsername *string `json:"private_docker_registry_username,omitempty"`
PrivateDockerRegistryPassword *string `json:"private_docker_registry_password,omitempty"`
PublicDockerAppImage *string `json:"public_docker_app_image,omitempty"`

IncludeIsolationSegments *bool `json:"include_isolation_segments,omitempty"`
IncludeRoutingIsolationSegments *bool `json:"include_routing_isolation_segments,omitempty"`
IsolationSegmentName *string `json:"isolation_segment_name,omitempty"`
IsolationSegmentDomain *string `json:"isolation_segment_domain,omitempty"`
IsolationSegmentName *string `json:"isolation_segment_name,omitempty"`
IsolationSegmentDomain *string `json:"isolation_segment_domain,omitempty"`

UnallocatedIPForSecurityGroup *string `json:"unallocated_ip_for_security_group"`
RequireProxiedAppTraffic *bool `json:"require_proxied_app_traffic"`

IncludeWindows *bool `json:"include_windows,omitempty"`
UseWindowsTestTask *bool `json:"use_windows_test_task,omitempty"`
UseWindowsContextPath *bool `json:"use_windows_context_path,omitempty"`
WindowsStack *string `json:"windows_stack,omitempty"`

IncludeServiceDiscovery *bool `json:"include_service_discovery,omitempty"`

IncludeHTTP2Routing *bool `json:"include_http2_routing,omitempty"`
IncludeTCPRouting *bool `json:"include_tcp_routing,omitempty"`

ReporterConfig *testReporterConfig `json:"reporter_config"`

Stacks *[]string `json:"stacks,omitempty"`

Infrastructure *string `json:"infrastructure"`

VolumeServiceName *string `json:"volume_service_name,omitempty"`
VolumeServicePlanName *string `json:"volume_service_plan_name,omitempty"`

IncludeAppSyslogTcp *bool `json:"include_app_syslog_tcp,omitempty"`
IncludeApps *bool `json:"include_apps,omitempty"`
IncludeContainerNetworking *bool `json:"include_container_networking,omitempty"`
IncludeDeployments *bool `json:"include_deployments,omitempty"`
IncludeDetect *bool `json:"include_detect,omitempty"`
IncludeDocker *bool `json:"include_docker,omitempty"`
IncludeInternetDependent *bool `json:"include_internet_dependent,omitempty"`
IncludeIsolationSegments *bool `json:"include_isolation_segments,omitempty"`
IncludePrivateDockerRegistry *bool `json:"include_private_docker_registry,omitempty"`
IncludeRouteServices *bool `json:"include_route_services,omitempty"`
IncludeRouting *bool `json:"include_routing,omitempty"`
IncludeRoutingIsolationSegments *bool `json:"include_routing_isolation_segments,omitempty"`
IncludeSSO *bool `json:"include_sso,omitempty"`
IncludeSecurityGroups *bool `json:"include_security_groups,omitempty"`
IncludeServiceDiscovery *bool `json:"include_service_discovery,omitempty"`
IncludeServiceInstanceSharing *bool `json:"include_service_instance_sharing,omitempty"`
IncludeServices *bool `json:"include_services,omitempty"`
IncludeUserProvidedServices *bool `json:"include_user_provided_services,omitempty"`
IncludeSsh *bool `json:"include_ssh,omitempty"`
IncludeTCPIsolationSegments *bool `json:"include_tcp_isolation_segments,omitempty"`
IncludeHTTP2Routing *bool `json:"include_http2_routing,omitempty"`
IncludeTCPRouting *bool `json:"include_tcp_routing,omitempty"`
IncludeTasks *bool `json:"include_tasks,omitempty"`
IncludeV3 *bool `json:"include_v3,omitempty"`
IncludeVolumeServices *bool `json:"include_volume_services,omitempty"`
IncludeZipkin *bool `json:"include_zipkin,omitempty"`
IncludeWindows *bool `json:"include_windows,omitempty"`

BinaryBuildpackName *string `json:"binary_buildpack_name,omitempty"`
GoBuildpackName *string `json:"go_buildpack_name,omitempty"`
HwcBuildpackName *string `json:"hwc_buildpack_name,omitempty"`
JavaBuildpackName *string `json:"java_buildpack_name,omitempty"`
NginxBuildpackName *string `json:"nginx_buildpack_name,omitempty"`
NodejsBuildpackName *string `json:"nodejs_buildpack_name,omitempty"`
RBuildpackName *string `json:"r_buildpack_name,omitempty"`
RubyBuildpackName *string `json:"ruby_buildpack_name,omitempty"`
StaticFileBuildpackName *string `json:"staticfile_buildpack_name,omitempty"`
}

type allConfig struct {
type nullConfig struct {
ApiEndpoint *string `json:"api"`
AppsDomain *string `json:"apps_domain"`
UseHttp *bool `json:"use_http"`
Expand Down Expand Up @@ -146,6 +173,9 @@ type allConfig struct {
IncludeHTTP2Routing *bool `json:"include_http2_routing"`
IncludeTCPRouting *bool `json:"include_tcp_routing"`
IncludeServiceDiscovery *bool `json:"include_service_discovery"`
IncludeVolumeServices *bool `json:"include_volume_services"`
IncludeTCPIsolationSegments *bool `json:"include_tcp_isolation_segments"`
IncludeAppSyslogTcp *bool `json:"include_app_syslog_tcp"`

CredhubMode *string `json:"credhub_mode"`
CredhubLocation *string `json:"credhub_location"`
Expand All @@ -162,6 +192,11 @@ type allConfig struct {
Stacks *[]string `json:"stacks"`

Infrastructure *string `json:"infrastructure"`

UnallocatedIPForSecurityGroup *string `json:"unallocated_ip_for_security_group"`
RequireProxiedAppTraffic *bool `json:"require_proxied_app_traffic"`
UseWindowsContextPath *bool `json:"use_windows_context_path"`
UseWindowsTestTask *bool `json:"use_windows_test_task"`
}

type testReporterConfig struct {
Expand Down Expand Up @@ -212,6 +247,7 @@ var _ = Describe("Config", func() {
testCfg.AdminPassword = ptrToString("admin")
testCfg.SkipSSLValidation = ptrToBool(true)
testCfg.AppsDomain = ptrToString("cf-app.bosh-lite.com")
testCfg.UseHttp = ptrToBool(false)
testCfg.Infrastructure = ptrToString("vms")
})

Expand Down Expand Up @@ -242,6 +278,7 @@ var _ = Describe("Config", func() {

Expect(config.GetIncludeAppSyslogTcp()).To(BeTrue())
Expect(config.GetIncludeApps()).To(BeTrue())
Expect(config.GetIncludeDeployments()).To(BeFalse())
Expect(config.GetIncludeDetect()).To(BeTrue())
Expect(config.GetIncludeRouting()).To(BeTrue())
Expect(config.GetIncludeV3()).To(BeTrue())
Expand All @@ -251,11 +288,13 @@ var _ = Describe("Config", func() {
Expect(config.GetIncludeRouteServices()).To(BeFalse())
Expect(config.GetIncludeContainerNetworking()).To(BeFalse())
Expect(config.GetIncludeSecurityGroups()).To(BeFalse())
Expect(config.GetIncludeServiceDiscovery()).To(BeFalse())
Expect(config.GetIncludeServices()).To(BeFalse())
Expect(config.GetIncludeUserProvidedServices()).To(BeFalse())
Expect(config.GetIncludeSsh()).To(BeFalse())
Expect(config.GetIncludeIsolationSegments()).To(BeFalse())
Expect(config.GetIncludeRoutingIsolationSegments()).To(BeFalse())
Expect(config.GetIncludeTCPIsolationSegments()).To(BeFalse())
Expect(config.GetIncludePrivateDockerRegistry()).To(BeFalse())
Expect(config.GetIncludeZipkin()).To(BeFalse())
Expect(config.GetIncludeSSO()).To(BeFalse())
Expand All @@ -265,6 +304,7 @@ var _ = Describe("Config", func() {
Expect(config.GetIncludeServiceInstanceSharing()).To(BeFalse())
Expect(config.GetIncludeHTTP2Routing()).To(BeFalse())
Expect(config.GetIncludeTCPRouting()).To(BeFalse())
Expect(config.GetIncludeVolumeServices()).To(BeFalse())

Expect(config.GetIncludeWindows()).To(BeFalse())
Expect(config.GetUseWindowsTestTask()).To(BeFalse())
Expand Down Expand Up @@ -317,12 +357,22 @@ var _ = Describe("Config", func() {
Expect(config.GetStacks()).To(ConsistOf("cflinuxfs3"))

Expect(config.RunningOnK8s()).To(BeFalse(), "RunningOnK8s should be false")

Expect(config.GetBinaryBuildpackName()).To(Equal("binary_buildpack"))
Expect(config.GetGoBuildpackName()).To(Equal("go_buildpack"))
Expect(config.GetHwcBuildpackName()).To(Equal("hwc_buildpack"))
Expect(config.GetJavaBuildpackName()).To(Equal("java_buildpack"))
Expect(config.GetNginxBuildpackName()).To(Equal("nginx_buildpack"))
Expect(config.GetNodejsBuildpackName()).To(Equal("nodejs_buildpack"))
Expect(config.GetRBuildpackName()).To(Equal("r_buildpack"))
Expect(config.GetRubyBuildpackName()).To(Equal("ruby_buildpack"))
Expect(config.GetStaticFileBuildpackName()).To(Equal("staticfile_buildpack"))
})

Context("when all values are null", func() {
It("returns an error", func() {
allCfgFilePath := writeConfigFile(&allConfig{})
_, err := cfg.NewCatsConfig(allCfgFilePath)
nullConfigFilePath := writeConfigFile(&nullConfig{})
_, err := cfg.NewCatsConfig(nullConfigFilePath)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("'api' must not be null"))
Expect(err.Error()).To(ContainSubstring("'apps_domain' must not be null"))
Expand Down Expand Up @@ -387,8 +437,11 @@ var _ = Describe("Config", func() {
Expect(err.Error()).To(ContainSubstring("'include_zipkin' must not be null"))
Expect(err.Error()).To(ContainSubstring("'include_isolation_segments' must not be null"))
Expect(err.Error()).To(ContainSubstring("'include_routing_isolation_segments' must not be null"))
Expect(err.Error()).To(ContainSubstring("'include_tcp_isolation_segments' must not be null"))
Expect(err.Error()).To(ContainSubstring("'include_windows' must not be null"))
Expect(err.Error()).To(ContainSubstring("'include_service_discovery' must not be null"))
Expect(err.Error()).To(ContainSubstring("'include_app_syslog_tcp' must not be null"))
Expect(err.Error()).To(ContainSubstring("'public_docker_app_image' must not be null"))
Expect(err.Error()).To(ContainSubstring("'private_docker_registry_image' must not be null"))
Expect(err.Error()).To(ContainSubstring("'private_docker_registry_username' must not be null"))
Expect(err.Error()).To(ContainSubstring("'private_docker_registry_password' must not be null"))
Expand All @@ -398,6 +451,15 @@ var _ = Describe("Config", func() {
Expect(err.Error()).To(ContainSubstring("'stacks' must not be null"))

Expect(err.Error()).To(ContainSubstring("'infrastructure' must not be null"))

// These values are allowed to be null
Expect(err.Error()).NotTo(ContainSubstring("unallocated_ip_for_security_group"))
Expect(err.Error()).NotTo(ContainSubstring("require_proxied_app_traffic"))
Expect(err.Error()).NotTo(ContainSubstring("use_windows_context_path"))
Expect(err.Error()).NotTo(ContainSubstring("reporter_config"))
Expect(err.Error()).NotTo(ContainSubstring("use_windows_test_task"))
Expect(err.Error()).NotTo(ContainSubstring("include_volume_services"))
Expect(err.Error()).NotTo(ContainSubstring("include_deployments"))
})
})

Expand All @@ -414,6 +476,53 @@ var _ = Describe("Config", func() {
testCfg.UnallocatedIPForSecurityGroup = ptrToString("192.168.0.1")
testCfg.RequireProxiedAppTraffic = ptrToBool(true)
testCfg.Infrastructure = ptrToString("kubernetes")

testCfg.IncludeAppSyslogTcp = ptrToBool(false)
testCfg.IncludeApps = ptrToBool(false)
testCfg.IncludeContainerNetworking = ptrToBool(true)
testCfg.IncludeDeployments = ptrToBool(true)
testCfg.IncludeDetect = ptrToBool(false)
testCfg.IncludeDocker = ptrToBool(true)
testCfg.IncludeInternetDependent = ptrToBool(true)
testCfg.IncludeIsolationSegments = ptrToBool(true)
testCfg.IncludePrivateDockerRegistry = ptrToBool(true)
testCfg.IncludeRouteServices = ptrToBool(true)
testCfg.IncludeRouting = ptrToBool(false)
testCfg.IncludeRoutingIsolationSegments = ptrToBool(true)
testCfg.IncludeSSO = ptrToBool(true)
testCfg.IncludeSecurityGroups = ptrToBool(true)
testCfg.IncludeServiceDiscovery = ptrToBool(true)
testCfg.IncludeServiceInstanceSharing = ptrToBool(true)
testCfg.IncludeServices = ptrToBool(true)
testCfg.IncludeUserProvidedServices = ptrToBool(true)
testCfg.IncludeSsh = ptrToBool(true)
testCfg.IncludeTCPIsolationSegments = ptrToBool(true)
testCfg.IncludeHTTP2Routing = ptrToBool(true)
testCfg.IncludeTCPRouting = ptrToBool(true)
testCfg.IncludeTasks = ptrToBool(true)
testCfg.IncludeV3 = ptrToBool(false)
testCfg.IncludeVolumeServices = ptrToBool(true)
testCfg.IncludeZipkin = ptrToBool(true)
testCfg.IncludeWindows = ptrToBool(true)

testCfg.BinaryBuildpackName = ptrToString("binary_buildpack_override")
testCfg.GoBuildpackName = ptrToString("go_buildpack_override")
testCfg.HwcBuildpackName = ptrToString("hwc_buildpack_override")
testCfg.JavaBuildpackName = ptrToString("java_buildpack_override")
testCfg.NginxBuildpackName = ptrToString("nginx_buildpack_override")
testCfg.NodejsBuildpackName = ptrToString("nodejs_buildpack_override")
testCfg.RBuildpackName = ptrToString("r_buildpack_override")
testCfg.RubyBuildpackName = ptrToString("ruby_buildpack_override")
testCfg.StaticFileBuildpackName = ptrToString("staticfile_buildpack_override")

// These values are set so as not to trigger validation errors associated with the overrides provided above
testCfg.PrivateDockerRegistryImage = ptrToString("avoid-validation-errors-by-setting-dummy-value")
testCfg.PrivateDockerRegistryUsername = ptrToString("avoid-validation-errors-by-setting-dummy-value")
testCfg.PrivateDockerRegistryPassword = ptrToString("avoid-validation-errors-by-setting-dummy-value")
testCfg.IsolationSegmentName = ptrToString("avoid-validation-errors-by-setting-dummy-value")
testCfg.IsolationSegmentDomain = ptrToString("avoid-validation-errors-by-setting-dummy-value")
testCfg.VolumeServiceName = ptrToString("avoid-validation-errors-by-setting-dummy-value")
testCfg.VolumeServicePlanName = ptrToString("avoid-validation-errors-by-setting-dummy-value")
})

It("respects the overriden values", func() {
Expand All @@ -431,6 +540,44 @@ var _ = Describe("Config", func() {
Expect(config.GetUnallocatedIPForSecurityGroup()).To(Equal("192.168.0.1"))
Expect(config.GetRequireProxiedAppTraffic()).To(BeTrue())
Expect(config.RunningOnK8s()).To(BeTrue(), "RunningOnK8s should be true")

Expect(config.GetIncludeAppSyslogTcp()).To(BeFalse())
Expect(config.GetIncludeApps()).To(BeFalse())
Expect(config.GetIncludeContainerNetworking()).To(BeTrue())
Expect(config.GetIncludeDeployments()).To(BeTrue())
Expect(config.GetIncludeDetect()).To(BeFalse())
Expect(config.GetIncludeDocker()).To(BeTrue())
Expect(config.GetIncludeInternetDependent()).To(BeTrue())
Expect(config.GetIncludeIsolationSegments()).To(BeTrue())
Expect(config.GetIncludePrivateDockerRegistry()).To(BeTrue())
Expect(config.GetIncludeRouteServices()).To(BeTrue())
Expect(config.GetIncludeRouting()).To(BeFalse())
Expect(config.GetIncludeRoutingIsolationSegments()).To(BeTrue())
Expect(config.GetIncludeSSO()).To(BeTrue())
Expect(config.GetIncludeSecurityGroups()).To(BeTrue())
Expect(config.GetIncludeServiceDiscovery()).To(BeTrue())
Expect(config.GetIncludeServiceInstanceSharing()).To(BeTrue())
Expect(config.GetIncludeServices()).To(BeTrue())
Expect(config.GetIncludeUserProvidedServices()).To(BeTrue())
Expect(config.GetIncludeSsh()).To(BeTrue())
Expect(config.GetIncludeTCPIsolationSegments()).To(BeTrue())
Expect(config.GetIncludeHTTP2Routing()).To(BeTrue())
Expect(config.GetIncludeTCPRouting()).To(BeTrue())
Expect(config.GetIncludeTasks()).To(BeTrue())
Expect(config.GetIncludeV3()).To(BeFalse())
Expect(config.GetIncludeVolumeServices()).To(BeTrue())
Expect(config.GetIncludeZipkin()).To(BeTrue())
Expect(config.GetIncludeWindows()).To(BeTrue())

Expect(config.GetBinaryBuildpackName()).To(Equal("binary_buildpack_override"))
Expect(config.GetGoBuildpackName()).To(Equal("go_buildpack_override"))
Expect(config.GetHwcBuildpackName()).To(Equal("hwc_buildpack_override"))
Expect(config.GetJavaBuildpackName()).To(Equal("java_buildpack_override"))
Expect(config.GetNginxBuildpackName()).To(Equal("nginx_buildpack_override"))
Expect(config.GetNodejsBuildpackName()).To(Equal("nodejs_buildpack_override"))
Expect(config.GetRBuildpackName()).To(Equal("r_buildpack_override"))
Expect(config.GetRubyBuildpackName()).To(Equal("ruby_buildpack_override"))
Expect(config.GetStaticFileBuildpackName()).To(Equal("staticfile_buildpack_override"))
})
})

Expand Down