mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 18:07:31 +00:00
chore: test server for direct resource access
This commit is contained in:
@@ -5,7 +5,9 @@ import (
|
||||
_ "embed"
|
||||
"errors"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
@@ -26,7 +28,7 @@ var (
|
||||
defaultConfig []byte
|
||||
)
|
||||
|
||||
func New(out io.Writer, in io.Reader, args []string) *cobra.Command {
|
||||
func New(out io.Writer, in io.Reader, args []string, server chan<- *start.Server) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "zitadel",
|
||||
Short: "The ZITADEL CLI lets you interact with ZITADEL",
|
||||
@@ -51,9 +53,9 @@ func New(out io.Writer, in io.Reader, args []string) *cobra.Command {
|
||||
admin.New(), //is now deprecated, remove later on
|
||||
initialise.New(),
|
||||
setup.New(),
|
||||
start.New(),
|
||||
start.NewStartFromInit(),
|
||||
start.NewStartFromSetup(),
|
||||
start.New(server),
|
||||
start.NewStartFromInit(server),
|
||||
start.NewStartFromSetup(server),
|
||||
key.New(),
|
||||
)
|
||||
|
||||
@@ -69,3 +71,30 @@ func initConfig() {
|
||||
logging.WithFields("file", file).OnError(err).Warn("unable to read config file")
|
||||
}
|
||||
}
|
||||
|
||||
type TestServer struct {
|
||||
*start.Server
|
||||
wg sync.WaitGroup
|
||||
}
|
||||
|
||||
func (s *TestServer) Done() {
|
||||
s.Shutdown <- os.Interrupt
|
||||
s.wg.Wait()
|
||||
}
|
||||
|
||||
func NewTestServer(args []string) *TestServer {
|
||||
testServer := new(TestServer)
|
||||
server := make(chan *start.Server, 1)
|
||||
|
||||
testServer.wg.Add(1)
|
||||
go func(wg *sync.WaitGroup) {
|
||||
defer wg.Done()
|
||||
|
||||
cmd := New(os.Stdout, os.Stdin, args, server)
|
||||
cmd.SetArgs(args)
|
||||
logging.OnError(cmd.Execute()).Fatal()
|
||||
}(&testServer.wg)
|
||||
|
||||
testServer.Server = <-server
|
||||
return testServer
|
||||
}
|
||||
|
Reference in New Issue
Block a user