Skip to content

Commit

Permalink
meta: Add test for deprecated package ioutil (syncthing#8053)
Browse files Browse the repository at this point in the history
  • Loading branch information
calmh authored Nov 22, 2021
1 parent 7161a99 commit 7c3b267
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
52 changes: 52 additions & 0 deletions meta/forbidden_words_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright (C) 2021 The Syncthing Authors.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.

package meta

import (
"bytes"
"os"
"path/filepath"
"strings"
"testing"
)

// Checks for forbidden words in all .go files
func TestForbiddenWords(t *testing.T) {
checkDirs := []string{"../cmd", "../lib", "../test", "../script"}
forbiddenWords := []string{
`"io/ioutil"`, // deprecated and should not be imported
}

for _, dir := range checkDirs {
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if path == ".git" {
return filepath.SkipDir
}
if filepath.Ext(path) != ".go" || strings.HasSuffix(path, ".pb.go") {
return nil
}

bs, err := os.ReadFile(path)
if err != nil {
return nil
}

for _, word := range forbiddenWords {
if bytes.Contains(bs, []byte(word)) {
t.Errorf("%s: forbidden word %q", path, word)
}
}
return nil
})
if err != nil {
t.Fatal(err)
}
}
}
2 changes: 1 addition & 1 deletion meta/gofmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.

// Checks for authors that are not mentioned in AUTHORS
package meta

import (
Expand All @@ -17,6 +16,7 @@ import (

var gofmtCheckDirs = []string{".", "../cmd", "../lib", "../test", "../script"}

// Checks that files are properly gofmt:ed.
func TestCheckGoFmt(t *testing.T) {
for _, dir := range gofmtCheckDirs {
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
Expand Down

0 comments on commit 7c3b267

Please sign in to comment.