}
return artifacts, nil
}
+
+// getID fetches ID of an artifact with provided path.
+func (aDB *ArtifactDB) getID(path ArtifactPath) (int64, error) {
+ res, err := aDB.dbmap.SelectInt("select ID from artifacts where Path=?", path)
+ if err != nil {
+ return 0, err
+ }
+ return res, nil
+}
+
+// SetStatus changes artifact's status in ArtifactDB.
+func (aDB *ArtifactDB) SetStatus(change ArtifactStatusChange) error {
+ ai, err := aDB.SelectPath(change.Path)
+ if err != nil {
+ return err
+ }
+ ar := artifactInfoRecord{
+ ArtifactInfo: ai,
+ }
+
+ id, err := aDB.getID(ar.Path)
+ if err != nil {
+ return err
+ }
+ ar.ID = id
+
+ ar.Status = change.NewStatus
+ _, err = aDB.dbmap.Update(&ar)
+ return err
+}
Entry("filter is empty", emptyFilter, artifact, aImageReady, aYamlFailed, aTestFailed),
)
})
+ Describe("SetStatus", func() {
+ BeforeEach(func() {
+ for _, a := range testArtifacts {
+ err := goldenUnicorn.InsertArtifactInfo(&a)
+ Expect(err).ToNot(HaveOccurred())
+ }
+ })
+ DescribeTable("artifact status change",
+ func(change weles.ArtifactStatusChange, expectedErr error) {
+
+ err := goldenUnicorn.SetStatus(change)
+ if expectedErr == nil {
+ Expect(err).ToNot(HaveOccurred())
+
+ a, err := goldenUnicorn.SelectPath(change.Path)
+ Expect(err).ToNot(HaveOccurred())
+ Expect(a.Status).To(Equal(change.NewStatus))
+ } else {
+ Expect(err).To(Equal(expectedErr))
+ a, err := goldenUnicorn.SelectPath(change.Path)
+ Expect(err).To(HaveOccurred())
+ Expect(a).To(Equal(weles.ArtifactInfo{}))
+ }
+ },
+ Entry("change status of artifact not present in ArtifactDB", weles.ArtifactStatusChange{invalidPath, weles.AM_DOWNLOADING}, sql.ErrNoRows),
+ Entry("change status of artifact present in ArtifactDB", weles.ArtifactStatusChange{artifact.Path, weles.AM_DOWNLOADING}, nil),
+ )
+ })
})