// 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 "
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 {
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,
},
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() {