kubernetes/kubernetes

Refactoring / cleanup: too many util pkgs for testing, some are dumb

Open

#117,385 opened on Apr 15, 2023

View on GitHub
 (8 comments) (0 reactions) (1 assignee)Go (43,066 forks)batch import
help wantedkind/cleanuppriority/backlogsig/architecturetriage/accepted

Repository metrics

Stars
 (122,268 stars)
PR merge metrics
 (Avg merge 28d 17h) (343 merged PRs in 30d)

Description

Examples: k8s.io/client-go/util/testing includes:

func MkTmpdir(prefix string) (string, error) {
        tmpDir, err := os.MkdirTemp(os.TempDir(), prefix)
        if err != nil {
                return "", err
        }
        return tmpDir, nil
}

I think that every caller of that can be replaced with os.MkdirTemp("", prefix).

It would be cool if someone went through ALL of the "testing" dirs to see if there are ACTUALLY USEFUL test helper functions. For functions that are called less than 10 times, maybe just copy them to the respective places (if they are simple). E.g. the same file as above has:

func MkTmpdirOrDie(prefix string) string {
        tmpDir, err := MkTmpdir(prefix)
        if err != nil {
                panic(err)
        }
        return tmpDir
}

...which is called just 5 times from 3 files. Kill it and copy to those pkgs.

If there are enough non-trivial, useful things, we can conside k/utils/testing or something?

Contributor guide