forked from erinkerNCS/gitlab-settings-enforcer
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_test.go
54 lines (48 loc) · 1.28 KB
/
main_test.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
package main
import (
"github.com/libri-gmbh/gitlab-settings-enforcer/cmd"
"github.com/stretchr/testify/require"
"os"
"os/exec"
"testing"
)
// TestCrasher tests the command from the outside with a special config.json
// modelled after https://talks.golang.org/2014/testing.slide#23
func TestCrasher(t *testing.T) {
// This variable is set by this test function so it calls itself
// to test the actual execution
if os.Getenv("BE_CRASHER") == "1" {
cmd.Execute()
return
}
const configJSON = `{
"group_name": "some/group",
"project_whitelist": ["some/group/some-project"],
"include_subgroups": false,
"create_default_branch": true,
"protected_branches": [
{
"name": "master",
"push_access_level": "noone",
"merge_access_level": "developer"
}
],
"project_settings": {
"default_branch": "master"
}
}`
cfgFile := "config.json"
require.NoError(t, os.WriteFile(cfgFile, ([]byte)(configJSON), 0666))
defer func() {
if err := os.Remove(cfgFile); err != nil {
t.Logf("failed to delete config: %v", err)
}
}()
command := exec.Command(os.Args[0], "-test.run=TestCrasher", "sync")
command.Env = append(os.Environ(), "BE_CRASHER=1")
out, err := command.CombinedOutput()
if err != nil {
t.Log(string(out))
//t.Errorf("run failed: %v", err)
}
}