Files
grafana/pkg/services/apiserver/options/storage_test.go
T
Stephanie Hingtgen 1091054c25 Unistore: Wire up inline secure values (#110072)
* Unistore: Wire up inline secure values

* add validation and test

* linter
2025-08-25 02:48:49 -06:00

86 lines
2.7 KiB
Go

package options
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestStorageOptions_Validate(t *testing.T) {
tests := []struct {
name string
Opts StorageOptions
wantErr bool
}{
{
name: "with unified storage grpc and no auth token",
Opts: StorageOptions{
StorageType: StorageTypeUnifiedGrpc,
},
wantErr: true,
},
{
name: "with unified storage grpc and auth info",
Opts: StorageOptions{
StorageType: StorageTypeUnifiedGrpc,
Address: "localhost:10000",
GrpcClientAuthenticationToken: "1234",
GrpcClientAuthenticationTokenExchangeURL: "http://localhost:8080",
GrpcClientAuthenticationTokenNamespace: "*",
},
wantErr: false,
},
{
name: "with secrets manager grpc client and no server address",
Opts: StorageOptions{
StorageType: StorageTypeUnifiedGrpc,
Address: "localhost:10000",
GrpcClientAuthenticationToken: "1234",
GrpcClientAuthenticationTokenExchangeURL: "http://localhost:8080",
GrpcClientAuthenticationTokenNamespace: "*",
SecretsManagerGrpcClientEnable: true,
},
wantErr: true,
},
{
name: "with secrets manager grpc client and no server ca file",
Opts: StorageOptions{
StorageType: StorageTypeUnifiedGrpc,
Address: "localhost:10000",
GrpcClientAuthenticationToken: "1234",
GrpcClientAuthenticationTokenExchangeURL: "http://localhost:8080",
GrpcClientAuthenticationTokenNamespace: "*",
SecretsManagerGrpcClientEnable: true,
SecretsManagerGrpcServerAddress: "localhost:10000",
SecretsManagerGrpcServerUseTLS: true,
},
wantErr: true,
},
{
name: "with secrets manager grpc client and server ca file",
Opts: StorageOptions{
StorageType: StorageTypeUnifiedGrpc,
Address: "localhost:10000",
GrpcClientAuthenticationToken: "1234",
GrpcClientAuthenticationTokenExchangeURL: "http://localhost:8080",
GrpcClientAuthenticationTokenNamespace: "*",
SecretsManagerGrpcClientEnable: true,
SecretsManagerGrpcServerAddress: "localhost:10000",
SecretsManagerGrpcServerUseTLS: true,
SecretsManagerGrpcServerTLSCAFile: "ca.crt",
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
errs := tt.Opts.Validate()
if tt.wantErr {
assert.NotEmpty(t, errs)
return
}
assert.Empty(t, errs)
})
}
}