Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
mmetc committed Oct 9, 2024
1 parent 2a28f98 commit 323960f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
5 changes: 5 additions & 0 deletions cmd/crowdsec/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,14 @@ func initAPIServer(ctx context.Context, cConfig *csconfig.Config) (*apiserver.AP

func serveAPIServer(apiServer *apiserver.APIServer) {
apiReady := make(chan bool, 1)

Check warning on line 62 in cmd/crowdsec/api.go

View check run for this annotation

Codecov / codecov/patch

cmd/crowdsec/api.go#L62

Added line #L62 was not covered by tests
apiTomb.Go(func() error {
defer trace.CatchPanic("crowdsec/serveAPIServer")

Check warning on line 65 in cmd/crowdsec/api.go

View check run for this annotation

Codecov / codecov/patch

cmd/crowdsec/api.go#L65

Added line #L65 was not covered by tests
go func() {
defer trace.CatchPanic("crowdsec/runAPIServer")
log.Debugf("serving API after %s ms", time.Since(crowdsecT0))

Check warning on line 69 in cmd/crowdsec/api.go

View check run for this annotation

Codecov / codecov/patch

cmd/crowdsec/api.go#L69

Added line #L69 was not covered by tests
if err := apiServer.Run(apiReady); err != nil {
log.Fatal(err)
}
Expand All @@ -77,6 +80,7 @@ func serveAPIServer(apiServer *apiserver.APIServer) {
<-apiTomb.Dying() // lock until go routine is dying
pluginTomb.Kill(nil)
log.Infof("serve: shutting down api server")

Check warning on line 83 in cmd/crowdsec/api.go

View check run for this annotation

Codecov / codecov/patch

cmd/crowdsec/api.go#L83

Added line #L83 was not covered by tests
return apiServer.Shutdown()
})
<-apiReady
Expand All @@ -88,5 +92,6 @@ func hasPlugins(profiles []*csconfig.ProfileCfg) bool {
return true
}
}

return false
}
4 changes: 2 additions & 2 deletions cmd/crowdsec/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func reloadHandler(sig os.Signal) (*csconfig.Config, error) {
return nil, err
}

if err := hub.Load(); err != nil {
if err = hub.Load(); err != nil {

Check warning on line 93 in cmd/crowdsec/serve.go

View check run for this annotation

Codecov / codecov/patch

cmd/crowdsec/serve.go#L93

Added line #L93 was not covered by tests
return nil, err
}

Expand Down Expand Up @@ -392,7 +392,7 @@ func Serve(cConfig *csconfig.Config, agentReady chan bool) error {
return err
}

if err := hub.Load(); err != nil {
if err = hub.Load(); err != nil {
return err
}

Expand Down
7 changes: 3 additions & 4 deletions pkg/apiserver/apiserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package apiserver
import (
"context"
"encoding/json"
"fmt"
"net/http"
"net/http/httptest"
"os"
Expand Down Expand Up @@ -41,7 +40,7 @@ var (
MachineID: &testMachineID,
Password: &testPassword,
}
UserAgent = fmt.Sprintf("crowdsec-test/%s", version.Version)
UserAgent = "crowdsec-test/" + version.Version
emptyBody = strings.NewReader("")
)

Expand Down Expand Up @@ -373,7 +372,7 @@ func TestLoggingDebugToFileConfig(t *testing.T) {
LogDir: tempDir,
DbConfig: &dbconfig,
}
expectedFile := fmt.Sprintf("%s/crowdsec_api.log", tempDir)
expectedFile := filepath.Join(tempDir, "crowdsec_api.log")
expectedLines := []string{"/test42"}
cfg.LogLevel = ptr.Of(log.DebugLevel)

Expand Down Expand Up @@ -426,7 +425,7 @@ func TestLoggingErrorToFileConfig(t *testing.T) {
LogDir: tempDir,
DbConfig: &dbconfig,
}
expectedFile := fmt.Sprintf("%s/crowdsec_api.log", tempDir)
expectedFile := filepath.Join(tempDir, "crowdsec_api.log")
cfg.LogLevel = ptr.Of(log.ErrorLevel)

// Configure logging
Expand Down

0 comments on commit 323960f

Please sign in to comment.