1
0
mirror of https://github.com/quay/quay.git synced 2026-01-26 06:21:37 +03:00
Files
quay/config-tool/pkg/lib/fieldgroups/distributedstorage/distributedstorage_test.go
Deirdre Malone e8790e844d chore(deps): update go version to 1.24.8 (PROJQUAY-9842) (#4653)
Update go version 1.24.8
Fix for CVE-2025-58183
2025-12-02 15:54:36 +00:00

79 lines
1.6 KiB
Go

package distributedstorage
import (
"fmt"
"testing"
"github.com/quay/quay/config-tool/pkg/lib/shared"
"gopkg.in/yaml.v3"
)
// TestValidateSchema tests the ValidateSchema function
func TestValidateDistributedStorage(t *testing.T) {
var config = []byte(`DISTRIBUTED_STORAGE_CONFIG:
local_us:
- RadosGWStorage
- access_key: X
bucket_name: quay-datastore
hostname: jonathan-registry.com
is_secure: true
port: 443
secret_key: X
storage_path: /datastorage/registry`)
// Define test data
var tests = []struct {
name string
config map[string]interface{}
want string
}{
{name: "MissingStorageConfig", config: map[string]interface{}{}, want: "invalid"},
}
// Iterate through tests
for _, tt := range tests {
// Run specific test
t.Run(tt.name, func(t *testing.T) {
// Load config into struct
var conf map[string]interface{}
if err := yaml.Unmarshal(config, &conf); err != nil {
fmt.Println(err.Error())
}
// Get validation result
fg, err := NewDistributedStorageFieldGroup(conf)
if err != nil && tt.want != "typeError" {
t.Errorf("Expected %s. Received %s", tt.want, err.Error())
}
opts := shared.Options{
Mode: "testing",
}
validationErrors := fg.Validate(opts)
// Get result type
received := ""
if len(validationErrors) == 0 {
received = "valid"
} else {
received = "invalid"
}
// Compare with expected
if tt.want != received {
t.Errorf("Expected %s. Received %s", tt.want, received)
for _, err := range validationErrors {
t.Errorf("%s", err.Message)
}
}
})
}
}