Skip to content

Commit

Permalink
review golangci-lint config and fix sensible issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Tofel committed Oct 20, 2023
1 parent 27d94ba commit e67c5d5
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 37 deletions.
3 changes: 1 addition & 2 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ run:
timeout: 5m
skip-dirs:
- contracts/ethereum
- environment
- examples
- imports
- client
linters:
enable:
# defaults
Expand Down
2 changes: 1 addition & 1 deletion client/mockserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"strings"

"github.com/go-resty/resty/v2"

"github.com/rs/zerolog/log"

"github.com/smartcontractkit/chainlink-testing-framework/env/environment"
"github.com/smartcontractkit/chainlink-testing-framework/env/pkg/helm/mockserver"
)
Expand Down
4 changes: 2 additions & 2 deletions client/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import (
"strings"

"github.com/jmoiron/sqlx"
"github.com/smartcontractkit/chainlink-testing-framework/env/environment"

// import for side effect of sql packages
_ "github.com/lib/pq"
"github.com/rs/zerolog/log"

"github.com/smartcontractkit/chainlink-testing-framework/env/environment"
)

// PostgresConnector sqlx postgres connector
Expand Down
14 changes: 4 additions & 10 deletions env/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,16 +341,13 @@ func (m *K8sClient) NamespaceExists(namespace string) bool {
// RemoveNamespace removes namespace
func (m *K8sClient) RemoveNamespace(namespace string) error {
log.Info().Str("Namespace", namespace).Msg("Removing namespace")
if err := m.ClientSet.CoreV1().Namespaces().Delete(context.Background(), namespace, metaV1.DeleteOptions{}); err != nil {
return err
}
return nil
return m.ClientSet.CoreV1().Namespaces().Delete(context.Background(), namespace, metaV1.DeleteOptions{})
}

// RolloutStatefulSets applies "rollout statefulset" to all existing statefulsets in that namespace
func (m *K8sClient) RolloutStatefulSets(ctx context.Context, namespace string) error {
stsClient := m.ClientSet.AppsV1().StatefulSets(namespace)
sts, err := stsClient.List(context.Background(), metaV1.ListOptions{})
sts, err := stsClient.List(ctx, metaV1.ListOptions{})
if err != nil {
return err
}
Expand Down Expand Up @@ -421,7 +418,7 @@ func (m *K8sClient) WaitForJob(namespaceName string, jobName string, fundReturnS
}

func (m *K8sClient) WaitForDeploymentsAvailable(ctx context.Context, namespace string) error {
deployments, err := m.ClientSet.AppsV1().Deployments(namespace).List(context.Background(), metaV1.ListOptions{})
deployments, err := m.ClientSet.AppsV1().Deployments(namespace).List(ctx, metaV1.ListOptions{})
if err != nil {
return err
}
Expand Down Expand Up @@ -472,10 +469,7 @@ func (m *K8sClient) Create(manifest string) error {
func (m *K8sClient) DryRun(manifest string) error {
manifestFile := fmt.Sprintf(TempDebugManifest, uuid.NewString())
log.Info().Str("File", manifestFile).Msg("Creating manifest")
if err := os.WriteFile(manifestFile, []byte(manifest), os.ModePerm); err != nil {
return err
}
return nil
return os.WriteFile(manifestFile, []byte(manifest), os.ModePerm)
}

// CopyToPod copies src to a particular container. Destination should be in the form of a proper K8s destination path
Expand Down
2 changes: 1 addition & 1 deletion env/client/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func readStdPipe(pipe io.ReadCloser, outputFunction func(string)) {

func ExecCmdWithOptions(ctx context.Context, command string, outputFunction func(string)) error {
c := strings.Split(command, " ")
cmd := exec.CommandContext(ctx, c[0], c[1:]...)
cmd := exec.CommandContext(ctx, c[0], c[1:]...) // #nosec: G204
stderr, err := cmd.StderrPipe()
if err != nil {
return err
Expand Down
15 changes: 3 additions & 12 deletions env/environment/artifacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ func (a *Artifacts) DumpTestResult(testDir string, dbName string) error {
if err := MkdirIfNotExists(testDir); err != nil {
return err
}
if err := a.writePodArtifacts(testDir); err != nil {
return err
}
return nil
return a.writePodArtifacts(testDir)
}

func (a *Artifacts) writePodArtifacts(testDir string) error {
Expand Down Expand Up @@ -124,10 +121,7 @@ func (a *Artifacts) writePostgresDump(podDir string, pod coreV1.Pod, cont coreV1
if err != nil {
return err
}
if err = logFile.Close(); err != nil {
return err
}
return nil
return logFile.Close()
}

func (a *Artifacts) writeContainerLogs(podDir string, pod coreV1.Pod, cont coreV1.Container) error {
Expand All @@ -153,10 +147,7 @@ func (a *Artifacts) writeContainerLogs(podDir string, pod coreV1.Pod, cont coreV
if err = logFile.Close(); err != nil {
return err
}
if err = podLogs.Close(); err != nil {
return err
}
return nil
return podLogs.Close()
}

// Writes logs for each container in a pod
Expand Down
15 changes: 6 additions & 9 deletions env/environment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ func (m *Environment) RunCustomReadyConditions(customCheck *client.ReadyCheckDat
return err
}
if m.Cfg.fundReturnFailed {
return errors.New("failed to return funds in remote runner.")
return errors.New("failed to return funds in remote runner")
}
m.Cfg.jobDeployed = true
} else {
Expand Down Expand Up @@ -770,15 +770,12 @@ func (m *Environment) DeployCustomReadyConditions(customCheck *client.ReadyCheck
log.Info().Str("Namespace", m.Cfg.Namespace).Msg("Deploying namespace")

if m.Cfg.DryRun {
if err := m.Client.DryRun(m.CurrentManifest); err != nil {
return err
}
return nil
return m.Client.DryRun(m.CurrentManifest)
}
ctx, cancel := context.WithTimeout(context.Background(), m.Cfg.ReadyCheckData.Timeout)
defer cancel()
err := m.Client.Apply(ctx, m.CurrentManifest, m.Cfg.Namespace)
if ctx.Err() == context.DeadlineExceeded {
if errors.Is(ctx.Err(), context.DeadlineExceeded) {
return errors.New("timeout waiting for environment to be ready")
}
if err != nil {
Expand Down Expand Up @@ -814,7 +811,7 @@ func (m *Environment) RolloutStatefulSets() error {
ctx, cancel := context.WithTimeout(context.Background(), m.Cfg.ReadyCheckData.Timeout)
defer cancel()
err := m.Client.RolloutStatefulSets(ctx, m.Cfg.Namespace)
if ctx.Err() == context.DeadlineExceeded {
if errors.Is(ctx.Err(), context.DeadlineExceeded) {
return errors.New("timeout waiting for rollout statefulset to complete")
}
return err
Expand All @@ -828,7 +825,7 @@ func (m *Environment) RolloutRestartBySelector(resource string, selector string)
ctx, cancel := context.WithTimeout(context.Background(), m.Cfg.ReadyCheckData.Timeout)
defer cancel()
err := m.Client.RolloutRestartBySelector(ctx, m.Cfg.Namespace, resource, selector)
if ctx.Err() == context.DeadlineExceeded {
if errors.Is(ctx.Err(), context.DeadlineExceeded) {
return errors.New("timeout waiting for rollout restart to complete")
}
return err
Expand Down Expand Up @@ -896,7 +893,7 @@ func getReplicaCount(spec map[string]any) int {
if ok {
replicaCount += int(replicas.(float64))
} else {
replicaCount += 1
replicaCount++
}

return replicaCount
Expand Down

0 comments on commit e67c5d5

Please sign in to comment.