Skip to content

Commit

Permalink
fix forbidigo linter
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Ramlot <42113979+inteon@users.noreply.github.com>
  • Loading branch information
inteon committed Apr 30, 2024
1 parent 16a344e commit 8ea7cbc
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 23 deletions.
1 change: 0 additions & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ issues:
- tenv
- exhaustive
- nilerr
- forbidigo
- interfacebloat
- noctx
- nilnil
Expand Down
8 changes: 5 additions & 3 deletions hack/extractcrd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ func main() {
os.Exit(1)
}

outWriter := os.Stdout

docs := docSeparatorRegexp.Split(string(rawYAMLBytes), -1)

decoder := crdDecoder()
Expand All @@ -85,15 +87,15 @@ func main() {

if wantedCRDName == nil {
if foundAny {
fmt.Println("---")
fmt.Fprintln(outWriter, "---")
}
fmt.Println(doc)
fmt.Fprintln(outWriter, doc)
foundAny = true
continue
} else {
crdName := strings.ToLower(crd.Spec.Names.Plural)
if crdName == *wantedCRDName {
fmt.Println(doc)
fmt.Fprintln(outWriter, doc)
return
}
}
Expand Down
15 changes: 9 additions & 6 deletions hack/prune-junit-xml/prunexml.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"flag"
"fmt"
"io"
"log"
"os"
"regexp"
"strconv"
Expand Down Expand Up @@ -92,12 +93,14 @@ type JUnitFailure struct {
var fuzzNameRegex = regexp.MustCompile(`^(.*)\/fuzz_\d+$`)

func main() {
logger := log.New(os.Stderr, "", 0)

maxTextSize := flag.Int("max-text-size", 1, "maximum size of attribute or text (in MB)")
flag.Parse()

if flag.NArg() > 0 {
for _, path := range flag.Args() {
fmt.Printf("processing junit xml file : %s\n", path)
logger.Printf("processing junit xml file : %s\n", path)
xmlReader, err := os.Open(path)
if err != nil {
panic(err)
Expand All @@ -108,7 +111,7 @@ func main() {
panic(err)
}

pruneXML(suites, *maxTextSize*1e6) // convert MB into bytes (roughly!)
pruneXML(logger, suites, *maxTextSize*1e6) // convert MB into bytes (roughly!)

xmlWriter, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
if err != nil {
Expand All @@ -119,12 +122,12 @@ func main() {
if err != nil {
panic(err)
}
fmt.Println("done.")
logger.Println("done.")
}
}
}

func pruneXML(suites *JUnitTestSuites, maxBytes int) {
func pruneXML(logger *log.Logger, suites *JUnitTestSuites, maxBytes int) {
// filter empty testSuites
filteredSuites := []JUnitTestSuite{}
for _, suite := range suites.Suites {
Expand Down Expand Up @@ -182,14 +185,14 @@ func pruneXML(suites *JUnitTestSuites, maxBytes int) {
for _, testcase := range suite.TestCases {
if testcase.SkipMessage != nil {
if len(testcase.SkipMessage.Message) > maxBytes {
fmt.Printf("clipping skip message in test case : %s\n", testcase.Name)
logger.Printf("clipping skip message in test case : %s\n", testcase.Name)
testcase.SkipMessage.Message = "[... clipped...]" +
testcase.SkipMessage.Message[len(testcase.SkipMessage.Message)-maxBytes:]
}
}
if testcase.Failure != nil {
if len(testcase.Failure.Contents) > maxBytes {
fmt.Printf("clipping failure message in test case : %s\n", testcase.Name)
logger.Printf("clipping failure message in test case : %s\n", testcase.Name)
testcase.Failure.Contents = "[... clipped...]" +
testcase.Failure.Contents[len(testcase.Failure.Contents)-maxBytes:]
}
Expand Down
5 changes: 4 additions & 1 deletion hack/prune-junit-xml/prunexml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ package main
import (
"bufio"
"bytes"
"log"
"os"
"strings"
"testing"

Expand Down Expand Up @@ -92,8 +94,9 @@ func TestPruneXML(t *testing.T) {
<testcase classname="internal/controller/certificaterequests" name="Test_serializeApplyStatus" time="1.610000"></testcase>
</testsuite>
</testsuites>`
logger := log.New(os.Stderr, "", 0)
suites, _ := fetchXML(strings.NewReader(sourceXML))
pruneXML(suites, 32)
pruneXML(logger, suites, 32)
var output bytes.Buffer
writer := bufio.NewWriter(&output)
_ = streamXML(writer, suites)
Expand Down
2 changes: 1 addition & 1 deletion make/config/samplewebhook/sample/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (c *customDNSProviderSolver) Present(ch *v1alpha1.ChallengeRequest) error {
}

// TODO: do something more useful with the decoded configuration
fmt.Printf("Decoded configuration %v", cfg)
fmt.Fprintf(os.Stdout, "Decoded configuration %v", cfg)

// TODO: add code that sets a record in the DNS provider's console
return nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/pki/nameconstraints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ func getExtensionFromPem(pemData string) (pkix.Extension, error) {
if pemData == "" {
return pkix.Extension{}, nil
}

pemData = strings.TrimSpace(pemData)
fmt.Println(pemData)
csrPEM := []byte(pemData)

block, _ := pem.Decode(csrPEM)
Expand Down
10 changes: 2 additions & 8 deletions test/e2e/framework/addon/vault/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ limitations under the License.
package vault

import (
"bytes"
"fmt"
"io"
"net"
"net/http"
"sync"

"github.com/onsi/ginkgo/v2"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/portforward"
Expand All @@ -37,8 +37,6 @@ type proxy struct {

podNamespace, podName string

logs bytes.Buffer

stopCh chan struct{}
mu sync.Mutex
doneCh chan error
Expand All @@ -48,7 +46,6 @@ func newProxy(
clientset kubernetes.Interface,
kubeConfig *rest.Config,
podNamespace, podName string,
vaultCA []byte,
) *proxy {
freePort, err := freePort()
if err != nil {
Expand Down Expand Up @@ -130,7 +127,7 @@ func (p *proxy) start() error {
doneCh <- err
return
default:
fmt.Printf("error while forwarding port: %v\n", err)
fmt.Fprintf(ginkgo.GinkgoWriter, "error while forwarding port: %v\n", err)
}
}
}()
Expand All @@ -139,9 +136,6 @@ func (p *proxy) start() error {
}

func (p *proxy) stop() error {
defer func() {
fmt.Printf("proxy logs: %s\n", p.logs.String())
}()
close(p.stopCh)

p.mu.Lock()
Expand Down
1 change: 0 additions & 1 deletion test/e2e/framework/addon/vault/vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,6 @@ func (v *Vault) Setup(cfg *config.Config, leaderData ...internal.AddonTransferab
v.Base.Details().KubeConfig,
v.Namespace,
fmt.Sprintf("%s-0", v.chart.ReleaseName),
vaultCA,
)

v.details.URL = fmt.Sprintf("https://%s", net.JoinHostPort(dnsName, "8200"))
Expand Down
4 changes: 3 additions & 1 deletion test/integration/webhook/dynamic_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ func TestDynamicSource_leaderelection(t *testing.T) {
if err := mgr.Add(&tls.DynamicSource{
DNSNames: []string{"example.com"},
Authority: &testAuthority{
t: t,
id: fmt.Sprintf("manager-%d", i),
started: &started,
},
Expand Down Expand Up @@ -280,6 +281,7 @@ func TestDynamicSource_leaderelection(t *testing.T) {
}

type testAuthority struct {
t *testing.T
id string
started *int64
}
Expand All @@ -289,7 +291,7 @@ func (m *testAuthority) Run(ctx context.Context) error {
return nil // context was cancelled, we are shutting down
}

fmt.Println("Starting authority with id", m.id)
m.t.Log("Starting authority with id", m.id)
atomic.AddInt64(m.started, 1)
<-ctx.Done()
return nil
Expand Down

0 comments on commit 8ea7cbc

Please sign in to comment.