From 384dff5e52a73619efb4dbc5e617e78067466ce3 Mon Sep 17 00:00:00 2001 From: dougal Date: Thu, 9 Jul 2026 15:18:46 +0100 Subject: [PATCH] docs/data: export backend data --- backend/info/info.go | 48 ++++++++++++++++++++++++++++++++ backend/info/info_test.go | 55 +++++++++++++++++++++++++++++++++++++ docs/data/backends/embed.go | 7 +++++ 3 files changed, 110 insertions(+) create mode 100644 backend/info/info.go create mode 100644 backend/info/info_test.go create mode 100644 docs/data/backends/embed.go diff --git a/backend/info/info.go b/backend/info/info.go new file mode 100644 index 000000000..2a60b03a9 --- /dev/null +++ b/backend/info/info.go @@ -0,0 +1,48 @@ +// Package info provides info about a backend +package info + +import ( + "fmt" + "strings" + + "github.com/rclone/rclone/docs/data/backends" + "gopkg.in/yaml.v3" +) + +// BackendConfig defines information about the backend +type BackendConfig struct { + Backend string `yaml:"backend"` + Name string `yaml:"name"` + Tier string `yaml:"tier"` + Maintainers string `yaml:"maintainers"` + FeaturesScore int `yaml:"features_score"` + IntegrationTests string `yaml:"integration_tests"` + DataIntegrity string `yaml:"data_integrity"` + Performance string `yaml:"performance"` + Adoption string `yaml:"adoption"` + Docs string `yaml:"docs"` + Security string `yaml:"security"` + Virtual bool `yaml:"virtual"` + Remote string `yaml:"remote"` + Features []string `yaml:"features"` + Hashes []string `yaml:"hashes"` + Precision int `yaml:"precision"` +} + +// GetBackendConfig from docs/data/backends +func GetBackendConfig(name string) (*BackendConfig, error) { + fileName := fmt.Sprintf("%s.yaml", strings.ToLower(name)) + + data, err := backends.BackendFS.ReadFile(fileName) + if err != nil { + return nil, fmt.Errorf("could not find backend file %s: %w", fileName, err) + } + + var config BackendConfig + err = yaml.Unmarshal(data, &config) + if err != nil { + return nil, fmt.Errorf("failed to parse YAML in %s: %w", fileName, err) + } + + return &config, nil +} diff --git a/backend/info/info_test.go b/backend/info/info_test.go new file mode 100644 index 000000000..3b04f06c6 --- /dev/null +++ b/backend/info/info_test.go @@ -0,0 +1,55 @@ +package info + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestGetBackendConfig(t *testing.T) { + // s3 tier test + conf, err := GetBackendConfig("S3") + require.NoError(t, err, "failed to load s3.yaml") + require.NotNil(t, conf, "config should not be nil") + + assert.Equal(t, "Tier 1", conf.Tier, "s3 should be tier 1") + + // memory backend (unlikely to change) + conf, err = GetBackendConfig("memory") + require.NoError(t, err, "failed to load s3.yaml") + require.NotNil(t, conf, "config should not be nil") + + expectedMemoryConfig := &BackendConfig{ + Backend: "memory", + Name: "Memory", + Tier: "Tier 1", + Maintainers: "Core", + FeaturesScore: 4, + IntegrationTests: "Passing", + DataIntegrity: "Hash", + Performance: "High", + Adoption: "Widely used", + Docs: "Full", + Security: "High", + Virtual: false, + Remote: ":memory:", + Features: []string{ + "BucketBased", + "BucketBasedRootOK", + "Copy", + "ListP", + "ListR", + "PutStream", + "ReadMimeType", + "WriteMimeType", + }, + Hashes: []string{ + "md5", + }, + Precision: 1, + } + + assert.Equal(t, expectedMemoryConfig, conf, "parsed memory.yaml should match") + +} diff --git a/docs/data/backends/embed.go b/docs/data/backends/embed.go new file mode 100644 index 000000000..6d00c636b --- /dev/null +++ b/docs/data/backends/embed.go @@ -0,0 +1,7 @@ +// Package backends provides embedded backend config +package backends + +import "embed" + +//go:embed *.yaml +var BackendFS embed.FS