47 lines
1.5 KiB
Go
47 lines
1.5 KiB
Go
package main
|
|
|
|
import (
|
|
"errors"
|
|
"io"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestDispatcherCommandDoesNotExposeLegacyTenantQueueFlags(t *testing.T) {
|
|
cmd := newDispatcherCommand()
|
|
for _, name := range []string{"tenant-key", "consume"} {
|
|
if cmd.Flags().Lookup(name) != nil {
|
|
t.Errorf("legacy flag --%s is still exposed", name)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestDispatcherRejectsNonMockExecutionBeforeOpeningResources(t *testing.T) {
|
|
for _, mode := range []string{"mixed", "real"} {
|
|
t.Run(mode, func(t *testing.T) {
|
|
dbPath := filepath.Join(t.TempDir(), "must-not-open.sqlite")
|
|
t.Setenv("SIP_GO_AGENT_MODE", mode)
|
|
t.Setenv("DISPATCHER_DB", dbPath)
|
|
t.Setenv("RABBITMQ_URL", "amqp://127.0.0.1:1/")
|
|
t.Setenv("DISPATCHER_GRPC_LISTEN", "")
|
|
t.Setenv("DISPATCHER_AGENT_ENDPOINTS_FILE", "")
|
|
t.Setenv("GO_SIP_OSS_ACCESS_KEY_ID", "local-test-placeholder")
|
|
t.Setenv("GO_SIP_OSS_ACCESS_KEY_SECRET", "local-test-placeholder")
|
|
cmd := newDispatcherCommand()
|
|
cmd.SetArgs([]string{"--config", filepath.Join("..", "..", "deploys", "config", "dispatcher.json.example")})
|
|
cmd.SilenceUsage, cmd.SilenceErrors = true, true
|
|
cmd.SetOut(io.Discard)
|
|
cmd.SetErr(io.Discard)
|
|
err := cmd.Execute()
|
|
if err == nil || !strings.Contains(err.Error(), "isolated Mock only") {
|
|
t.Fatalf("%s dispatcher reached resources instead of refusing unapproved execution: %v", mode, err)
|
|
}
|
|
if _, err := os.Stat(dbPath); !errors.Is(err, os.ErrNotExist) {
|
|
t.Fatalf("%s dispatcher opened a business DB before authorization: %v", mode, err)
|
|
}
|
|
})
|
|
}
|
|
}
|