-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
5,537 additions
and
3,278 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package internal | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func CreateApiServer(t *testing.T, port int) { | ||
mux := http.NewServeMux() | ||
mux.HandleFunc("/", func(writer http.ResponseWriter, request *http.Request) { | ||
writer.WriteHeader(200) | ||
}) | ||
|
||
_, cancelCtx := context.WithCancel(context.Background()) | ||
s := &http.Server{ | ||
Addr: fmt.Sprintf("0.0.0.0:%d", port), | ||
Handler: mux, | ||
} | ||
|
||
t.Cleanup(func() { | ||
cancelCtx() | ||
}) | ||
|
||
go func() { | ||
if err := s.ListenAndServe(); !errors.Is(err, http.ErrServerClosed) { | ||
require.NoError(t, err) | ||
} | ||
}() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.