forked from RedisGrafana/grafana-redis-datasource
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Magefile.go
76 lines (59 loc) · 2.08 KB
/
Magefile.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//go:build mage
// +build mage
package main
import (
"os"
"path/filepath"
// mage:import
build "github.com/grafana/grafana-plugin-sdk-go/build"
"github.com/magefile/mage/sh"
)
// runs backend tests and makes a txt coverage report in "atomic" mode and html coverage report.
func Cover() error {
// Create a coverage file if it does not already exist
if err := os.MkdirAll(filepath.Join(".", "coverage"), os.ModePerm); err != nil {
return err
}
if err := sh.RunV("go", "test", "./pkg/...", "-v", "-cover", "-covermode=atomic", "-coverprofile=coverage/backend.txt"); err != nil {
return err
}
if err := sh.RunV("go", "tool", "cover", "-html=coverage/backend.txt", "-o", "coverage/backend.html"); err != nil {
return err
}
return nil
}
// up docker-compose environment and run backend tests including integration tests with coverage report
func Integration() error {
// Create a coverage file if it does not already exist
if err := os.MkdirAll(filepath.Join(".", "coverage"), os.ModePerm); err != nil {
return err
}
if err := Up(); err != nil {
return err
}
defer Down()
if err := sh.RunV("go", "test", "./pkg/...", "-tags=integration", "-v", "-cover", "-covermode=atomic", "-coverprofile=coverage/backend.txt"); err != nil {
return err
}
if err := sh.RunV("go", "tool", "cover", "-html=coverage/backend.txt", "-o", "coverage/backend.html"); err != nil {
return err
}
return nil
}
// up docker-compose environment and run cluster tests
func Cluster() error {
if err := sh.Run("docker-compose", "-f", "docker-compose/cluster.yml", "run", "gotest", "bash", "/app/docker-compose/cluster/cluster_tests.sh"); err != nil {
return err
}
return nil
}
// up docker-compose environment from integration tests
func Up() error {
return sh.RunV("docker-compose", "-f", "docker-compose/test.yml", "-p", "grd-integration", "up", "-d")
}
// down docker-compose environment from integration tests
func Down() error {
return sh.RunV("docker-compose", "-f", "docker-compose/test.yml", "-p", "grd-integration", "down")
}
// Default configures the default target.
var Default = build.BuildAll