Move ArtifactNotFound error to database pkg 45/186445/17
authorAlexander Mazuruk <a.mazuruk@samsung.com>
Fri, 3 Aug 2018 12:03:29 +0000 (14:03 +0200)
committerPawel Wieczorek <p.wieczorek2@samsung.com>
Fri, 14 Sep 2018 13:20:48 +0000 (15:20 +0200)
Previously server was checking for this error.

Change-Id: I17467a4569c4ec6c65954c0a3a97b12351ec8848
Signed-off-by: Alexander Mazuruk <a.mazuruk@samsung.com>
artifacts/database/database.go
artifacts/database/database_test.go
server/artifact_lister_handler.go

index b4c71a2..473316b 100644 (file)
@@ -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,
index eb34efa..bb9debc 100644 (file)
@@ -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() {
index fbe3c6f..d6ba94f 100644 (file)
@@ -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(