-
Notifications
You must be signed in to change notification settings - Fork 688
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
Return NotFound error when decks uri is empty (#642) #6228
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -170,34 +170,50 @@ func (t testMetadata) Exists() bool { | |||||
return t.exists | ||||||
} | ||||||
|
||||||
func TestCreateDownloadLink(t *testing.T) { | ||||||
type CreateDownloadLinkDependencies struct { | ||||||
dataStore *storage.DataStore | ||||||
nodeExecutionManager *mocks.NodeExecutionInterface | ||||||
taskExecutionManager *mocks.TaskExecutionInterface | ||||||
} | ||||||
|
||||||
func setupCreateDownloadLink(t *testing.T) (Service, CreateDownloadLinkDependencies) { | ||||||
dataStore := commonMocks.GetMockStorageClient() | ||||||
nodeExecutionManager := &mocks.NodeExecutionInterface{} | ||||||
nodeExecutionManager.EXPECT().GetNodeExecution(mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, request *admin.NodeExecutionGetRequest) (*admin.NodeExecution, error) { | ||||||
taskExecutionManager := &mocks.TaskExecutionInterface{} | ||||||
s, err := NewService(config.DataProxyConfig{Download: config.DataProxyDownloadConfig{MaxExpiresIn: stdlibConfig.Duration{Duration: time.Hour}}}, nodeExecutionManager, dataStore, taskExecutionManager) | ||||||
assert.NoError(t, err) | ||||||
return s, CreateDownloadLinkDependencies{ | ||||||
dataStore: dataStore, | ||||||
nodeExecutionManager: nodeExecutionManager, | ||||||
taskExecutionManager: taskExecutionManager, | ||||||
} | ||||||
} | ||||||
|
||||||
func TestCreateDownloadLink(t *testing.T) { | ||||||
nodeExecutionFunc := func(ctx context.Context, request *admin.NodeExecutionGetRequest) (*admin.NodeExecution, error) { | ||||||
return &admin.NodeExecution{ | ||||||
Closure: &admin.NodeExecutionClosure{ | ||||||
DeckUri: "s3://something/something", | ||||||
}, | ||||||
}, nil | ||||||
}) | ||||||
taskExecutionManager := &mocks.TaskExecutionInterface{} | ||||||
|
||||||
s, err := NewService(config.DataProxyConfig{Download: config.DataProxyDownloadConfig{MaxExpiresIn: stdlibConfig.Duration{Duration: time.Hour}}}, nodeExecutionManager, dataStore, taskExecutionManager) | ||||||
assert.NoError(t, err) | ||||||
} | ||||||
|
||||||
t.Run("Invalid expiry", func(t *testing.T) { | ||||||
_, err = s.CreateDownloadLink(context.Background(), &service.CreateDownloadLinkRequest{ | ||||||
s, dependencies := setupCreateDownloadLink(t) | ||||||
dependencies.nodeExecutionManager.EXPECT().GetNodeExecution(mock.Anything, mock.Anything).RunAndReturn(nodeExecutionFunc) | ||||||
_, err := s.CreateDownloadLink(context.Background(), &service.CreateDownloadLinkRequest{ | ||||||
Comment on lines
+202
to
+204
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider consolidating duplicate test setup code
Consider consolidating the duplicate setup code. The Code suggestionCheck the AI-generated fix before applying
Code Review Run #b1cb17 Is this a valid issue, or was it incorrectly flagged by the Agent?
|
||||||
ExpiresIn: durationpb.New(-time.Hour), | ||||||
}) | ||||||
assert.Error(t, err) | ||||||
}) | ||||||
|
||||||
t.Run("item not found", func(t *testing.T) { | ||||||
dataStore.ComposedProtobufStore.(*commonMocks.TestDataStore).HeadCb = func(ctx context.Context, ref storage.DataReference) (storage.Metadata, error) { | ||||||
s, dependencies := setupCreateDownloadLink(t) | ||||||
dependencies.dataStore.ComposedProtobufStore.(*commonMocks.TestDataStore).HeadCb = func(ctx context.Context, ref storage.DataReference) (storage.Metadata, error) { | ||||||
return testMetadata{exists: false}, nil | ||||||
} | ||||||
|
||||||
_, err = s.CreateDownloadLink(context.Background(), &service.CreateDownloadLinkRequest{ | ||||||
dependencies.nodeExecutionManager.EXPECT().GetNodeExecution(mock.Anything, mock.Anything).RunAndReturn(nodeExecutionFunc) | ||||||
_, err := s.CreateDownloadLink(context.Background(), &service.CreateDownloadLinkRequest{ | ||||||
ArtifactType: service.ArtifactType_ARTIFACT_TYPE_DECK, | ||||||
Source: &service.CreateDownloadLinkRequest_NodeExecutionId{ | ||||||
NodeExecutionId: &core.NodeExecutionIdentifier{}, | ||||||
|
@@ -212,11 +228,12 @@ func TestCreateDownloadLink(t *testing.T) { | |||||
}) | ||||||
|
||||||
t.Run("valid config", func(t *testing.T) { | ||||||
dataStore.ComposedProtobufStore.(*commonMocks.TestDataStore).HeadCb = func(ctx context.Context, ref storage.DataReference) (storage.Metadata, error) { | ||||||
s, dependencies := setupCreateDownloadLink(t) | ||||||
dependencies.dataStore.ComposedProtobufStore.(*commonMocks.TestDataStore).HeadCb = func(ctx context.Context, ref storage.DataReference) (storage.Metadata, error) { | ||||||
return testMetadata{exists: true}, nil | ||||||
} | ||||||
|
||||||
_, err = s.CreateDownloadLink(context.Background(), &service.CreateDownloadLinkRequest{ | ||||||
dependencies.nodeExecutionManager.EXPECT().GetNodeExecution(mock.Anything, mock.Anything).RunAndReturn(nodeExecutionFunc) | ||||||
_, err := s.CreateDownloadLink(context.Background(), &service.CreateDownloadLinkRequest{ | ||||||
ArtifactType: service.ArtifactType_ARTIFACT_TYPE_DECK, | ||||||
Source: &service.CreateDownloadLinkRequest_NodeExecutionId{ | ||||||
NodeExecutionId: &core.NodeExecutionIdentifier{}, | ||||||
|
@@ -227,12 +244,40 @@ func TestCreateDownloadLink(t *testing.T) { | |||||
assert.NoError(t, err) | ||||||
}) | ||||||
|
||||||
t.Run("no deckUrl found", func(t *testing.T) { | ||||||
s, dependencies := setupCreateDownloadLink(t) | ||||||
dependencies.dataStore.ComposedProtobufStore.(*commonMocks.TestDataStore).HeadCb = func(ctx context.Context, ref storage.DataReference) (storage.Metadata, error) { | ||||||
return testMetadata{exists: true}, nil | ||||||
} | ||||||
nodeExecutionFuncWithoutDecks := func(ctx context.Context, request *admin.NodeExecutionGetRequest) (*admin.NodeExecution, error) { | ||||||
return &admin.NodeExecution{ | ||||||
Closure: &admin.NodeExecutionClosure{ | ||||||
DeckUri: "", | ||||||
}, | ||||||
}, nil | ||||||
} | ||||||
dependencies.nodeExecutionManager.EXPECT().GetNodeExecution(mock.Anything, mock.Anything).RunAndReturn(nodeExecutionFuncWithoutDecks) | ||||||
_, err := s.CreateDownloadLink(context.Background(), &service.CreateDownloadLinkRequest{ | ||||||
ArtifactType: service.ArtifactType_ARTIFACT_TYPE_DECK, | ||||||
Source: &service.CreateDownloadLinkRequest_NodeExecutionId{ | ||||||
NodeExecutionId: &core.NodeExecutionIdentifier{}, | ||||||
}, | ||||||
ExpiresIn: durationpb.New(time.Hour), | ||||||
}) | ||||||
assert.Error(t, err) | ||||||
st, ok := status.FromError(err) | ||||||
assert.True(t, ok) | ||||||
assert.Equal(t, codes.NotFound, st.Code()) | ||||||
assert.Contains(t, st.Message(), "no deckUrl found for request") | ||||||
}) | ||||||
|
||||||
t.Run("head failed", func(t *testing.T) { | ||||||
dataStore.ComposedProtobufStore.(*commonMocks.TestDataStore).HeadCb = func(ctx context.Context, ref storage.DataReference) (storage.Metadata, error) { | ||||||
s, dependencies := setupCreateDownloadLink(t) | ||||||
dependencies.dataStore.ComposedProtobufStore.(*commonMocks.TestDataStore).HeadCb = func(ctx context.Context, ref storage.DataReference) (storage.Metadata, error) { | ||||||
return testMetadata{}, fmt.Errorf("head fail") | ||||||
} | ||||||
|
||||||
_, err = s.CreateDownloadLink(context.Background(), &service.CreateDownloadLinkRequest{ | ||||||
dependencies.nodeExecutionManager.EXPECT().GetNodeExecution(mock.Anything, mock.Anything).RunAndReturn(nodeExecutionFunc) | ||||||
_, err := s.CreateDownloadLink(context.Background(), &service.CreateDownloadLinkRequest{ | ||||||
ArtifactType: service.ArtifactType_ARTIFACT_TYPE_DECK, | ||||||
Source: &service.CreateDownloadLinkRequest_NodeExecutionId{ | ||||||
NodeExecutionId: &core.NodeExecutionIdentifier{}, | ||||||
|
@@ -247,11 +292,12 @@ func TestCreateDownloadLink(t *testing.T) { | |||||
}) | ||||||
|
||||||
t.Run("use default ExpiresIn", func(t *testing.T) { | ||||||
dataStore.ComposedProtobufStore.(*commonMocks.TestDataStore).HeadCb = func(ctx context.Context, ref storage.DataReference) (storage.Metadata, error) { | ||||||
s, dependencies := setupCreateDownloadLink(t) | ||||||
dependencies.dataStore.ComposedProtobufStore.(*commonMocks.TestDataStore).HeadCb = func(ctx context.Context, ref storage.DataReference) (storage.Metadata, error) { | ||||||
return testMetadata{exists: true}, nil | ||||||
} | ||||||
|
||||||
_, err = s.CreateDownloadLink(context.Background(), &service.CreateDownloadLinkRequest{ | ||||||
dependencies.nodeExecutionManager.EXPECT().GetNodeExecution(mock.Anything, mock.Anything).RunAndReturn(nodeExecutionFunc) | ||||||
_, err := s.CreateDownloadLink(context.Background(), &service.CreateDownloadLinkRequest{ | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Variable shadowing in CreateDownloadLink test
Consider declaring Code suggestionCheck the AI-generated fix before applying
Suggested change
Code Review Run #b1cb17 Is this a valid issue, or was it incorrectly flagged by the Agent?
|
||||||
ArtifactType: service.ArtifactType_ARTIFACT_TYPE_DECK, | ||||||
Source: &service.CreateDownloadLinkRequest_NodeExecutionId{ | ||||||
NodeExecutionId: &core.NodeExecutionIdentifier{}, | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider if changing error code from
Internal
toNotFound
is appropriate here. TheNotFound
error code should only be used when we're certain the resource doesn't exist. In this case, an emptydeckUrl
could indicate an internal system issue rather than a missing resource.Code suggestion
Code Review Run #b1cb17
Is this a valid issue, or was it incorrectly flagged by the Agent?