Доработайте публикацию и сверку вложений по итогам ревью
This commit is contained in:
@@ -43,7 +43,7 @@ func run(ctx context.Context, args []string, out, errOut io.Writer) int {
|
||||
fmt.Fprintln(errOut, "reconcile: no positional arguments allowed; --grace must be at least 2m")
|
||||
return 2
|
||||
}
|
||||
dbConfig, err := config.LoadMigrate(os.LookupEnv)
|
||||
databaseURL, err := config.LoadDatabaseURL(os.LookupEnv)
|
||||
if err != nil {
|
||||
fmt.Fprintln(errOut, "configuration error:", err)
|
||||
return 2
|
||||
@@ -54,12 +54,12 @@ func run(ctx context.Context, args []string, out, errOut io.Writer) int {
|
||||
fmt.Fprintln(errOut, "configuration error:", err)
|
||||
return 2
|
||||
}
|
||||
blobs, err := s3store.New(s3Config.Endpoint, s3Config.Region, s3Config.Bucket, s3Config.AccessKey, s3Config.SecretKey)
|
||||
blobs, err := s3store.New(s3Config)
|
||||
if err != nil {
|
||||
fmt.Fprintln(errOut, "configuration error:", err)
|
||||
return 2
|
||||
}
|
||||
db, err := postgres.NewPool(ctx, dbConfig.DatabaseURL, 10)
|
||||
db, err := postgres.NewPool(ctx, databaseURL, 10)
|
||||
if err != nil {
|
||||
fmt.Fprintln(errOut, "reconcile:", err)
|
||||
return 1
|
||||
@@ -76,7 +76,8 @@ func run(ctx context.Context, args []string, out, errOut io.Writer) int {
|
||||
defer cancel()
|
||||
encoder := json.NewEncoder(out)
|
||||
var outputErr error
|
||||
stats, runErr := r.Run(scanCtx, *apply, *deep, func(f attachment.Finding) {
|
||||
options := attachment.ReconcileOptions{Apply: *apply, Deep: *deep}
|
||||
stats, runErr := r.Run(scanCtx, options, func(f attachment.Finding) {
|
||||
if outputErr == nil {
|
||||
outputErr = encoder.Encode(f)
|
||||
if outputErr != nil {
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestReconcileDoesNotValidateUnusedLogging(t *testing.T) {
|
||||
for key, value := range map[string]string{
|
||||
"DATABASE_URL_FILE": "postgres://test:test@127.0.0.1:5432/messenger?sslmode=disable",
|
||||
"S3_ACCESS_KEY_ID_FILE": "test-access",
|
||||
"S3_SECRET_ACCESS_KEY_FILE": "test-secret",
|
||||
} {
|
||||
path := filepath.Join(t.TempDir(), key)
|
||||
if err := os.WriteFile(path, []byte(value), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Setenv(key, path)
|
||||
}
|
||||
t.Setenv("S3_ENDPOINT", "http://127.0.0.1:8333")
|
||||
t.Setenv("S3_REGION", "us-east-1")
|
||||
t.Setenv("S3_BUCKET", "attachments")
|
||||
t.Setenv("APP_LOG_LEVEL", "not-a-log-level")
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel() // Stop before dialing: only configuration relevant to this CLI is checked.
|
||||
var out, errOut bytes.Buffer
|
||||
code := run(ctx, nil, &out, &errOut)
|
||||
if code != 1 || strings.Contains(errOut.String(), "APP_LOG_LEVEL") {
|
||||
t.Fatalf("unused logging prevented the database operation: code=%d error=%s", code, errOut.String())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user