-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
commit 990c74a Merge: 86d7ce1 7824f3b Author: koplas <[email protected]> Date: Fri Nov 22 16:58:46 2024 +0100 Merge branch 'sha-handling' into unittest commit 86d7ce1 Merge: a6807d2 79b8900 Author: koplas <[email protected]> Date: Fri Nov 22 16:54:45 2024 +0100 Merge branch 'sha-handling' into unittest commit 79b8900 Author: koplas <[email protected]> Date: Fri Nov 22 16:31:56 2024 +0100 Improve hash fetching and logging commit a6807d2 Merge: ddb5518 d18d2c3 Author: koplas <[email protected]> Date: Fri Nov 22 16:51:55 2024 +0100 Merge branch 'sha-handling' into unittest commit d18d2c3 Author: koplas <[email protected]> Date: Fri Nov 22 16:31:56 2024 +0100 Improve hash fetching and logging commit ddb5518 Author: koplas <[email protected]> Date: Tue Sep 17 10:45:25 2024 +0200 Extend SHA marking tests commit 13c94f4 Author: koplas <[email protected]> Date: Mon Sep 16 20:46:31 2024 +0200 Use temp directory for downloads commit 1819b48 Author: koplas <[email protected]> Date: Mon Sep 16 20:37:55 2024 +0200 Fix rolie feed commit 989e366 Author: koplas <[email protected]> Date: Mon Sep 16 20:23:22 2024 +0200 Fix provider-metadata.json commit 714735d Author: koplas <[email protected]> Date: Mon Sep 16 20:08:21 2024 +0200 Implement provider handler commit d488e39 Author: koplas <[email protected]> Date: Mon Sep 16 16:26:37 2024 +0200 Add info about gpg key commit a9bf9da Author: koplas <[email protected]> Date: Mon Sep 16 16:12:49 2024 +0200 Rename directory testdata commit 6ca6dfe Author: koplas <[email protected]> Date: Mon Sep 16 16:01:41 2024 +0200 Add initial downloader tests commit 20bee79 Author: koplas <[email protected]> Date: Mon Sep 16 15:58:31 2024 +0200 Fix: Remove unecessary error print commit 8e4e508 Author: koplas <[email protected]> Date: Mon Sep 16 14:50:48 2024 +0200 Extend links test commit 3ba29f9 Author: koplas <[email protected]> Date: Mon Sep 16 14:11:14 2024 +0200 Add initial directory feed testdata commit dee55aa Author: koplas <[email protected]> Date: Mon Sep 16 10:47:32 2024 +0200 Add initial testdata commit cd9338a Author: koplas <[email protected]> Date: Thu Sep 12 15:54:42 2024 +0200 Add initial download unittests
- Loading branch information
Showing
30 changed files
with
1,115 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// This file is Free Software under the MIT License | ||
// without warranty, see README.md and LICENSES/MIT.txt for details. | ||
// | ||
// SPDX-License-Identifier: MIT | ||
// | ||
// SPDX-FileCopyrightText: 2022 German Federal Office for Information Security (BSI) <https://www.bsi.bund.de> | ||
// Software-Engineering: 2022 Intevation GmbH <https://intevation.de> | ||
|
||
package main | ||
|
||
import ( | ||
"io" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/csaf-poc/csaf_distribution/v3/util" | ||
Check failure on line 17 in cmd/csaf_aggregator/client_test.go GitHub Actions / build
Check failure on line 17 in cmd/csaf_aggregator/client_test.go GitHub Actions / build
Check failure on line 17 in cmd/csaf_aggregator/client_test.go GitHub Actions / build
|
||
) | ||
|
||
func Test_downloadJSON(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
statusCode int | ||
contentType string | ||
wantErr error | ||
}{ | ||
{ | ||
name: "status ok, application/json", | ||
statusCode: http.StatusOK, | ||
contentType: "application/json", | ||
wantErr: nil, | ||
}, | ||
{ | ||
name: "status found, application/json", | ||
statusCode: http.StatusFound, | ||
contentType: "application/json", | ||
wantErr: errNotFound, | ||
}, | ||
{ | ||
name: "status ok, application/xml", | ||
statusCode: http.StatusOK, | ||
contentType: "application/xml", | ||
wantErr: errNotFound, | ||
}, | ||
} | ||
|
||
t.Parallel() | ||
for _, testToRun := range tests { | ||
test := testToRun | ||
t.Run(test.name, func(tt *testing.T) { | ||
tt.Parallel() | ||
found := func(r io.Reader) error { | ||
return nil | ||
} | ||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
w.Header().Add("Content-Type", test.contentType) | ||
w.WriteHeader(test.statusCode) | ||
})) | ||
defer server.Close() | ||
hClient := http.Client{} | ||
client := util.Client(&hClient) | ||
if gotErr := downloadJSON(client, server.URL, found); gotErr != test.wantErr { | ||
t.Errorf("downloadJSON: Expected %q but got %q.", test.wantErr, gotErr) | ||
} | ||
}) | ||
} | ||
} |
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
Oops, something went wrong.