forked from testcontainers/testcontainers-go
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into compose-module
* main: chore: generate dependabot configs for examples (testcontainers#654) chore: format dependabot using go-yaml indents (testcontainers#658) chore(deps): bump github.com/docker/compose/v2 from 2.12.2 to 2.14.0 (testcontainers#657) chore(deps): bump github.com/stretchr/testify from 1.8.0 to 1.8.1 (#583) chore(deps): bump github.com/cenkalti/backoff/v4 from 4.1.3 to 4.2.0 (testcontainers#656) chore: remove quotes from dependabot updates (testcontainers#655) fix: do not create garbage in examples nav bar (testcontainers#652) chore(deps): bump github.com/containerd/containerd from 1.6.8 to 1.6.10 (#621) chore(deps): bump golang.org/x/sys from 0.1.0 to 0.3.0 (testcontainers#651)
- Loading branch information
Showing
12 changed files
with
440 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,68 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: gomod | ||
directory: "/" | ||
schedule: | ||
interval: daily | ||
open-pull-requests-limit: 3 | ||
rebase-strategy: disabled | ||
- package-ecosystem: gomod | ||
directory: "/e2e" | ||
schedule: | ||
interval: daily | ||
open-pull-requests-limit: 3 | ||
rebase-strategy: disabled | ||
- package-ecosystem: gomod | ||
directory: / | ||
schedule: | ||
interval: daily | ||
open-pull-requests-limit: 3 | ||
rebase-strategy: disabled | ||
- package-ecosystem: gomod | ||
directory: /e2e | ||
schedule: | ||
interval: daily | ||
open-pull-requests-limit: 3 | ||
rebase-strategy: disabled | ||
- package-ecosystem: gomod | ||
directory: /examples/cockroachdb | ||
schedule: | ||
interval: daily | ||
open-pull-requests-limit: 3 | ||
rebase-strategy: disabled | ||
- package-ecosystem: gomod | ||
directory: /examples/datastore | ||
schedule: | ||
interval: daily | ||
open-pull-requests-limit: 3 | ||
rebase-strategy: disabled | ||
- package-ecosystem: gomod | ||
directory: /examples/firestore | ||
schedule: | ||
interval: daily | ||
open-pull-requests-limit: 3 | ||
rebase-strategy: disabled | ||
- package-ecosystem: gomod | ||
directory: /examples/nginx | ||
schedule: | ||
interval: daily | ||
open-pull-requests-limit: 3 | ||
rebase-strategy: disabled | ||
- package-ecosystem: gomod | ||
directory: /examples/pubsub | ||
schedule: | ||
interval: daily | ||
open-pull-requests-limit: 3 | ||
rebase-strategy: disabled | ||
- package-ecosystem: gomod | ||
directory: /examples/pulsar | ||
schedule: | ||
interval: daily | ||
open-pull-requests-limit: 3 | ||
rebase-strategy: disabled | ||
- package-ecosystem: gomod | ||
directory: /examples/redis | ||
schedule: | ||
interval: daily | ||
open-pull-requests-limit: 3 | ||
rebase-strategy: disabled | ||
- package-ecosystem: gomod | ||
directory: /examples/spanner | ||
schedule: | ||
interval: daily | ||
open-pull-requests-limit: 3 | ||
rebase-strategy: disabled | ||
- package-ecosystem: gomod | ||
directory: /examples/toxiproxy | ||
schedule: | ||
interval: daily | ||
open-pull-requests-limit: 3 | ||
rebase-strategy: disabled |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
package main | ||
|
||
import ( | ||
"io/ioutil" | ||
"path/filepath" | ||
|
||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
type Updates []Update | ||
|
||
type DependabotConfig struct { | ||
Version int `yaml:"version"` | ||
Updates Updates `yaml:"updates"` | ||
} | ||
|
||
type Schedule struct { | ||
Interval string `yaml:"interval"` | ||
} | ||
|
||
type Update struct { | ||
PackageEcosystem string `yaml:"package-ecosystem"` | ||
Directory string `yaml:"directory"` | ||
Schedule Schedule `yaml:"schedule"` | ||
OpenPullRequestsLimit int `yaml:"open-pull-requests-limit"` | ||
RebaseStrategy string `yaml:"rebase-strategy"` | ||
} | ||
|
||
func NewUpdate(example string) Update { | ||
return Update{ | ||
Directory: "/examples/" + example, | ||
OpenPullRequestsLimit: 3, | ||
PackageEcosystem: "gomod", | ||
RebaseStrategy: "disabled", | ||
Schedule: Schedule{ | ||
Interval: "daily", | ||
}, | ||
} | ||
} | ||
|
||
// Len is the number of elements in the collection. | ||
func (u Updates) Len() int { | ||
return len(u) | ||
} | ||
|
||
// Less reports whether the element with index i | ||
// must sort before the element with index j. | ||
// | ||
// If both Less(i, j) and Less(j, i) are false, | ||
// then the elements at index i and j are considered equal. | ||
// Sort may place equal elements in any order in the final result, | ||
// while Stable preserves the original input order of equal elements. | ||
// | ||
// Less must describe a transitive ordering: | ||
// - if both Less(i, j) and Less(j, k) are true, then Less(i, k) must be true as well. | ||
// - if both Less(i, j) and Less(j, k) are false, then Less(i, k) must be false as well. | ||
// | ||
// Note that floating-point comparison (the < operator on float32 or float64 values) | ||
// is not a transitive ordering when not-a-number (NaN) values are involved. | ||
// See Float64Slice.Less for a correct implementation for floating-point values. | ||
func (u Updates) Less(i, j int) bool { | ||
return u[i].Directory < u[j].Directory | ||
} | ||
|
||
// Swap swaps the elements with indexes i and j. | ||
func (u Updates) Swap(i, j int) { | ||
u[i], u[j] = u[j], u[i] | ||
} | ||
|
||
func getDependabotConfigFile(rootDir string) string { | ||
return filepath.Join(rootDir, ".github", "dependabot.yml") | ||
} | ||
|
||
func getDependabotUpdates() ([]Update, error) { | ||
parent, err := getRootDir() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
config, err := readDependabotConfig(parent) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return config.Updates, nil | ||
} | ||
|
||
func readDependabotConfig(rootDir string) (*DependabotConfig, error) { | ||
configFile := getDependabotConfigFile(rootDir) | ||
|
||
file, err := ioutil.ReadFile(configFile) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
config := &DependabotConfig{} | ||
|
||
err = yaml.Unmarshal(file, config) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return config, nil | ||
} | ||
|
||
func writeDependabotConfig(rootDir string, config *DependabotConfig) error { | ||
data, err := yaml.Marshal(config) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
file := getDependabotConfigFile(rootDir) | ||
|
||
return ioutil.WriteFile(file, data, 0777) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.