Files
summercms/modules/lagoon/attach/infra_smoke_test.go
Jakub Zych 2382040b25 feat(19.3-03): summer.yaml build.tags and the summercms_s3 tag that links the S3 uploads driver
- Manifest.Tags from build.tags (^[a-z0-9_]+$, duplicates dropped), round-tripped by SaveManifest
- summer build passes -tags=<list> through goBuildArgs and prints the build tags line
- attach: s3blob imported only by s3_on.go (//go:build summercms_s3); an untagged binary
  refuses an s3:// bucket_url naming the tag, build.tags and -tags
- go mod tidy adds the AWS SDK v2 modules as indirect requirements
- storage, modules, scaffolding, configuration and scaling docs plus the lagoon README
2026-10-15 18:07:05 +02:00

61 lines
1.7 KiB
Go

package attach
import (
"os"
"path/filepath"
"strings"
"testing"
"git.golem15.com/golem15/summercms/modules/compass"
)
// openTestConfig writes storage.yaml into a temp config dir and opens it.
func openTestConfig(t *testing.T, storageYAML string) *compass.Config {
t.Helper()
dir := t.TempDir()
if err := os.WriteFile(filepath.Join(dir, "storage.yaml"), []byte(storageYAML), 0o644); err != nil {
t.Fatal(err)
}
cfg, err := compass.Open(compass.Options{
Dir: dir,
Env: "development",
Environ: []string{"SUMMER_ENV=development"},
})
if err != nil {
t.Fatal(err)
}
return cfg
}
// TestOpenBucketS3Smoke runs in both tag modes: without summercms_s3 an
// s3:// bucket_url fails boot naming the tag, with it the bucket opens
// (s3blob connects lazily, so no network is needed).
func TestOpenBucketS3Smoke(t *testing.T) {
t.Setenv("AWS_ACCESS_KEY_ID", "smoke-access-key")
t.Setenv("AWS_SECRET_ACCESS_KEY", "smoke-secret-key")
t.Setenv("AWS_REGION", "us-east-1")
t.Setenv("AWS_EC2_METADATA_DISABLED", "true")
t.Cleanup(func() { setPublicPathPrefix(defaultPublicPathPrefix) })
cfg := openTestConfig(t, "uploads:\n bucket_url: \"s3://smoke-bucket?region=us-east-1\"\n")
bucket, err := OpenBucket(t.Context(), cfg)
if !s3Enabled {
if err == nil {
_ = bucket.Close()
t.Fatal("OpenBucket opened s3:// without the summercms_s3 tag")
}
for _, want := range []string{S3BuildTag, "build.tags", "-tags " + S3BuildTag} {
if !strings.Contains(err.Error(), want) {
t.Fatalf("error %q does not name %q", err, want)
}
}
return
}
if err != nil {
t.Fatalf("OpenBucket with the summercms_s3 tag: %v", err)
}
if err := bucket.Close(); err != nil {
t.Fatalf("close: %v", err)
}
}