From 8f6b701bb09a550eac9d86ce33500c2cd77b2d68 Mon Sep 17 00:00:00 2001 From: Yash Bhardwaj Date: Fri, 6 Dec 2024 15:21:59 +0530 Subject: [PATCH] fix : tests to add deprication info in resource table --- client/local/model/resource_spec.go | 2 +- core/resource/resource.go | 5 +-- .../postgres/resource/repository_test.go | 42 +++++++++---------- tests/bench/resource/resource_repo_test.go | 14 +++---- 4 files changed, 30 insertions(+), 33 deletions(-) diff --git a/client/local/model/resource_spec.go b/client/local/model/resource_spec.go index 41a522a862..db767adc90 100644 --- a/client/local/model/resource_spec.go +++ b/client/local/model/resource_spec.go @@ -36,7 +36,7 @@ func (r ResourceSpec) ToProto() (*pb.ResourceSpecification, error) { if r.Deprecation != nil && len(r.Deprecation.Date) > 0 { deprecationDate, err := time.Parse(time.DateOnly, r.Deprecation.Date) if err != nil { - return nil, fmt.Errorf("error parsing deprication Date, for resource: %s, expected_format: [YYYY-MM-DD], got: [%s], err: %w", r.Name, r.Deprecation.Date, err) + return nil, fmt.Errorf("error parsing deprivation Date, for resource: %s, expected_format: [YYYY-MM-DD], got: [%s], err: %w", r.Name, r.Deprecation.Date, err) } deprecation = &pb.Deprecation{ Reason: r.Deprecation.Reason, diff --git a/core/resource/resource.go b/core/resource/resource.go index 74b51ae9b5..9350055f2b 100644 --- a/core/resource/resource.go +++ b/core/resource/resource.go @@ -110,10 +110,7 @@ type Resource struct { } func (r *Resource) IsDeprecated() bool { - if r.deprecation != nil { - return true - } - return false + return r.deprecation != nil } func (r *Resource) GetUpdateImpact(incoming *Resource) UpdateImpact { diff --git a/internal/store/postgres/resource/repository_test.go b/internal/store/postgres/resource/repository_test.go index 6fe66e8f9f..1d6bb54be6 100644 --- a/internal/store/postgres/resource/repository_test.go +++ b/internal/store/postgres/resource/repository_test.go @@ -42,7 +42,7 @@ func TestPostgresResourceRepository(t *testing.T) { pool := dbSetup() repository := repoResource.NewRepository(pool) - resourceToCreate, err := serviceResource.NewResource("project.dataset", kindDataset, store, tnnt, meta, spec) + resourceToCreate, err := serviceResource.NewResource("project.dataset", kindDataset, store, tnnt, meta, spec, nil) assert.NoError(t, err) resourceToCreate.UpdateURN(resourceURN) @@ -56,7 +56,7 @@ func TestPostgresResourceRepository(t *testing.T) { pool := dbSetup() repository := repoResource.NewRepository(pool) - resourceToCreate, err := serviceResource.NewResource("project.dataset", kindDataset, store, tnnt, meta, spec) + resourceToCreate, err := serviceResource.NewResource("project.dataset", kindDataset, store, tnnt, meta, spec, nil) assert.NoError(t, err) resourceURN, err := serviceResource.ParseURN("bigquery://project:dataset") assert.NoError(t, err) @@ -77,7 +77,7 @@ func TestPostgresResourceRepository(t *testing.T) { pool := dbSetup() repository := repoResource.NewRepository(pool) - resourceToUpdate, err := serviceResource.NewResource("project.dataset", kindDataset, store, tnnt, meta, spec) + resourceToUpdate, err := serviceResource.NewResource("project.dataset", kindDataset, store, tnnt, meta, spec, nil) assert.NoError(t, err) resourceToUpdate.UpdateURN(resourceURN) @@ -89,7 +89,7 @@ func TestPostgresResourceRepository(t *testing.T) { pool := dbSetup() repository := repoResource.NewRepository(pool) - resourceToCreate, err := serviceResource.NewResource("project.dataset", kindDataset, store, tnnt, meta, spec) + resourceToCreate, err := serviceResource.NewResource("project.dataset", kindDataset, store, tnnt, meta, spec, nil) assert.NoError(t, err) resourceToCreate.UpdateURN(resourceURN) @@ -115,7 +115,7 @@ func TestPostgresResourceRepository(t *testing.T) { pool := dbSetup() repository := repoResource.NewRepository(pool) - resourceToUpdate, err := serviceResource.NewResource("project.dataset", kindDataset, store, tnnt, meta, spec) + resourceToUpdate, err := serviceResource.NewResource("project.dataset", kindDataset, store, tnnt, meta, spec, nil) assert.NoError(t, err) resourceToUpdate.UpdateURN(resourceURN) @@ -127,7 +127,7 @@ func TestPostgresResourceRepository(t *testing.T) { pool := dbSetup() repository := repoResource.NewRepository(pool) - resourceToCreate, err := serviceResource.NewResource("project.dataset", kindDataset, store, tnnt, meta, spec) + resourceToCreate, err := serviceResource.NewResource("project.dataset", kindDataset, store, tnnt, meta, spec, nil) assert.NoError(t, err) resourceToCreate.UpdateURN(resourceURN) @@ -153,13 +153,13 @@ func TestPostgresResourceRepository(t *testing.T) { urn, err := serviceResource.ParseURN("bigquery://project:dataset") assert.NoError(t, err) - resourceExisting, err := serviceResource.NewResource("project.dataset", kindDataset, store, tnnt, meta, spec) + resourceExisting, err := serviceResource.NewResource("project.dataset", kindDataset, store, tnnt, meta, spec, nil) assert.NoError(t, err) resourceExisting.UpdateURN(urn) otherTnnt, err := tenant.NewTenant(tnnt.ProjectName().String(), "n-optimus-2") assert.NoError(t, err) - resourceToChange, err := serviceResource.NewResource("project.dataset", kindDataset, store, otherTnnt, meta, spec) + resourceToChange, err := serviceResource.NewResource("project.dataset", kindDataset, store, otherTnnt, meta, spec, nil) assert.NoError(t, err) resourceToChange.UpdateURN(urn) @@ -194,7 +194,7 @@ func TestPostgresResourceRepository(t *testing.T) { repository := repoResource.NewRepository(pool) fullName := "project.dataset" - resourceToCreate, err := serviceResource.NewResource(fullName, kindDataset, store, tnnt, meta, spec) + resourceToCreate, err := serviceResource.NewResource(fullName, kindDataset, store, tnnt, meta, spec, nil) assert.NoError(t, err) err = repository.Create(ctx, resourceToCreate) @@ -221,7 +221,7 @@ func TestPostgresResourceRepository(t *testing.T) { pool := dbSetup() repository := repoResource.NewRepository(pool) - resourceToCreate, err := serviceResource.NewResource("project.dataset", kindDataset, store, tnnt, meta, spec) + resourceToCreate, err := serviceResource.NewResource("project.dataset", kindDataset, store, tnnt, meta, spec, nil) assert.NoError(t, err) err = repository.Create(ctx, resourceToCreate) @@ -240,7 +240,7 @@ func TestPostgresResourceRepository(t *testing.T) { repository := repoResource.NewRepository(pool) name1 := "project.dataset" - resourceToCreate1, err := serviceResource.NewResource(name1, kindDataset, store, tnnt, meta, spec) + resourceToCreate1, err := serviceResource.NewResource(name1, kindDataset, store, tnnt, meta, spec, nil) assert.NoError(t, err) resourceURN, err := serviceResource.ParseURN("bigquery://project:dataset1") assert.NoError(t, err) @@ -253,7 +253,7 @@ func TestPostgresResourceRepository(t *testing.T) { "view_query": "select * from `project.dataset.table`", } name2 := "project.dataset.view" - resourceToCreate2, err := serviceResource.NewResource(name2, "view", store, tnnt, meta, viewSpec) + resourceToCreate2, err := serviceResource.NewResource(name2, "view", store, tnnt, meta, viewSpec, nil) assert.NoError(t, err) resourceURN, err = serviceResource.ParseURN("bigquery://project:dataset.view") assert.NoError(t, err) @@ -274,11 +274,11 @@ func TestPostgresResourceRepository(t *testing.T) { pool := dbSetup() repository := repoResource.NewRepository(pool) - existingResource, err := serviceResource.NewResource("project.dataset1", kindDataset, store, tnnt, meta, spec) + existingResource, err := serviceResource.NewResource("project.dataset1", kindDataset, store, tnnt, meta, spec, nil) assert.NoError(t, err) err = repository.Create(ctx, existingResource) assert.NoError(t, err) - nonExistingResource, err := serviceResource.NewResource("project.dataset2", kindDataset, store, tnnt, meta, spec) + nonExistingResource, err := serviceResource.NewResource("project.dataset2", kindDataset, store, tnnt, meta, spec, nil) assert.NoError(t, err) resourcesToUpdate := []*serviceResource.Resource{ @@ -299,12 +299,12 @@ func TestPostgresResourceRepository(t *testing.T) { pool := dbSetup() repository := repoResource.NewRepository(pool) - existingResource1, err := serviceResource.NewResource("project.dataset1", kindDataset, store, tnnt, meta, spec) + existingResource1, err := serviceResource.NewResource("project.dataset1", kindDataset, store, tnnt, meta, spec, nil) assert.NoError(t, err) resourceURN, err := serviceResource.ParseURN("bigquery://project:dataset1") assert.NoError(t, err) existingResource1.UpdateURN(resourceURN) - existingResource2, err := serviceResource.NewResource("project.dataset2", kindDataset, store, tnnt, meta, spec) + existingResource2, err := serviceResource.NewResource("project.dataset2", kindDataset, store, tnnt, meta, spec, nil) assert.NoError(t, err) resourceURN, err = serviceResource.ParseURN("bigquery://project:dataset2") assert.NoError(t, err) @@ -317,10 +317,10 @@ func TestPostgresResourceRepository(t *testing.T) { newSpec := map[string]any{ "Description": "spec for testing update status", } - modifiedResource1, err := serviceResource.NewResource("project.dataset1", kindDataset, store, tnnt, meta, newSpec) + modifiedResource1, err := serviceResource.NewResource("project.dataset1", kindDataset, store, tnnt, meta, newSpec, nil) assert.NoError(t, err) modifiedResource1.MarkExistInStore() - modifiedResource2, err := serviceResource.NewResource("project.dataset2", kindDataset, store, tnnt, meta, newSpec) + modifiedResource2, err := serviceResource.NewResource("project.dataset2", kindDataset, store, tnnt, meta, newSpec, nil) assert.NoError(t, err) resourcesToUpdate := []*serviceResource.Resource{ serviceResource.FromExisting(modifiedResource1, serviceResource.ReplaceStatus(serviceResource.StatusSuccess)), @@ -344,7 +344,7 @@ func TestPostgresResourceRepository(t *testing.T) { pool := dbSetup() repository := repoResource.NewRepository(pool) - resourceToDelete, err := serviceResource.NewResource("project.dataset", kindDataset, store, tnnt, meta, spec) + resourceToDelete, err := serviceResource.NewResource("project.dataset", kindDataset, store, tnnt, meta, spec, nil) assert.NoError(t, err) _ = resourceToDelete.MarkToDelete() @@ -359,7 +359,7 @@ func TestPostgresResourceRepository(t *testing.T) { urn, err := serviceResource.ParseURN("bigquery://project:dataset") assert.NoError(t, err) - resourceToCreate, err := serviceResource.NewResource("project.dataset", kindDataset, store, tnnt, meta, spec) + resourceToCreate, err := serviceResource.NewResource("project.dataset", kindDataset, store, tnnt, meta, spec, nil) assert.NoError(t, err) resourceToCreate.UpdateURN(urn) @@ -434,7 +434,7 @@ func TestPostgresResourceRepository(t *testing.T) { urn, err := serviceResource.ParseURN("bigquery://project:dataset.table") assert.NoError(t, err) - resourceToCreate, err := serviceResource.NewResource("project.dataset.table", kindDataset, store, tnnt, meta, spec) + resourceToCreate, err := serviceResource.NewResource("project.dataset.table", kindDataset, store, tnnt, meta, spec, nil) assert.NoError(t, err) err = resourceToCreate.UpdateURN(urn) assert.NoError(t, err) diff --git a/tests/bench/resource/resource_repo_test.go b/tests/bench/resource/resource_repo_test.go index 7c4646a44b..d8821b0fc6 100644 --- a/tests/bench/resource/resource_repo_test.go +++ b/tests/bench/resource/resource_repo_test.go @@ -81,7 +81,7 @@ func BenchmarkResourceRepository(b *testing.B) { for i := 0; i < b.N; i++ { fullName := fmt.Sprintf("project.dataset_%d", i) - resourceToCreate, err := serviceResource.NewResource(fullName, bigquery.KindDataset, serviceResource.Bigquery, tnnt, meta, spec) + resourceToCreate, err := serviceResource.NewResource(fullName, bigquery.KindDataset, serviceResource.Bigquery, tnnt, meta, spec, nil) assert.NoError(b, err) name := fmt.Sprintf("%s:%s.%s", projectName, namespaceName, fullName) @@ -101,7 +101,7 @@ func BenchmarkResourceRepository(b *testing.B) { fullNames := make([]string, maxNumberOfResources) for i := 0; i < maxNumberOfResources; i++ { fullName := fmt.Sprintf("project.dataset_%d", i) - resourceToCreate, err := serviceResource.NewResource(fullName, bigquery.KindDataset, serviceResource.Bigquery, tnnt, meta, spec) + resourceToCreate, err := serviceResource.NewResource(fullName, bigquery.KindDataset, serviceResource.Bigquery, tnnt, meta, spec, nil) assert.NoError(b, err) name := fmt.Sprintf("%s:%s.%s", projectName, namespaceName, fullName) @@ -128,7 +128,7 @@ func BenchmarkResourceRepository(b *testing.B) { resourceIdx := i % maxNumberOfResources fullName := fullNames[resourceIdx] - resourceToUpdate, err := serviceResource.NewResource(fullName, bigquery.KindDataset, serviceResource.Bigquery, tnnt, updatedMeta, spec) + resourceToUpdate, err := serviceResource.NewResource(fullName, bigquery.KindDataset, serviceResource.Bigquery, tnnt, updatedMeta, spec, nil) assert.NoError(b, err) name := fmt.Sprintf("%s:%s.%s", projectName, namespaceName, fullName) @@ -157,7 +157,7 @@ func BenchmarkResourceRepository(b *testing.B) { fullNames := make([]string, maxNumberOfResources) for i := 0; i < maxNumberOfResources; i++ { fullName := fmt.Sprintf("project.dataset_%d", i) - resourceToCreate, err := serviceResource.NewResource(fullName, bigquery.KindDataset, serviceResource.Bigquery, tnnt, meta, spec) + resourceToCreate, err := serviceResource.NewResource(fullName, bigquery.KindDataset, serviceResource.Bigquery, tnnt, meta, spec, nil) assert.NoError(b, err) name := fmt.Sprintf("%s:%s.%s", projectName, namespaceName, fullName) @@ -190,7 +190,7 @@ func BenchmarkResourceRepository(b *testing.B) { repository := repoResource.NewRepository(db) for i := 0; i < maxNumberOfResources; i++ { fullName := fmt.Sprintf("project.dataset_%d", i) - resourceToCreate, err := serviceResource.NewResource(fullName, bigquery.KindDataset, serviceResource.Bigquery, tnnt, meta, spec) + resourceToCreate, err := serviceResource.NewResource(fullName, bigquery.KindDataset, serviceResource.Bigquery, tnnt, meta, spec, nil) assert.NoError(b, err) name := fmt.Sprintf("%s:%s.%s", projectName, namespaceName, fullName) @@ -218,7 +218,7 @@ func BenchmarkResourceRepository(b *testing.B) { fullNames := make([]string, maxNumberOfResources) for i := 0; i < maxNumberOfResources; i++ { fullName := fmt.Sprintf("project.dataset_%d", i) - resourceToCreate, err := serviceResource.NewResource(fullName, bigquery.KindDataset, serviceResource.Bigquery, tnnt, meta, spec) + resourceToCreate, err := serviceResource.NewResource(fullName, bigquery.KindDataset, serviceResource.Bigquery, tnnt, meta, spec, nil) assert.NoError(b, err) name := fmt.Sprintf("%s:%s.%s", projectName, namespaceName, fullName) @@ -248,7 +248,7 @@ func BenchmarkResourceRepository(b *testing.B) { resources := make([]*serviceResource.Resource, maxNumberOfResources) for i := 0; i < maxNumberOfResources; i++ { fullName := fmt.Sprintf("project.dataset_%d", i) - resourceToCreate, err := serviceResource.NewResource(fullName, bigquery.KindDataset, serviceResource.Bigquery, tnnt, meta, spec) + resourceToCreate, err := serviceResource.NewResource(fullName, bigquery.KindDataset, serviceResource.Bigquery, tnnt, meta, spec, nil) assert.NoError(b, err) name := fmt.Sprintf("%s:%s.%s", projectName, namespaceName, fullName)