Files
mtusi2026lab5/cmd/reconcile/main_test.go
T

36 lines
1.1 KiB
Go

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())
}
}