44 "bufio"
55 "bytes"
66 "context"
7- "errors"
8- "flag"
97 "io"
108 "net/http"
119 "net/http/httptest"
@@ -27,10 +25,12 @@ const runMainEnv = "GITHUBSTATUS_MCP_TEST_RUN_MAIN"
2725func TestMain (m * testing.M ) {
2826 if os .Getenv (runMainEnv ) == "1" {
2927 main ()
28+ // The test binary is acting as the command process in this branch.
29+ //revive:disable-next-line:redundant-test-main-exit
3030 os .Exit (0 )
3131 }
3232
33- os . Exit ( m .Run () )
33+ m .Run ()
3434}
3535
3636// newStatusAPI serves the summary fixture and returns its base URL.
@@ -89,15 +89,21 @@ func checkSession(t *testing.T, cs *mcp.ClientSession) {
8989 }
9090
9191 out , ok := res .StructuredContent .(map [string ]any )
92- if ! ok || out ["healthy" ] != false || out ["description" ] != "Minor Service Outage" {
92+ if ! ok {
93+ t .Errorf ("check_github_health = %#v" , res .StructuredContent )
94+ return
95+ }
96+
97+ healthy , healthyOK := out ["healthy" ].(bool )
98+ if ! healthyOK || healthy || out ["description" ] != "Minor Service Outage" {
9399 t .Errorf ("check_github_health = %#v" , res .StructuredContent )
94100 }
95101}
96102
97103func TestStdio (t * testing.T ) {
98104 baseURL := newStatusAPI (t )
99105
100- cmd := exec .Command (os .Args [0 ], "-base-url" , baseURL )
106+ cmd := exec .Command (os .Args [0 ], "-- base-url" , baseURL )
101107
102108 cmd .Env = append (os .Environ (), runMainEnv + "=1" )
103109
@@ -136,7 +142,7 @@ func TestHTTP(t *testing.T) {
136142
137143 done := make (chan error , 1 )
138144 go func () {
139- done <- run (ctx , []string {"-http" , "127.0.0.1:0" , "-base-url" , baseURL }, pw )
145+ done <- run (ctx , []string {"-- http" , "127.0.0.1:0" , "- -base-url" , baseURL }, pw )
140146
141147 _ = pw .Close ()
142148 }()
@@ -205,25 +211,25 @@ func TestRunErrors(t *testing.T) {
205211 tests := []struct {
206212 name string
207213 args []string
208- wantErr error
214+ wantError bool
209215 wantStderr string
210216 }{
211- {"help" , []string {"-h " }, flag . ErrHelp , "Usage: githubstatus-mcp" },
212- {"unknown flag" , []string {"-bogus" }, nil , "flag provided but not defined: -bogus" },
213- {"unexpected argument" , []string {"extra" }, nil , "unexpected arguments: [extra]" },
214- {"bad listen address" , []string {"-http" , "256.0.0.1:bad" }, nil , "githubstatus-mcp: listen tcp" },
217+ {"help" , []string {"--help " }, false , "Usage:\n githubstatus-mcp [flags] " },
218+ {"unknown flag" , []string {"-- bogus" }, true , "unknown flag: - -bogus" },
219+ {"unexpected argument" , []string {"extra" }, true , "unexpected arguments: [extra]" },
220+ {"bad listen address" , []string {"-- http" , "256.0.0.1:bad" }, true , "githubstatus-mcp: listen tcp" },
215221 }
216222 for _ , tt := range tests {
217223 t .Run (tt .name , func (t * testing.T ) {
218224 var stderr bytes.Buffer
219225
220226 err := run (context .Background (), tt .args , & stderr )
221- if err == nil {
227+ if err == nil && tt . wantError {
222228 t .Fatal ("expected an error" )
223229 }
224230
225- if tt . wantErr != nil && ! errors . Is ( err , tt .wantErr ) {
226- t .Errorf ("err = %v, want %v " , err , tt . wantErr )
231+ if err != nil && ! tt .wantError {
232+ t .Fatalf ("err = %v, want nil " , err )
227233 }
228234
229235 if ! strings .Contains (stderr .String (), tt .wantStderr ) {
0 commit comments