func TestDestroyImage(t *testing.T) {
	results, err := FindAll(Query())
	if err != nil || len(results) == 0 {
		t.Fatalf("images: Destroy no image found :%s", err)
	}
	image := results[0]
	count := len(results)
	err = image.Destroy()
	if err != nil {
		t.Fatalf("images: Destroy image failed :%s", err)
	}
	results, err = FindAll(Query())
	if err != nil {
		t.Fatalf("images: Destroy error getting results :%s", err)
	}
	if len(results) != count-1 {
		t.Fatalf("images: Destroy image count wrong :%d", len(results))
	}
}
Test Destroy method
package images
import (
	"testing"
	"github.com/fragmenta/fragmenta-cms/src/lib/resource"
)
var testName = "foo"
func TestSetup(t *testing.T) {
	err := resource.SetupTestDatabase(2)
	if err != nil {
		t.Fatalf("images: Setup db failed %s", err)
	}
}
func TestCreateImage(t *testing.T) {
	imageParams := map[string]string{
		"name":   testName,
		"status": "100",
	}
	id, err := New().Create(imageParams)
	if err != nil {
		t.Fatalf("images: Create image failed :%s", err)
	}
	image, err := Find(id)
	if err != nil {
		t.Fatalf("images: Create image find failed")
	}
	if image.Name != testName {
		t.Fatalf("images: Create image name failed expected:%s got:%s", testName, image.Name)
	}
}
func TestListImage(t *testing.T) {
	results, err := FindAll(Query())
	if err != nil {
		t.Fatalf("images: List no image found :%s", err)
	}
	if len(results) < 1 {
		t.Fatalf("images: List no images found :%s", err)
	}
}
func TestUpdateImage(t *testing.T) {
	image, err := FindFirst("name=?", testName)
	if err != nil {
		t.Fatalf("images: Update no image found :%s", err)
	}
	name := "bar"
	imageParams := map[string]string{"name": name}
	err = image.Update(imageParams)
	if err != nil {
		t.Fatalf("images: Update image failed :%s", err)
	}
	image, err = Find(image.ID)
	if err != nil {
		t.Fatalf("images: Update image fetch failed :%s", image.Name)
	}
	if image.Name != name {
		t.Fatalf("images: Update image failed :%s", image.Name)
	}
}
func TestQuery(t *testing.T) {
	results, err := FindAll(Published())
	if err != nil {
		t.Fatalf("images: error getting images :%s", err)
	}
	if len(results) == 0 {
		t.Fatalf("images: published images not found :%s", err)
	}
	results, err = FindAll(Query().Where("id>=? AND id <=?", 0, 100))
	if err != nil || len(results) == 0 {
		t.Fatalf("images: no image found :%s", err)
	}
	if len(results) > 1 {
		t.Fatalf("images: more than one image found for where :%s", err)
	}
}