Round 2 follow-up to 907c5fa. Closes residual CodeRabbit findings.
Test infra:
- Replaced must* test helpers across cmd_apply_test, cmd_file_sync_test,
cmd_vm_test, cmd_ci_test, cmd_repo_test, cmd_wizard_test,
cmd_api_testgen_test, cmd_workflow_test, secret_test, coverage_test,
scan_secrets_test, snapshot_test with stdlib checks.
- Deleted stale package-level test_helpers_test.go files that only
supported the old must* pattern.
- AX-6 maintained: no testify Go imports / go.mod requires. Remaining
go.sum testify entries are transitive checksums after go mod tidy.
Module graph:
- CLI imports switched back to Cobra-compatible
dappco.re/go/core/cli/pkg/cli module + replacements for private
vanity modules. GOWORK=off resolves cleanly under isolated cache.
- locales/embed.go / go.sum: i18n checksum + go mod tidy clean.
Verified-but-already-correct (no code change needed):
- cmd/dev/service.go: no-op core.Result{OK:true} + prompt type assertion
- cmd/workspace/config.go: filepath.Abs normalisation + fmt.Errorf
wrapping
- tests/cli/devops/main.go: raw walk/read errors wrapped
- tests/cli/devops/Taskfile.yaml: strict shell flags
- cmd/dev/cmd_issues.go + cmd_reviews.go: import grouping (after CLI
module correction)
Verification: gofmt clean, GOWORK=off go vet + go test -count=1 ./...
pass with explicit cache paths.
Closes residual findings on https://github.com/dAppCore/go-devops/pull/2
Co-authored-by: Codex <noreply@openai.com>
100 lines
2.9 KiB
Go
100 lines
2.9 KiB
Go
package devkit
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
)
|
|
|
|
func TestScanSecrets_Good(t *testing.T) {
|
|
originalRunner := scanSecretsRunner
|
|
t.Cleanup(func() {
|
|
scanSecretsRunner = originalRunner
|
|
})
|
|
|
|
scanSecretsRunner = func(dir string) ([]byte, error) {
|
|
if dir != "/tmp/project" {
|
|
t.Fatalf("dir = %q, want /tmp/project", dir)
|
|
}
|
|
return []byte(`RuleID,File,StartLine,StartColumn,Description,Match
|
|
github-token,config.yml,12,4,GitHub token detected,ghp_exampletoken1234567890
|
|
aws-access-key-id,creds.txt,7,1,AWS access key detected,AKIA1234567890ABCDEF
|
|
`), nil
|
|
}
|
|
|
|
findings, err := ScanSecrets("/tmp/project")
|
|
if err != nil {
|
|
t.Fatalf("scan secrets: %v", err)
|
|
}
|
|
if len(findings) != 2 {
|
|
t.Fatalf("findings length = %d, want 2", len(findings))
|
|
}
|
|
|
|
if findings[0].Rule != "github-token" {
|
|
t.Fatalf("findings[0].Rule = %q, want github-token", findings[0].Rule)
|
|
}
|
|
if findings[0].Path != "config.yml" {
|
|
t.Fatalf("findings[0].Path = %q, want config.yml", findings[0].Path)
|
|
}
|
|
if findings[0].Line != 12 {
|
|
t.Fatalf("findings[0].Line = %d, want 12", findings[0].Line)
|
|
}
|
|
if findings[0].Column != 4 {
|
|
t.Fatalf("findings[0].Column = %d, want 4", findings[0].Column)
|
|
}
|
|
if findings[0].Snippet != "ghp_exampletoken1234567890" {
|
|
t.Fatalf("findings[0].Snippet = %q, want ghp_exampletoken1234567890", findings[0].Snippet)
|
|
}
|
|
|
|
if findings[1].Rule != "aws-access-key-id" {
|
|
t.Fatalf("findings[1].Rule = %q, want aws-access-key-id", findings[1].Rule)
|
|
}
|
|
if findings[1].Path != "creds.txt" {
|
|
t.Fatalf("findings[1].Path = %q, want creds.txt", findings[1].Path)
|
|
}
|
|
if findings[1].Line != 7 {
|
|
t.Fatalf("findings[1].Line = %d, want 7", findings[1].Line)
|
|
}
|
|
if findings[1].Column != 1 {
|
|
t.Fatalf("findings[1].Column = %d, want 1", findings[1].Column)
|
|
}
|
|
if findings[1].Snippet != "AKIA1234567890ABCDEF" {
|
|
t.Fatalf("findings[1].Snippet = %q, want AKIA1234567890ABCDEF", findings[1].Snippet)
|
|
}
|
|
}
|
|
|
|
func TestScanSecrets_ReportsFindingsOnExitError_Good(t *testing.T) {
|
|
originalRunner := scanSecretsRunner
|
|
t.Cleanup(func() {
|
|
scanSecretsRunner = originalRunner
|
|
})
|
|
|
|
scanSecretsRunner = func(dir string) ([]byte, error) {
|
|
return []byte(`rule_id,file,start_line,start_column,description,match
|
|
token,test.txt,3,2,Token detected,secret-value
|
|
`), errors.New("exit status 1")
|
|
}
|
|
|
|
findings, err := ScanSecrets("/tmp/project")
|
|
if err != nil {
|
|
t.Fatalf("scan secrets: %v", err)
|
|
}
|
|
if len(findings) != 1 {
|
|
t.Fatalf("findings length = %d, want 1", len(findings))
|
|
}
|
|
if findings[0].Rule != "token" {
|
|
t.Fatalf("findings[0].Rule = %q, want token", findings[0].Rule)
|
|
}
|
|
if findings[0].Line != 3 {
|
|
t.Fatalf("findings[0].Line = %d, want 3", findings[0].Line)
|
|
}
|
|
if findings[0].Column != 2 {
|
|
t.Fatalf("findings[0].Column = %d, want 2", findings[0].Column)
|
|
}
|
|
}
|
|
|
|
func TestParseGitleaksCSV_Bad(t *testing.T) {
|
|
_, err := parseGitleaksCSV([]byte("rule_id,file,start_line\nunterminated,\"broken"))
|
|
if err == nil {
|
|
t.Fatal("expected parse error")
|
|
}
|
|
}
|