Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Commit

Permalink
expose artifact createdAt time (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
chanadian authored Feb 20, 2020
1 parent cd77548 commit 5d28ea3
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 94 deletions.
13 changes: 13 additions & 0 deletions pkg/manager/impl/artifact_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package impl
import (
"context"
"testing"
"time"

"fmt"

"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/ptypes"
"github.com/lyft/datacatalog/pkg/common"
"github.com/lyft/datacatalog/pkg/errors"
"github.com/lyft/datacatalog/pkg/repositories/mocks"
Expand Down Expand Up @@ -48,6 +50,11 @@ func getTestStringLiteral() *core.Literal {
}
}

func getTestTimestamp() time.Time {
timestamp, _ := time.Parse(time.RFC3339, "2019-12-26T00:00:00+00:00")
return timestamp
}

func getTestArtifact() *datacatalog.Artifact {
datasetID := &datacatalog.DatasetID{
Project: "test-project",
Expand All @@ -56,6 +63,8 @@ func getTestArtifact() *datacatalog.Artifact {
Version: "test-version",
UUID: "test-uuid",
}
createdAt, _ := ptypes.TimestampProto(getTestTimestamp())

return &datacatalog.Artifact{
Id: "test-id",
Dataset: datasetID,
Expand All @@ -75,6 +84,7 @@ func getTestArtifact() *datacatalog.Artifact {
Tags: []*datacatalog.Tag{
{Name: "test-tag", Dataset: datasetID, ArtifactId: "test-id"},
},
CreatedAt: createdAt,
}
}

Expand Down Expand Up @@ -134,6 +144,9 @@ func getExpectedArtifactModel(ctx context.Context, t *testing.T, datastore *stor
Tags: []models.Tag{
{TagKey: models.TagKey{TagName: "test-tag"}, DatasetUUID: expectedDataset.UUID, ArtifactID: artifact.Id},
},
BaseModel: models.BaseModel{
CreatedAt: getTestTimestamp(),
},
}
}

Expand Down
10 changes: 10 additions & 0 deletions pkg/repositories/transformers/artifact.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package transformers

import (
"github.com/golang/protobuf/ptypes"
"github.com/lyft/datacatalog/pkg/errors"
"github.com/lyft/datacatalog/pkg/repositories/models"
datacatalog "github.com/lyft/datacatalog/protos/gen"
"google.golang.org/grpc/codes"
)

func CreateArtifactModel(request datacatalog.CreateArtifactRequest, artifactData []models.ArtifactData, dataset models.Dataset) (models.Artifact, error) {
Expand Down Expand Up @@ -63,12 +66,19 @@ func FromArtifactModel(artifact models.Artifact) (datacatalog.Artifact, error) {
for i, tag := range artifact.Tags {
tags[i] = FromTagModel(datasetID, tag)
}

createdAt, err := ptypes.TimestampProto(artifact.CreatedAt)
if err != nil {
return datacatalog.Artifact{}, errors.NewDataCatalogErrorf(codes.Internal,
"artifact [%+v] invalid createdAt time conversion", artifact)
}
return datacatalog.Artifact{
Id: artifact.ArtifactID,
Dataset: &datasetID,
Metadata: metadata,
Partitions: partitions,
Tags: tags,
CreatedAt: createdAt,
}, nil
}

Expand Down
12 changes: 12 additions & 0 deletions pkg/repositories/transformers/artifact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package transformers
import (
"testing"

"time"

"github.com/golang/protobuf/ptypes"
"github.com/lyft/datacatalog/pkg/repositories/models"
datacatalog "github.com/lyft/datacatalog/protos/gen"
"github.com/lyft/flyteidl/gen/pb-go/flyteidl/core"
Expand Down Expand Up @@ -101,6 +104,8 @@ func TestCreateArtifactModelNoMetdata(t *testing.T) {
}

func TestFromArtifactModel(t *testing.T) {
createdAt := time.Now()

artifactModel := models.Artifact{
ArtifactKey: models.ArtifactKey{
DatasetProject: "project1",
Expand All @@ -112,6 +117,9 @@ func TestFromArtifactModel(t *testing.T) {
SerializedMetadata: []byte{},
Partitions: getTestPartitions(),
Tags: getTestTags(),
BaseModel: models.BaseModel{
CreatedAt: createdAt,
},
}

actual, err := FromArtifactModel(artifactModel)
Expand All @@ -130,6 +138,10 @@ func TestFromArtifactModel(t *testing.T) {

assert.Len(t, actual.Tags, 1)
assert.EqualValues(t, artifactModel.Tags[0].TagName, actual.Tags[0].Name)

timestampProto, err := ptypes.TimestampProto(createdAt)
assert.NoError(t, err)
assert.Equal(t, actual.CreatedAt, timestampProto)
}

func TestToArtifactKey(t *testing.T) {
Expand Down
Loading

0 comments on commit 5d28ea3

Please sign in to comment.