forked from testcontainers/testcontainers-go
/
dependabot_test.go
81 lines (62 loc) · 2.08 KB
/
dependabot_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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
import (
"os"
"path/filepath"
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestGetDependabotConfigFile(t *testing.T) {
tmp := t.TempDir()
rootDir := filepath.Join(tmp, "testcontainers-go")
githubDir := filepath.Join(rootDir, ".github")
cfgFile := filepath.Join(githubDir, "dependabot.yml")
err := os.MkdirAll(githubDir, 0777)
require.NoError(t, err)
err = os.WriteFile(cfgFile, []byte{}, 0777)
require.NoError(t, err)
file := getDependabotConfigFile(rootDir)
require.NotNil(t, file)
assert.True(t, strings.HasSuffix(file, filepath.Join("testcontainers-go", ".github", "dependabot.yml")))
}
func TestReadDependabotConfig(t *testing.T) {
tmp := t.TempDir()
rootDir := filepath.Join(tmp, "testcontainers-go")
githubDir := filepath.Join(rootDir, ".github")
err := os.MkdirAll(githubDir, 0777)
require.NoError(t, err)
err = copyInitialDependabotConfig(t, rootDir)
require.NoError(t, err)
config, err := readDependabotConfig(rootDir)
require.NoError(t, err)
require.NotNil(t, config)
assert.Greater(t, len(config.Updates), 0)
}
func TestExamplesHasDependabotEntry(t *testing.T) {
examples, err := getExamples()
require.NoError(t, err)
exampleUpdates, err := getDependabotUpdates()
require.NoError(t, err)
// we have to exclude the main and e2e modules from the examples updates
assert.Equal(t, len(exampleUpdates)-2, len(examples))
// all example modules exist in the dependabot updates
for _, example := range examples {
found := false
for _, exampleUpdate := range exampleUpdates {
dependabotDir := "/examples/" + strings.ToLower(example.Name())
if dependabotDir == exampleUpdate.Directory {
found = true
continue
}
}
assert.True(t, found, "example %s is not present in the dependabot updates", example.Name())
}
}
func copyInitialDependabotConfig(t *testing.T, tmpDir string) error {
projectDir, err := getRootDir()
require.NoError(t, err)
initialConfig, err := readDependabotConfig(projectDir)
require.NoError(t, err)
return writeDependabotConfig(tmpDir, initialConfig)
}