Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from tenv to usetesting #718

Merged
merged 2 commits into from
Mar 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ linters:
- misspell
- revive
- staticcheck
- tenv
- unconvert
- unused
- unparam
- usetesting

issues:
# Excluding configuration per-path, per-linter, per-text and per-source
Expand Down
19 changes: 2 additions & 17 deletions crosslink/internal/crosslink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,8 @@ func TestCrosslink(t *testing.T) {
err = Crosslink(test.config)

if assert.NoError(t, err, "error message on execution %s") {

for modFilePath, modFilesExpected := range test.expected {
modFileActual, err := os.ReadFile(filepath.Clean(filepath.Join(tmpRootDir, modFilePath)))

if err != nil {
t.Fatalf("error reading actual mod files: %v", err)
}
Expand Down Expand Up @@ -167,7 +165,6 @@ func TestCrosslink(t *testing.T) {
}
}
}

})
}
}
Expand Down Expand Up @@ -256,7 +253,6 @@ func TestOverwrite(t *testing.T) {

for modFilePath, modFilesExpected := range test.expected {
modFileActual, err := os.ReadFile(filepath.Clean(filepath.Join(tmpRootDir, modFilePath)))

if err != nil {
t.Fatalf("error reading actual mod files: %v", err)
}
Expand Down Expand Up @@ -286,14 +282,12 @@ func TestOverwrite(t *testing.T) {
}
}
}

})
}
err := lg.Sync()
if err != nil {
fmt.Printf("failed to sync logger: %v", err)
}

}

// Testing exclude functionality for prune, overwrite, and no overwrite.
Expand Down Expand Up @@ -372,7 +366,6 @@ func TestExclude(t *testing.T) {

for modFilePath, modFilesExpected := range modFilesExpected {
modFileActual, err := os.ReadFile(filepath.Clean(modFilePath))

if err != nil {
t.Fatalf("TestCase: %s, error reading actual mod files: %v", test.testCase, err)
}
Expand Down Expand Up @@ -410,13 +403,11 @@ func TestBadRootPath(t *testing.T) {
lg, _ := zap.NewDevelopment()
tests := []struct {
testName string
mockDir string
setConfigPath bool
config RunConfig
}{
{
testName: "noGoMod",
mockDir: "noGoMod",
setConfigPath: true,
config: RunConfig{
Logger: lg,
Expand All @@ -426,22 +417,17 @@ func TestBadRootPath(t *testing.T) {

for _, test := range tests {
t.Run(test.testName, func(t *testing.T) {
tmpRootDir, err := os.MkdirTemp(testDataDir, test.mockDir)
if err != nil {
t.Fatalf("Failed to create temp dir %v", err)
}
tmpRootDir := t.TempDir()
if test.setConfigPath {
test.config.RootPath = tmpRootDir
}

t.Cleanup(func() { os.RemoveAll(tmpRootDir) })
err = Crosslink(test.config)
err := Crosslink(test.config)
assert.Error(t, err)
err = Prune(test.config)
assert.Error(t, err)
})
}

}

// Testing skipping specified go modules.
Expand Down Expand Up @@ -526,7 +512,6 @@ func TestSkip(t *testing.T) {
}
}
modFileActual, err := os.ReadFile(filepath.Clean(modFilePath))

if err != nil {
t.Fatalf("TestCase: %s, error reading actual mod files: %v", test.testCase, err)
}
Expand Down
21 changes: 3 additions & 18 deletions multimod/internal/sync/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,7 @@ func TestNewSync(t *testing.T) {
myVersioningFilename := filepath.Join(versionsYamlDir, "versions_valid.yaml")
otherVersioningFilename := filepath.Join(versionsYamlDir, "other_versions_valid.yaml")

tmpRootDir, err := os.MkdirTemp(testDataDir, testName)
if err != nil {
t.Fatal("creating temp dir:", err)
}

defer os.RemoveAll(tmpRootDir)
tmpRootDir := t.TempDir()

modFiles := map[string][]byte{
filepath.Join(tmpRootDir, "my", "test", "test1", "go.mod"): []byte("module go.opentelemetry.io/build-tools/multimod/internal/sync/test/test1\n\n" +
Expand Down Expand Up @@ -273,12 +268,7 @@ func TestUpdateAllGoModFilesWithCommitHash(t *testing.T) {
}

for _, tc := range testCases {
tmpRootDir, err := os.MkdirTemp(testDataDir, testName)
if err != nil {
t.Fatal("creating temp dir:", err)
}

defer os.RemoveAll(tmpRootDir)
tmpRootDir := t.TempDir()

modFiles := map[string][]byte{
filepath.Join(tmpRootDir, "my", "test", "test1", "go.mod"): []byte("module go.opentelemetry.io/build-tools/multimod/internal/sync/test/test1\n\n" +
Expand Down Expand Up @@ -475,12 +465,7 @@ func TestUpdateAllGoModFiles(t *testing.T) {
}

for _, tc := range testCases {
tmpRootDir, err := os.MkdirTemp(testDataDir, testName)
if err != nil {
t.Fatal("creating temp dir:", err)
}

defer os.RemoveAll(tmpRootDir)
tmpRootDir := t.TempDir()

modFiles := map[string][]byte{
filepath.Join(tmpRootDir, "my", "test", "test1", "go.mod"): []byte("module go.opentelemetry.io/build-tools/multimod/internal/sync/test/test1\n\n" +
Expand Down
3 changes: 1 addition & 2 deletions semconvgen/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,10 @@ func TestCapitalizations(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tmpfile, err := os.CreateTemp("", "test")
tmpfile, err := os.CreateTemp(t.TempDir(), "test")
if err != nil {
t.Fatal(err)
}
defer os.Remove(tmpfile.Name())

if _, err = tmpfile.Write([]byte(tt.capitalizations)); err != nil {
t.Fatal(err)
Expand Down
Loading