From bbbe311ac5287047a06345b3c93558d200bf94d0 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Mon, 2 Oct 2017 11:22:17 +0200 Subject: [PATCH] Added test job --- jobs/jobs.go | 1 + jobs/test/test.go | 58 +++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 54 insertions(+), 5 deletions(-) diff --git a/jobs/jobs.go b/jobs/jobs.go index 9f3a86d1..edfb0049 100644 --- a/jobs/jobs.go +++ b/jobs/jobs.go @@ -30,6 +30,7 @@ var jobs = map[string]time.Duration{ "statistics": 15 * time.Minute, "popular-anime": 20 * time.Minute, "avatars": 30 * time.Minute, + "test": 1 * time.Hour, "twist": 1 * time.Hour, "search-index": 2 * time.Hour, "sync-shoboi": 8 * time.Hour, diff --git a/jobs/test/test.go b/jobs/test/test.go index c7c4cae5..0fc58c8d 100644 --- a/jobs/test/test.go +++ b/jobs/test/test.go @@ -1,14 +1,46 @@ package main import ( - "os" "os/exec" + "sync" + + "github.com/animenotifier/arn" + + "github.com/fatih/color" ) +var packages = []string{ + "github.com/animenotifier/notify.moe", + "github.com/animenotifier/arn", + "github.com/animenotifier/kitsu", + "github.com/animenotifier/anilist", + "github.com/animenotifier/mal", + "github.com/animenotifier/shoboi", + "github.com/animenotifier/twist", + "github.com/animenotifier/avatar", + "github.com/animenotifier/japanese", + // "github.com/animenotifier/osu", +} + func main() { - cmd := exec.Command("go", "test", "github.com/animenotifier/notify.moe") - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr + wg := sync.WaitGroup{} + + for _, pkg := range packages { + wg.Add(1) + + go func(pkgLocal string) { + testPackage(pkgLocal) + wg.Done() + }(pkg) + } + + wg.Wait() +} + +func testPackage(pkg string) { + cmd := exec.Command("go", "test", pkg+"/...") + // cmd.Stdout = os.Stdout + // cmd.Stderr = os.Stderr err := cmd.Start() @@ -16,5 +48,21 @@ func main() { panic(err) } - cmd.Wait() + err = cmd.Wait() + + if err != nil { + color.Red("%s", pkg) + + // Send notification to the admin + admin, _ := arn.GetUser("4J6qpK1ve") + admin.SendNotification(&arn.Notification{ + Title: pkg, + Message: "Test failed", + Link: "https://" + pkg, + Icon: "https://notify.moe/images/brand/300.png", + }) + return + } + + color.Green("%s", pkg) }