77 "github.com/stretchr/testify/assert"
88 "github.com/stretchr/testify/require"
99 "github.com/webhookx-io/webhookx/app"
10- "github.com/webhookx-io/webhookx/cmd"
1110 "github.com/webhookx-io/webhookx/db"
1211 "github.com/webhookx-io/webhookx/plugins/webhookx_signature"
1312 "github.com/webhookx-io/webhookx/test/helper"
@@ -55,7 +54,7 @@ var _ = Describe("admin", Ordered, func() {
5554 })
5655
5756 It ("sanity" , func () {
58- output , err := executeCommand (cmd . NewRootCmd (), "admin" , "sync" , "../fixtures/webhookx.yml" )
57+ output , err := executeCommand ("admin" , "sync" , "../fixtures/webhookx.yml" , "--addr" , helper . AdminHttpURL )
5958 assert .Nil (GinkgoT (), err )
6059 assert .Equal (GinkgoT (), "sync successfully\n " , output )
6160
@@ -109,7 +108,7 @@ var _ = Describe("admin", Ordered, func() {
109108 err = db .Sources .Insert (context .TODO (), & source )
110109 assert .NoError (GinkgoT (), err )
111110
112- _ , err = executeCommand (cmd . NewRootCmd (), "admin" , "sync" , "../fixtures/webhookx.yml" )
111+ _ , err = executeCommand ("admin" , "sync" , "../fixtures/webhookx.yml" , "--addr" , helper . AdminHttpURL )
113112 assert .Nil (GinkgoT (), err )
114113
115114 dbEndpoint , err := db .Endpoints .Get (context .TODO (), endpoint .ID )
@@ -122,14 +121,14 @@ var _ = Describe("admin", Ordered, func() {
122121 })
123122
124123 It ("entities id should not be changed after multiple syncs" , func () {
125- _ , err := executeCommand (cmd . NewRootCmd (), "admin" , "sync" , "../fixtures/webhookx.yml" )
124+ _ , err := executeCommand ("admin" , "sync" , "../fixtures/webhookx.yml" , "--addr" , helper . AdminHttpURL )
126125 assert .Nil (GinkgoT (), err )
127126
128127 endpoint1 , err := db .Endpoints .Select (context .TODO (), "name" , "default-endpoint" )
129128 assert .NoError (GinkgoT (), err )
130129 assert .NotNil (GinkgoT (), endpoint1 )
131130
132- _ , err = executeCommand (cmd . NewRootCmd (), "admin" , "sync" , "../fixtures/webhookx.yml" )
131+ _ , err = executeCommand ("admin" , "sync" , "../fixtures/webhookx.yml" , "--addr" , helper . AdminHttpURL )
133132 assert .Nil (GinkgoT (), err )
134133
135134 endpoint2 , err := db .Endpoints .Select (context .TODO (), "name" , "default-endpoint" )
@@ -141,17 +140,17 @@ var _ = Describe("admin", Ordered, func() {
141140
142141 Context ("errors" , func () {
143142 It ("missing filename" , func () {
144- output , err := executeCommand (cmd . NewRootCmd (), "admin" , "sync" )
143+ output , err := executeCommand ("admin" , "sync" , "--addr" , helper . AdminHttpURL )
145144 assert .NotNil (GinkgoT (), err )
146145 assert .Equal (GinkgoT (), "Error: accepts 1 arg(s), received 0\n " , output )
147146 })
148147 It ("invalid filename" , func () {
149- output , err := executeCommand (cmd . NewRootCmd (), "admin" , "sync" , "unknown.yaml" )
148+ output , err := executeCommand ("admin" , "sync" , "unknown.yaml" , "--addr" , helper . AdminHttpURL )
150149 assert .NotNil (GinkgoT (), err )
151150 assert .Equal (GinkgoT (), "Error: open unknown.yaml: no such file or directory\n " , output )
152151 })
153152 It ("invalid yaml" , func () {
154- output , err := executeCommand (cmd . NewRootCmd (), "admin" , "sync" , "../fixtures/invalid_webhookx.yml" )
153+ output , err := executeCommand ("admin" , "sync" , "../fixtures/invalid_webhookx.yml" , "--addr" , helper . AdminHttpURL )
155154 assert .NotNil (GinkgoT (), err )
156155 assert .Equal (GinkgoT (), "Error: invalid status code: 400 {\" message\" :\" malformed yaml content: yaml: unmarshal errors:\\ n line 1: cannot unmarshal !!str `webhook...` into map[string]interface {}\" }\n " , output )
157156 })
@@ -163,7 +162,7 @@ var _ = Describe("admin", Ordered, func() {
163162 server := startHTTP (func (writer http.ResponseWriter , r * http.Request ) {
164163 time .Sleep (time .Second * 2 )
165164 }, ":9601" )
166- output , err := executeCommand (cmd . NewRootCmd (), "admin" , "sync" , "../fixtures/webhookx.yml" , "--timeout" , "1" )
165+ output , err := executeCommand ("admin" , "sync" , "../fixtures/webhookx.yml" , "--timeout" , "1" )
167166 assert .NotNil (GinkgoT (), err )
168167 assert .Equal (GinkgoT (), "Error: Post \" http://localhost:9601/workspaces/default/config/sync\" : context deadline exceeded (Client.Timeout exceeded while awaiting headers)\n " , output )
169168 assert .Nil (GinkgoT (), server .Shutdown (context .TODO ()))
@@ -174,7 +173,7 @@ var _ = Describe("admin", Ordered, func() {
174173 server := startHTTP (func (writer http.ResponseWriter , r * http.Request ) {
175174 url = fullURL (r )
176175 }, "127.0.0.1:9601" )
177- output , err := executeCommand (cmd . NewRootCmd (), "admin" , "sync" , "../fixtures/webhookx.yml" , "--workspace" , "foo" )
176+ output , err := executeCommand ("admin" , "sync" , "../fixtures/webhookx.yml" , "--workspace" , "foo" )
178177 assert .Nil (GinkgoT (), err )
179178 assert .Equal (GinkgoT (), "sync successfully\n " , output )
180179 assert .Equal (GinkgoT (), "http://localhost:9601/workspaces/foo/config/sync" , url )
@@ -187,7 +186,7 @@ var _ = Describe("admin", Ordered, func() {
187186 server := startHTTP (func (writer http.ResponseWriter , r * http.Request ) {
188187 url = fullURL (r )
189188 }, "127.0.0.1:8888" )
190- output , err := executeCommand (cmd . NewRootCmd (), "admin" , "sync" , "../fixtures/webhookx.yml" , "--addr" , "http://localhost:8888" )
189+ output , err := executeCommand ("admin" , "sync" , "../fixtures/webhookx.yml" , "--addr" , "http://localhost:8888" )
191190 assert .Nil (GinkgoT (), err )
192191 assert .Equal (GinkgoT (), "sync successfully\n " , output )
193192 assert .Equal (GinkgoT (), "http://localhost:8888/workspaces/default/config/sync" , url )
@@ -235,7 +234,7 @@ var _ = Describe("admin", Ordered, func() {
235234 factory .WithPluginMetadata (map [string ]string {"k" : "v" }))
236235 assert .NoError (GinkgoT (), db .Plugins .Insert (context .TODO (), & plugin ))
237236
238- output , err := executeCommand (cmd . NewRootCmd (), "admin" , "dump" )
237+ output , err := executeCommand ("admin" , "dump" , "--addr" , helper . AdminHttpURL )
239238 assert .Nil (GinkgoT (), err )
240239 expected , err := os .ReadFile ("testdata/dump.yml" )
241240 require .NoError (GinkgoT (), err )
0 commit comments