-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'refactor/sparrow-api' into refactor/api
- Loading branch information
Showing
9 changed files
with
362 additions
and
304 deletions.
There are no files selected for viewing
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,70 @@ | ||
// sparrow | ||
// (C) 2024, Deutsche Telekom IT GmbH | ||
// | ||
// Deutsche Telekom IT GmbH and all other contributors / | ||
// copyright owners license this file to you under the Apache | ||
// License, Version 2.0 (the "License"); you may not use this | ||
// file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package api | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/go-chi/chi/v5" | ||
) | ||
|
||
func TestAPI_RegisterRoutes(_ *testing.T) { | ||
} | ||
|
||
func TestAPI_shutdownWhenContextCanceled(t *testing.T) { | ||
a := API{ | ||
router: chi.NewRouter(), | ||
server: &http.Server{}, //nolint:gosec | ||
} | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
cancel() | ||
|
||
if err := a.Run(ctx); !errors.Is(err, context.Canceled) { | ||
t.Error("Expected ErrApiContext") | ||
} | ||
} | ||
|
||
func Test_okHandler(t *testing.T) { | ||
ctx := context.Background() | ||
|
||
req, err := http.NewRequestWithContext(ctx, "GET", "/okHandler", http.NoBody) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
rr := httptest.NewRecorder() | ||
handler := okHandler(ctx) | ||
|
||
handler.ServeHTTP(rr, req) | ||
|
||
if status := rr.Code; status != http.StatusOK { | ||
t.Errorf("Handler returned wrong status code: got %v want %v", | ||
status, http.StatusOK) | ||
} | ||
|
||
expected := "ok" | ||
if rr.Body.String() != expected { | ||
t.Errorf("Handler returned unexpected body: got %v want %v", | ||
rr.Body.String(), expected) | ||
} | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Oops, something went wrong.