func artifactRecordToInfo(ar artifactInfoRecord) ArtifactInfo {
return ar.ArtifactInfo
}
+
+// 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 := newArtifactInfoRecord(&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
+}
return n
}
+ // statusInDB := func(status weles.ArtifactStatus) int64 {
+ // n, err := goldenUnicorn.dbmap.SelectInt(`SELECT COUNT(*)
+ // FROM artifacts
+ // WHERE Status = ?`, status)
+ // Expect(err).ToNot(HaveOccurred())
+ // return n
+ // }
+
BeforeEach(func() {
var err error
tmpDir, err = ioutil.TempDir("", "weles-")
)
})
- Describe("list", func() {
+ Describe("List", func() {
BeforeEach(func() {
for _, a := range testArtifacts {
err := goldenUnicorn.InsertArtifactInfo(&a)
Expect(err).ToNot(HaveOccurred())
}
})
- DescribeTable("ArtifactDB.List()",
+ DescribeTable("list artifacts matching filter",
func(filter weles.ArtifactFilter, expected []weles.ArtifactInfo) {
results, err := goldenUnicorn.Filter(filter)
Expect(err).ToNot(HaveOccurred())
)
})
+ 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),
+ )
+ })
})