Skip to content

Commit

Permalink
fix : tests to add deprication info in resource table
Browse files Browse the repository at this point in the history
  • Loading branch information
Mryashbhardwaj committed Dec 6, 2024
1 parent 20b0133 commit 8f6b701
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 33 deletions.
2 changes: 1 addition & 1 deletion client/local/model/resource_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 1 addition & 4 deletions core/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
42 changes: 21 additions & 21 deletions internal/store/postgres/resource/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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{
Expand All @@ -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)
Expand All @@ -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)),
Expand All @@ -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()

Expand All @@ -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)

Expand Down Expand Up @@ -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)
Expand Down
14 changes: 7 additions & 7 deletions tests/bench/resource/resource_repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 8f6b701

Please sign in to comment.