mirror of
https://github.com/gocsaf/csaf.git
synced 2025-12-22 11:55:40 +01:00
Add initial downloader tests
This commit is contained in:
parent
20bee797c6
commit
6ca6dfee25
2 changed files with 50 additions and 10 deletions
|
|
@ -11,22 +11,56 @@ package main
|
|||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/csaf-poc/csaf_distribution/v3/csaf"
|
||||
"github.com/csaf-poc/csaf_distribution/v3/internal/options"
|
||||
"github.com/csaf-poc/csaf_distribution/v3/util"
|
||||
)
|
||||
|
||||
func TestShaMarking(t *testing.T) {
|
||||
cfg := config{LogLevel: &options.LogLevel{Level: slog.LevelDebug}}
|
||||
cfg.prepare()
|
||||
d, err := newDownloader(&cfg)
|
||||
if err != nil {
|
||||
t.Fatalf("could not init downloader: %v", err)
|
||||
tests := []struct {
|
||||
name string
|
||||
wantSha256 bool
|
||||
wantSha512 bool
|
||||
}{
|
||||
{
|
||||
name: "want sha256 and sha512",
|
||||
wantSha256: true,
|
||||
wantSha512: true,
|
||||
},
|
||||
}
|
||||
defer d.close()
|
||||
ctx := context.Background()
|
||||
files := []csaf.AdvisoryFile{}
|
||||
|
||||
d.downloadFiles(ctx, csaf.TLPLabelWhite, files)
|
||||
t.Parallel()
|
||||
for _, testToRun := range tests {
|
||||
test := testToRun
|
||||
t.Run(test.name, func(tt *testing.T) {
|
||||
tt.Parallel()
|
||||
serverURL := ""
|
||||
fs := http.FileServer(http.Dir("../../testdata/simple-rolie-provider"))
|
||||
server := httptest.NewTLSServer(fs)
|
||||
defer server.Close()
|
||||
|
||||
serverURL = server.URL
|
||||
|
||||
hClient := server.Client()
|
||||
client := util.Client(hClient)
|
||||
|
||||
cfg := config{LogLevel: &options.LogLevel{Level: slog.LevelDebug}}
|
||||
cfg.prepare()
|
||||
d, err := newDownloader(&cfg)
|
||||
if err != nil {
|
||||
t.Fatalf("could not init downloader: %v", err)
|
||||
}
|
||||
defer d.close()
|
||||
d.client = &client
|
||||
|
||||
ctx := context.Background()
|
||||
err = d.run(ctx, []string{serverURL + "/provider-metadata.json"})
|
||||
if err != nil {
|
||||
t.Errorf("SHA marking: Expected no error, got: %v", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue