Skip to content

Commit

Permalink
fall through :/
Browse files Browse the repository at this point in the history
  • Loading branch information
katiewelch committed Nov 15, 2023
1 parent e9b3535 commit 7eed757
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
14 changes: 9 additions & 5 deletions sherlock/db/migrations/000062_environment_v3.up.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
alter table environments
add constraint name_valid
check (name != '' and name similar to '[a-z0-9]([-a-z0-9]*[a-z0-9])?');
check (name is not null and name != '' and name similar to '[a-z0-9]([-a-z0-9]*[a-z0-9])?');

alter table environments
add constraint owner_id_present
Expand All @@ -10,23 +10,27 @@ alter table environments
alter table environments
add constraint lifecycle_valid
check ((lifecycle = 'template' and template_environment_id is null) or
(lifecycle = 'dynamic' and template_environment_id is not null) or
(lifecycle = 'dynamic' and
template_environment_id is not null and
base is not null and base != '' and
default_cluster_id is not null and
requires_suitability is not null) or
(lifecycle = 'static' and
base != '' and
base is not null and base != '' and
default_cluster_id is not null and
requires_suitability is not null));

alter table environments
add constraint default_namespace_present
check (default_namespace != '');
check (default_namespace is not null and default_namespace != '');

alter table environments
add constraint helmfile_ref_present
check (helmfile_ref is not null and helmfile_ref != '');

alter table environments
add constraint unique_resource_prefix_present
check (unique_resource_prefix != '');
check (unique_resource_prefix is not null and unique_resource_prefix != '');

alter table environments
add constraint delete_after_valid
Expand Down
21 changes: 21 additions & 0 deletions sherlock/internal/models/environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,27 @@ func (s *modelSuite) TestEnvironmentValidationSqlDynamicLifecycle() {
s.ErrorContains(err, "violates check constraint \"lifecycle_valid\"")
}

func (s *modelSuite) TestEnvironmentValidationSqlDynamicLifecycleBase() {
s.SetSuitableTestUserForDB()
staticEnv := s.TestData.Environment_Swatomation_LongBee()
err := s.DB.Model(&staticEnv).Select("Base").Updates(&Environment{Base: ""}).Error
s.ErrorContains(err, "violates check constraint \"lifecycle_valid\"")
}

func (s *modelSuite) TestEnvironmentValidationSqlDynamicLifecycleDefaultClusterID() {
s.SetSuitableTestUserForDB()
staticEnv := s.TestData.Environment_Swatomation_DevBee()
err := s.DB.Model(&staticEnv).Select("DefaultClusterID").Updates(&Environment{DefaultClusterID: nil}).Error
s.ErrorContains(err, "violates check constraint \"lifecycle_valid\"")
}

func (s *modelSuite) TestEnvironmentValidationSqlDynamicLifecycleRequiresSuitability() {
s.SetSuitableTestUserForDB()
staticEnv := s.TestData.Environment_Swatomation_TestBee()
err := s.DB.Model(&staticEnv).Select("RequiresSuitability").Updates(&Environment{RequiresSuitability: nil}).Error
s.ErrorContains(err, "violates check constraint \"lifecycle_valid\"")
}

func (s *modelSuite) TestEnvironmentValidationSqlStaticLifecycleBase() {
s.SetSuitableTestUserForDB()
staticEnv := s.TestData.Environment_Prod()
Expand Down

0 comments on commit 7eed757

Please sign in to comment.