github-vet / github-vet/rangeloop-pointer-findings

JoshVanL/k8s-subject-access-delegation: pkg/end_to_end/test/test.go; 60 LoC

Open
#16,292 0 comments 0 reactions 0 assignees View on GitHub
fresh medium
Dominant language
No language data
Stars
0
Forks
0
PR merge metrics
PR metrics pending

Description

Found a possible issue in [JoshVanL/k8s-subject-access-delegation](https://www.github.com/JoshVanL/k8s-subject-access-delegation) at [pkg/end_to_end/test/test.go](https://github.com/JoshVanL/k8s-subject-access-delegation/blob/6ae2a8c7050d4d376ab09cbeeeb020cdcb7c627b/pkg/end_to_end/test/test.go#L103-L162)

Below is the message reported by the analyzer for this snippet of code. Beware that the analyzer only reports the first issue it finds, so please do not limit your consideration to the contents of the below message.

> range-loop variable cmd used in defer or goroutine at line 113

[Click here to see the code in its original context.](https://github.com/JoshVanL/k8s-subject-access-delegation/blob/6ae2a8c7050d4d376ab09cbeeeb020cdcb7c627b/pkg/end_to_end/test/test.go#L103-L162)

Click here to show the 60 line(s) of Go which triggered the analyzer.

```go
for _, cmd := range block.Commands {
t.log.Infof("Running command: $ %s", cmd.Command.String())

var wg sync.WaitGroup

wg.Add(3)

time.Sleep(time.Second * time.Duration(cmd.Delay))

go func() {
if err := cmd.Command.Run(); err != nil {
result = multierror.Append(result, err)
}
if cmd.Background {
backgroundCmds = append(backgroundCmds, cmd.Command)
}

wg.Done()
}()

go func() {
for str := range cmd.Command.Stdout() {
cmd.stdout = append(cmd.stdout, str)
fmt.Printf("%s\n", str)
}
wg.Done()
}()

go func() {
for str := range cmd.Command.Stderr() {
cmd.stdout = append(cmd.stdout, str)
fmt.Printf("%s\n", str)
}
wg.Done()
}()

if cmd.Background {
time.Sleep(time.Second * 5)
} else {
wg.Wait()
}

for _, condition := range cmd.SplitString {
if condition.TestConditon(cmd.stdout) {
t.log.Infof("Condition passed.")
} else {
err := fmt.Errorf("Condition failed in test block '%s': %s", block.Name, condition.Expected(cmd.stdout))
result = multierror.Append(result, err)
}
}

for _, condition := range cmd.String {
if condition.TestConditon(cmd.stdout) {
t.log.Infof("Condition passed.")
} else {
err := fmt.Errorf("Condition failed in test block '%s': %s", block.Name, condition.Expected(cmd.stdout))
result = multierror.Append(result, err)
}
}
}

```

Leave a reaction on this issue to contribute to the project by classifying this instance as a **Bug** :-1:, **Mitigated** :+1:, or **Desirable Behavior** :rocket:
See the descriptions of the classifications [here](https://github.com/github-vet/rangeclosure-findings#how-can-i-help) for more information.

commit ID: 6ae2a8c7050d4d376ab09cbeeeb020cdcb7c627b

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.