Feat v0.8.2 capability negotiation (#69)
All checks were successful
CI/CD / detect-changes (push) Successful in 4s
CI/CD / test-frontend (push) Has been skipped
CI/CD / test-runners (push) Has been skipped
CI/CD / e2e-smoke (push) Has been skipped
CI/CD / test-go-pg (push) Successful in 2m47s
CI/CD / test-sqlite (push) Successful in 2m52s
CI/CD / build-and-deploy (push) Successful in 30s
All checks were successful
CI/CD / detect-changes (push) Successful in 4s
CI/CD / test-frontend (push) Has been skipped
CI/CD / test-runners (push) Has been skipped
CI/CD / e2e-smoke (push) Has been skipped
CI/CD / test-go-pg (push) Successful in 2m47s
CI/CD / test-sqlite (push) Successful in 2m52s
CI/CD / build-and-deploy (push) Successful in 30s
Co-authored-by: Jeffrey Smith <jasafpro@gmail.com> Co-committed-by: Jeffrey Smith <jasafpro@gmail.com>
This commit was merged in pull request #69.
This commit is contained in:
75
server/sandbox/settings_module_test.go
Normal file
75
server/sandbox/settings_module_test.go
Normal file
@@ -0,0 +1,75 @@
|
||||
package sandbox
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"go.starlark.net/starlark"
|
||||
|
||||
"armature/store"
|
||||
)
|
||||
|
||||
func execWithSettings(t *testing.T, caps map[string]bool, script string) (*Result, error) {
|
||||
t.Helper()
|
||||
ctx := context.Background()
|
||||
mod := BuildSettingsModule(ctx, store.Stores{}, "", "", "", caps)
|
||||
sb := New(DefaultConfig())
|
||||
return sb.Exec(ctx, "test.star", script, map[string]starlark.Value{
|
||||
"settings": mod,
|
||||
})
|
||||
}
|
||||
|
||||
func TestHasCapability_True(t *testing.T) {
|
||||
caps := map[string]bool{"postgres": true, "pgvector": true}
|
||||
result, err := execWithSettings(t, caps, `
|
||||
result = settings.has_capability("pgvector")
|
||||
`)
|
||||
if err != nil {
|
||||
t.Fatalf("exec error: %v", err)
|
||||
}
|
||||
v := result.Globals["result"]
|
||||
if v != starlark.True {
|
||||
t.Errorf("has_capability('pgvector') = %v, want True", v)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHasCapability_False(t *testing.T) {
|
||||
caps := map[string]bool{"postgres": true, "pgvector": false}
|
||||
result, err := execWithSettings(t, caps, `
|
||||
result = settings.has_capability("pgvector")
|
||||
`)
|
||||
if err != nil {
|
||||
t.Fatalf("exec error: %v", err)
|
||||
}
|
||||
v := result.Globals["result"]
|
||||
if v != starlark.False {
|
||||
t.Errorf("has_capability('pgvector') = %v, want False", v)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHasCapability_UnknownCap(t *testing.T) {
|
||||
caps := map[string]bool{"postgres": true}
|
||||
result, err := execWithSettings(t, caps, `
|
||||
result = settings.has_capability("gpu")
|
||||
`)
|
||||
if err != nil {
|
||||
t.Fatalf("exec error: %v", err)
|
||||
}
|
||||
v := result.Globals["result"]
|
||||
if v != starlark.False {
|
||||
t.Errorf("has_capability('gpu') = %v, want False", v)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHasCapability_NilCaps(t *testing.T) {
|
||||
result, err := execWithSettings(t, nil, `
|
||||
result = settings.has_capability("postgres")
|
||||
`)
|
||||
if err != nil {
|
||||
t.Fatalf("exec error: %v", err)
|
||||
}
|
||||
v := result.Globals["result"]
|
||||
if v != starlark.False {
|
||||
t.Errorf("has_capability with nil caps = %v, want False", v)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user