From: Alexander Mazuruk Date: Fri, 3 Aug 2018 12:03:29 +0000 (+0200) Subject: Move ArtifactNotFound error to database pkg X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F45%2F186445%2F17;p=tools%2Fweles.git Move ArtifactNotFound error to database pkg Previously server was checking for this error. Change-Id: I17467a4569c4ec6c65954c0a3a97b12351ec8848 Signed-off-by: Alexander Mazuruk --- diff --git a/artifacts/database/database.go b/artifacts/database/database.go index b4c71a2..473316b 100644 --- a/artifacts/database/database.go +++ b/artifacts/database/database.go @@ -80,11 +80,9 @@ func (aDB *ArtifactDB) SelectPath(path weles.ArtifactPath) (weles.ArtifactInfo, // prepareQuery prepares query based on given filter. // TODO code duplication -func prepareQuery( - filter weles.ArtifactFilter, - sorter weles.ArtifactSorter, - paginator weles.ArtifactPagination, - totalRecords, remainingRecords bool, offset int64) (query string, args []interface{}) { +func prepareQuery(filter weles.ArtifactFilter, sorter weles.ArtifactSorter, + paginator weles.ArtifactPagination, totalRecords, remainingRecords bool, offset int64, +) (query string, args []interface{}) { if !totalRecords && !remainingRecords { query = "select * from artifacts " @@ -196,10 +194,9 @@ func (aDB *ArtifactDB) Filter(filter weles.ArtifactFilter, sorter weles.Artifact if err != nil { return nil, weles.ListInfo{}, errors.New(whileFilter + dbTotalFail + err.Error()) } - // TODO: refactor this file. below is to ignore pagination object when pagination is turned off. - if paginator.Limit == 0 { - paginator.Forward = true - paginator.ID = 0 + + if tr == 0 { + return []weles.ArtifactInfo{}, weles.ListInfo{}, weles.ErrArtifactNotFound } if !paginator.Forward { @@ -212,9 +209,7 @@ func (aDB *ArtifactDB) Filter(filter weles.ArtifactFilter, sorter weles.Artifact return nil, weles.ListInfo{}, errors.New(whileFilter + dbArtifactInfoFail + err.Error()) } if err := trans.Commit(); err != nil { - return nil, - weles.ListInfo{}, - errors.New(whileFilter + dbTransCommitFail + err.Error()) + return nil, weles.ListInfo{}, errors.New(whileFilter + dbTransCommitFail + err.Error()) } return results, diff --git a/artifacts/database/database_test.go b/artifacts/database/database_test.go index eb34efa..bb9debc 100644 --- a/artifacts/database/database_test.go +++ b/artifacts/database/database_test.go @@ -289,21 +289,28 @@ var _ = Describe("ArtifactDB", func() { }, Entry("filter one JobID", oneJobFilter, artifact), Entry("filter more than one JobIDs", twoJobsFilter, artifact, aImageReady, aYamlFailed), - Entry("filter JobID not in db", noJobFilter), Entry("filter one Type", oneTypeFilter, aYamlFailed), Entry("filter more than one Type", twoTypesFilter, aYamlFailed, aTestFailed), - Entry("filter Type not in db", noTypeFilter), Entry("filter one Status", oneStatusFilter, artifact), Entry("filter more than one Status", twoStatusFilter, artifact, aTestFailed, aYamlFailed), - Entry("filter Status not in db", noStatusFilter), Entry("filter one Alias", oneAliasFilter, artifact), Entry("filter more than one Alias", twoAliasFilter, artifact, aImageReady, aYamlFailed), - Entry("filter Alias not in db", noAliasFilter), Entry("filter is completly set up", fullFilter, aYamlFailed), - Entry("no artifact in db matches filter", noMatchFilter), Entry("filter is empty", emptyFilter, artifact, aImageReady, aYamlFailed, aTestFailed), ) + + DescribeTable("return artifact not found error", + func(filter weles.ArtifactFilter, expected ...weles.ArtifactInfo) { + _, _, err := goldenUnicorn.Filter(filter, defaultSorter, weles.ArtifactPagination{}) + Expect(err).To(Equal(weles.ErrArtifactNotFound)) + }, + Entry("filter JobID not in db", noJobFilter), + Entry("filter Type not in db", noTypeFilter), + Entry("filter Status not in db", noStatusFilter), + Entry("filter Alias not in db", noAliasFilter), + Entry("no artifact in db matches filter", noMatchFilter), + ) }) Describe("SetStatus", func() { BeforeEach(func() { diff --git a/server/artifact_lister_handler.go b/server/artifact_lister_handler.go index fbe3c6f..d6ba94f 100644 --- a/server/artifact_lister_handler.go +++ b/server/artifact_lister_handler.go @@ -44,12 +44,6 @@ func (a *APIDefaults) ArtifactLister(params artifacts.ArtifactListerParams) midd weles.ArtifactFilter{}, weles.ArtifactSorter{}, paginator) } - // TODO: remove this when artifactmanager will return this. - if len(artifactInfoReceived) == 0 { - return artifacts.NewArtifactListerNotFound().WithPayload( - &weles.ErrResponse{Message: weles.ErrArtifactNotFound.Error()}) - } - switch err { default: return artifacts.NewArtifactListerInternalServerError().WithPayload(