As we reevaluate how to best support and maintain Staging Ref in the future, we encourage development teams using this environment to highlight their use cases in the following issue: https://gitlab.com/gitlab-com/gl-infra/software-delivery/framework/software-delivery-framework-issue-tracker/-/issues/36.

Skip to content
Snippets Groups Projects
Commit 1e02a179 authored by Archish's avatar Archish
Browse files

Lint fixes in healtcheck and discover package

parent cffe8fc0
No related branches found
No related tags found
No related merge requests found
// Package discover implements the "discover" command for fetching user info and displaying a welcome message.
package discover
import (
Loading
Loading
@@ -11,25 +12,27 @@ import (
"gitlab.com/gitlab-org/gitlab-shell/v14/internal/gitlabnet/discover"
)
// Command struct encapsulates the necessary components for executing the Discover command.
type Command struct {
Config *config.Config
Args *commandargs.Shell
ReadWriter *readwriter.ReadWriter
}
// Execute runs the discover command, fetching and displaying user information.
func (c *Command) Execute(ctx context.Context) (context.Context, error) {
response, err := c.getUserInfo(ctx)
if err != nil {
return ctx, fmt.Errorf("Failed to get username: %v", err)
return ctx, fmt.Errorf("failed to get username: %v", err)
}
logData := command.LogData{}
if response.IsAnonymous() {
logData.Username = "Anonymous"
fmt.Fprintf(c.ReadWriter.Out, "Welcome to GitLab, Anonymous!\n")
_, _ = fmt.Fprintf(c.ReadWriter.Out, "Welcome to GitLab, Anonymous!\n")
} else {
logData.Username = response.Username
fmt.Fprintf(c.ReadWriter.Out, "Welcome to GitLab, @%s!\n", response.Username)
_, _ = fmt.Fprintf(c.ReadWriter.Out, "Welcome to GitLab, @%s!\n", response.Username)
}
ctxWithLogData := context.WithValue(ctx, "logData", logData)
Loading
Loading
Loading
Loading
@@ -106,17 +106,17 @@ func TestFailingExecute(t *testing.T) {
{
desc: "With missing arguments",
arguments: &commandargs.Shell{},
expectedError: "Failed to get username: who='' is invalid",
expectedError: "failed to get username: who='' is invalid",
},
{
desc: "When the API returns an error",
arguments: &commandargs.Shell{GitlabUsername: "broken_message"},
expectedError: "Failed to get username: Forbidden!",
expectedError: "failed to get username: Forbidden!",
},
{
desc: "When the API fails",
arguments: &commandargs.Shell{GitlabUsername: "broken"},
expectedError: "Failed to get username: Internal API unreachable",
expectedError: "failed to get username: Internal API unreachable",
},
}
Loading
Loading
// Package healthcheck provides functionality to perform health checks.
package healthcheck
import (
Loading
Loading
@@ -14,24 +15,26 @@ var (
redisMessage = "Redis available via internal API"
)
// Command handles the execution of health checks.
type Command struct {
Config *config.Config
ReadWriter *readwriter.ReadWriter
}
// Execute performs the health check and outputs the result.
func (c *Command) Execute(ctx context.Context) (context.Context, error) {
response, err := c.runCheck(ctx)
if err != nil {
return ctx, fmt.Errorf("%v: FAILED - %v", apiMessage, err)
}
fmt.Fprintf(c.ReadWriter.Out, "%v: OK\n", apiMessage)
_, _ = fmt.Fprintf(c.ReadWriter.Out, "%v: OK\n", apiMessage)
if !response.Redis {
return ctx, fmt.Errorf("%v: FAILED", redisMessage)
}
fmt.Fprintf(c.ReadWriter.Out, "%v: OK\n", redisMessage)
_, _ = fmt.Fprintf(c.ReadWriter.Out, "%v: OK\n", redisMessage)
return ctx, nil
}
Loading
Loading
Loading
Loading
@@ -195,8 +195,8 @@ func TestHandleShell(t *testing.T) {
desc: "fails to parse command",
cmd: "discover",
gitlabKeyID: "",
errMsg: "ERROR: Failed to get username: who='' is invalid\n",
expectedErrString: "Failed to get username: who='' is invalid",
errMsg: "ERROR: failed to get username: who='' is invalid\n",
expectedErrString: "failed to get username: who='' is invalid",
expectedExitCode: 1,
},
{
Loading
Loading
Loading
Loading
@@ -124,18 +124,7 @@ internal/command/commandargs/shell.go:61:10: ST1005: error strings should not be
internal/command/commandargs/shell.go:69:6: var-naming: var keyId should be keyID (revive)
internal/command/commandargs/shell.go:98:6: var-naming: func tryParseKeyId should be tryParseKeyID (revive)
internal/command/commandargs/shell.go:106:1: exported: exported method Shell.ParseCommand should have comment or be unexported (revive)
internal/command/discover/discover.go:1:1: package-comments: should have a package comment (revive)
internal/command/discover/discover.go:14:6: exported: exported type Command should have comment or be unexported (revive)
internal/command/discover/discover.go:20:1: exported: exported method Command.Execute should have comment or be unexported (revive)
internal/command/discover/discover.go:23:15: ST1005: error strings should not be capitalized (stylecheck)
internal/command/discover/discover.go:29:14: Error return value of `fmt.Fprintf` is not checked (errcheck)
internal/command/discover/discover.go:32:14: Error return value of `fmt.Fprintf` is not checked (errcheck)
internal/command/discover/discover.go:35:20: context-keys-type: should not use basic type string as key in context.WithValue (revive)
internal/command/healthcheck/healthcheck.go:1:1: package-comments: should have a package comment (revive)
internal/command/healthcheck/healthcheck.go:17:6: exported: exported type Command should have comment or be unexported (revive)
internal/command/healthcheck/healthcheck.go:22:1: exported: exported method Command.Execute should have comment or be unexported (revive)
internal/command/healthcheck/healthcheck.go:28:13: Error return value of `fmt.Fprintf` is not checked (errcheck)
internal/command/healthcheck/healthcheck.go:34:13: Error return value of `fmt.Fprintf` is not checked (errcheck)
internal/command/discover/discover.go:38:20: context-keys-type: should not use basic type string as key in context.WithValue (revive)
internal/command/healthcheck/healthcheck_test.go:37:41: unused-parameter: parameter 'r' seems to be unused, consider removing or renaming it as _ (revive)
internal/command/lfsauthenticate/lfsauthenticate.go:87:13: Error return value of `fmt.Fprintf` is not checked (errcheck)
internal/command/lfsauthenticate/lfsauthenticate_test.go:76:5: go-require: do not use require in http handlers (testifylint)
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment