예제 #1
0
func TestHideUnhideAdvisory(*testing.T) {

	db, err := openDB()

	defer db.Close()

	adv := steward.Advisory{Text: "pony"}

	team_id := 10

	adv.ID, err = steward.AddAdvisory(db.db, team_id, adv.Text)
	if err != nil {
		log.Fatalln("Add advisory fail:", err)
	}

	advisories, err := steward.GetAdvisories(db.db)
	if err != nil {
		log.Fatalln("Get advisory fail:", err)
	}

	if len(advisories) != 1 {
		log.Fatalln("No added advisory")
	}

	err = steward.HideAdvisory(db.db, adv.ID, true)
	if err != nil {
		log.Fatalln("Hide advisory fail:", err)
	}

	advisories, err = steward.GetAdvisories(db.db)
	if err != nil {
		log.Fatalln("Get advisory fail:", err)
	}

	if len(advisories) != 0 {
		log.Fatalln("Hide advisory does not work")
	}

	err = steward.HideAdvisory(db.db, adv.ID, false)
	if err != nil {
		log.Fatalln("Hide advisory fail:", err)
	}

	advisories, err = steward.GetAdvisories(db.db)
	if err != nil {
		log.Fatalln("Get advisory fail:", err)
	}

	if len(advisories) != 1 {
		log.Fatalln("Unhide advisory does not work")
	}
}
예제 #2
0
func advisoryUpdater(db *sql.DB, updateTimeout time.Duration) {

	for {
		var tmpAdvisories string

		advs, err := steward.GetAdvisories(db)
		if err != nil {
			time.Sleep(updateTimeout)
			continue
		}

		for i := range advs {
			adv := advs[len(advs)-i-1]
			if adv.Reviewed {
				tmpAdvisories += advisoryToHTML(adv)
			}
		}

		if len(tmpAdvisories) == 0 {
			advisories = "Current no advisories"
		} else {
			advisories = tmpAdvisories
		}

		time.Sleep(updateTimeout)
	}
}
예제 #3
0
func TestGetAdvisories(t *testing.T) {

	db, err := openDB()

	defer db.Close()

	team_id := 10

	var adv1, adv2 steward.Advisory

	adv1.Text = "adv1_test"
	adv1.Score = 10
	adv1.Reviewed = true

	adv2.Text = "adv2_test"
	adv2.Score = 20
	adv2.Reviewed = true

	adv1.ID, _ = steward.AddAdvisory(db.db, team_id, adv1.Text)
	adv2.ID, _ = steward.AddAdvisory(db.db, team_id, adv2.Text)

	steward.ReviewAdvisory(db.db, adv1.ID, adv1.Score)
	steward.ReviewAdvisory(db.db, adv2.ID, adv2.Score)

	advisories, err := steward.GetAdvisories(db.db)
	if err != nil {
		log.Fatalln("Get all advisories failed:", err)
	}

	if len(advisories) != 2 {
		log.Fatalln("Get advisories more than added")
	}

	if time.Now().Sub(advisories[0].Timestamp) > 5*time.Second {
		log.Fatalln("Time must be ~ current:", advisories[0].Timestamp)
	}

	// No timestamp check
	adv1.Timestamp = advisories[0].Timestamp
	adv2.Timestamp = advisories[1].Timestamp

	if advisories[0] != adv1 || advisories[1] != adv2 {
		log.Fatalln("Added advisories broken")
	}

}
예제 #4
0
func advisoryList(db *sql.DB) {
	advisories, err := steward.GetAdvisories(db)
	if err != nil {
		log.Fatalln("Get advisories fail:", err)
	}

	for _, advisory := range advisories {

		if *advNotReviewed && advisory.Reviewed {
			continue
		}

		fmt.Printf(">>> Advisory: id %d <<<\n", advisory.ID)
		fmt.Printf("(Score: %d, Reviewed: %t, Timestamp: %s)\n",
			advisory.Score, advisory.Reviewed,
			advisory.Timestamp.String())

		fmt.Println(advisory.Text)
	}

}