mirror of
https://github.com/gocsaf/csaf.git
synced 2025-12-22 05:40:11 +01:00
parent
5709b14650
commit
0848143a0b
7 changed files with 16 additions and 19 deletions
6
.github/workflows/go.yml
vendored
6
.github/workflows/go.yml
vendored
|
|
@ -17,7 +17,7 @@ jobs:
|
||||||
- name: Set up Go
|
- name: Set up Go
|
||||||
uses: actions/setup-go@v4
|
uses: actions/setup-go@v4
|
||||||
with:
|
with:
|
||||||
go-version: 'stable'
|
go-version: "stable"
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
run: go build -v ./cmd/...
|
run: go build -v ./cmd/...
|
||||||
|
|
@ -31,10 +31,10 @@ jobs:
|
||||||
gofmt-flags: "-l -d"
|
gofmt-flags: "-l -d"
|
||||||
|
|
||||||
- name: golint
|
- name: golint
|
||||||
uses: Jerome1337/golint-action@v1.0.2
|
uses: Jerome1337/golint-action@v1.0.3
|
||||||
|
|
||||||
- name: Revive Action
|
- name: Revive Action
|
||||||
uses: morphy2k/revive-action@v2.5.1
|
uses: morphy2k/revive-action@v2.7.4
|
||||||
|
|
||||||
- name: Tests
|
- name: Tests
|
||||||
run: go test -v ./...
|
run: go test -v ./...
|
||||||
|
|
|
||||||
|
|
@ -49,10 +49,10 @@ func Test_downloadJSON(t *testing.T) {
|
||||||
test := testToRun
|
test := testToRun
|
||||||
t.Run(test.name, func(tt *testing.T) {
|
t.Run(test.name, func(tt *testing.T) {
|
||||||
tt.Parallel()
|
tt.Parallel()
|
||||||
found := func(r io.Reader) error {
|
found := func(_ io.Reader) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.Header().Add("Content-Type", test.contentType)
|
w.Header().Add("Content-Type", test.contentType)
|
||||||
w.WriteHeader(test.statusCode)
|
w.WriteHeader(test.statusCode)
|
||||||
}))
|
}))
|
||||||
|
|
|
||||||
|
|
@ -24,12 +24,10 @@ import (
|
||||||
func checkIfFileExists(path string, t *testing.T) bool {
|
func checkIfFileExists(path string, t *testing.T) bool {
|
||||||
if _, err := os.Stat(path); err == nil {
|
if _, err := os.Stat(path); err == nil {
|
||||||
return true
|
return true
|
||||||
} else if errors.Is(err, os.ErrNotExist) {
|
} else if !errors.Is(err, os.ErrNotExist) {
|
||||||
return false
|
|
||||||
} else {
|
|
||||||
t.Fatalf("Failed to check if file exists: %v", err)
|
t.Fatalf("Failed to check if file exists: %v", err)
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestShaMarking(t *testing.T) {
|
func TestShaMarking(t *testing.T) {
|
||||||
|
|
|
||||||
|
|
@ -224,12 +224,12 @@ func (f *forwarder) storeFailed(filename, doc, sha256, sha512 string) {
|
||||||
|
|
||||||
// limitedString reads max bytes from reader and returns it as a string.
|
// limitedString reads max bytes from reader and returns it as a string.
|
||||||
// Longer strings are indicated by "..." as a suffix.
|
// Longer strings are indicated by "..." as a suffix.
|
||||||
func limitedString(r io.Reader, max int) (string, error) {
|
func limitedString(r io.Reader, maxLength int) (string, error) {
|
||||||
var msg strings.Builder
|
var msg strings.Builder
|
||||||
if _, err := io.Copy(&msg, io.LimitReader(r, int64(max))); err != nil {
|
if _, err := io.Copy(&msg, io.LimitReader(r, int64(maxLength))); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
if msg.Len() >= max {
|
if msg.Len() >= maxLength {
|
||||||
msg.WriteString("...")
|
msg.WriteString("...")
|
||||||
}
|
}
|
||||||
return msg.String(), nil
|
return msg.String(), nil
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ func main() {
|
||||||
|
|
||||||
cfg, err := loadConfig()
|
cfg, err := loadConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cgi.Serve(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
|
cgi.Serve(http.HandlerFunc(func(rw http.ResponseWriter, _ *http.Request) {
|
||||||
http.Error(rw, "Something went wrong. Check server logs for more details",
|
http.Error(rw, "Something went wrong. Check server logs for more details",
|
||||||
http.StatusInternalServerError)
|
http.StatusInternalServerError)
|
||||||
}))
|
}))
|
||||||
|
|
|
||||||
|
|
@ -37,10 +37,10 @@ func TestParse(t *testing.T) {
|
||||||
},
|
},
|
||||||
Usage: "[OPTIONS] domain...",
|
Usage: "[OPTIONS] domain...",
|
||||||
HasVersion: func(cfg *config) bool { return cfg.Version },
|
HasVersion: func(cfg *config) bool { return cfg.Version },
|
||||||
SetDefaults: func(cfg *config) {
|
SetDefaults: func(_ *config) {
|
||||||
},
|
},
|
||||||
// Re-establish default values if not set.
|
// Re-establish default values if not set.
|
||||||
EnsureDefaults: func(cfg *config) {
|
EnsureDefaults: func(_ *config) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -157,7 +157,6 @@ func TestErrorCheck(t *testing.T) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
t.Fatalf("process ran with err %v, want exit status 1", err)
|
t.Fatalf("process ran with err %v, want exit status 1", err)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestSecondPassCommandlineParsing checks if the second pass
|
// TestSecondPassCommandlineParsing checks if the second pass
|
||||||
|
|
@ -168,7 +167,7 @@ func TestSecondPassCommandlineParsing(t *testing.T) {
|
||||||
|
|
||||||
os.Args = []string{"cmd"}
|
os.Args = []string{"cmd"}
|
||||||
p := Parser[config]{
|
p := Parser[config]{
|
||||||
ConfigLocation: func(cfg *config) string {
|
ConfigLocation: func(_ *config) string {
|
||||||
// This is a bit stupid.
|
// This is a bit stupid.
|
||||||
os.Args = []string{"cmd", "--invalid"}
|
os.Args = []string{"cmd", "--invalid"}
|
||||||
return "data/empty.toml"
|
return "data/empty.toml"
|
||||||
|
|
@ -188,7 +187,7 @@ func TestSecondPassCommandlineHelp(t *testing.T) {
|
||||||
|
|
||||||
os.Args = []string{"cmd"}
|
os.Args = []string{"cmd"}
|
||||||
p := Parser[config]{
|
p := Parser[config]{
|
||||||
ConfigLocation: func(cfg *config) string {
|
ConfigLocation: func(_ *config) string {
|
||||||
// This is a bit stupid.
|
// This is a bit stupid.
|
||||||
os.Args = []string{"cmd", "--help"}
|
os.Args = []string{"cmd", "--help"}
|
||||||
return "data/empty.toml"
|
return "data/empty.toml"
|
||||||
|
|
|
||||||
|
|
@ -155,7 +155,7 @@ func TestMakeUniqFile(t *testing.T) {
|
||||||
|
|
||||||
func Test_mkUniq(t *testing.T) {
|
func Test_mkUniq(t *testing.T) {
|
||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
name, err := mkUniq(dir+"/", func(name string) error {
|
name, err := mkUniq(dir+"/", func(_ string) error {
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue