Skip to content

Commit

Permalink
Merge pull request #1762 from thevilledev/chore/code-quality-fixes
Browse files Browse the repository at this point in the history
Various code quality fixes/linting
  • Loading branch information
roncodingenthusiast committed Jun 21, 2023
2 parents b677bea + ec16049 commit a3e4db1
Show file tree
Hide file tree
Showing 15 changed files with 58 additions and 98 deletions.
2 changes: 1 addition & 1 deletion config/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func TestFileModePresent(t *testing.T) {
},
{
"present",
FileMode(123),
FileMode(0644),
true,
},
{
Expand Down
2 changes: 1 addition & 1 deletion config/vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ type VaultConfig struct {

// ClientUserAgent is the User-Agent header that will be set on the client
// when making requests to Vault.
ClientUserAgent *string `mapstructure:"client_user_agent""`
ClientUserAgent *string `mapstructure:"client_user_agent"`

// DefaultLeaseDuration configures the default lease duration when not explicitly
// set by vault
Expand Down
11 changes: 4 additions & 7 deletions dependency/catalog_datacenters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,12 @@ func TestCatalogDatacentersQuery_Fetch(t *testing.T) {
dataCh := make(chan interface{}, 1)
errCh := make(chan error, 1)
go func() {
for {
data, _, err := d.Fetch(testClients, &QueryOptions{WaitIndex: qm.LastIndex})
if err != nil {
errCh <- err
return
}
dataCh <- data
data, _, err := d.Fetch(testClients, &QueryOptions{WaitIndex: qm.LastIndex})
if err != nil {
errCh <- err
return
}
dataCh <- data
}()

select {
Expand Down
8 changes: 3 additions & 5 deletions dependency/dependency.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (q *QueryOptions) Merge(o *QueryOptions) *QueryOptions {
return &r
}

if o.AllowStale != false {
if o.AllowStale {
r.AllowStale = o.AllowStale
}

Expand All @@ -105,7 +105,7 @@ func (q *QueryOptions) Merge(o *QueryOptions) *QueryOptions {
r.Choose = o.Choose
}

if o.RequireConsistent != false {
if o.RequireConsistent {
r.RequireConsistent = o.RequireConsistent
}

Expand Down Expand Up @@ -197,9 +197,7 @@ type ResponseMetadata struct {
// sorts and returns the copied result.
func deepCopyAndSortTags(tags []string) []string {
newTags := make([]string, 0, len(tags))
for _, tag := range tags {
newTags = append(newTags, tag)
}
newTags = append(newTags, tags...)
sort.Strings(newTags)
return newTags
}
Expand Down
11 changes: 4 additions & 7 deletions dependency/kv_get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,12 @@ func TestKVGetQuery_Fetch(t *testing.T) {
dataCh := make(chan interface{}, 1)
errCh := make(chan error, 1)
go func() {
for {
data, _, err := d.Fetch(testClients, &QueryOptions{WaitIndex: qm.LastIndex})
if err != nil {
errCh <- err
return
}
dataCh <- data
data, _, err := d.Fetch(testClients, &QueryOptions{WaitIndex: qm.LastIndex})
if err != nil {
errCh <- err
return
}
dataCh <- data
}()

testConsul.SetKVString(t, "test-kv-get/key", "new-value")
Expand Down
11 changes: 4 additions & 7 deletions dependency/kv_keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,12 @@ func TestKVKeysQuery_Fetch(t *testing.T) {
dataCh := make(chan interface{}, 1)
errCh := make(chan error, 1)
go func() {
for {
data, _, err := d.Fetch(testClients, &QueryOptions{WaitIndex: qm.LastIndex})
if err != nil {
errCh <- err
return
}
dataCh <- data
data, _, err := d.Fetch(testClients, &QueryOptions{WaitIndex: qm.LastIndex})
if err != nil {
errCh <- err
return
}
dataCh <- data
}()

testConsul.SetKVString(t, "test-kv-keys/prefix/zebra", "value")
Expand Down
11 changes: 4 additions & 7 deletions dependency/kv_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,15 +276,12 @@ func TestKVListQuery_Fetch(t *testing.T) {
dataCh := make(chan interface{}, 1)
errCh := make(chan error, 1)
go func() {
for {
data, _, err := d.Fetch(testClients, &QueryOptions{WaitIndex: qm.LastIndex})
if err != nil {
errCh <- err
return
}
dataCh <- data
data, _, err := d.Fetch(testClients, &QueryOptions{WaitIndex: qm.LastIndex})
if err != nil {
errCh <- err
return
}
dataCh <- data
}()

testConsul.SetKVString(t, "test-kv-list/prefix/foo", "new-bar")
Expand Down
24 changes: 11 additions & 13 deletions dependency/nomad_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,20 +178,18 @@ func TestNomadServiceQuery_Fetch(t *testing.T) {

act := actI.([]*NomadService)

if act != nil {
for _, s := range act {
// Assert the shape of the randomized fields
assert.Regexp(t, "^_nomad-task.+", s.ID)
assert.Regexp(t, ".+-.+-.+-.+-.+", s.Node)
assert.NotZero(t, s.Port)
assert.Regexp(t, ".+-.+-.+-.+-.+", s.AllocID)
for _, s := range act {
// Assert the shape of the randomized fields
assert.Regexp(t, "^_nomad-task.+", s.ID)
assert.Regexp(t, ".+-.+-.+-.+-.+", s.Node)
assert.NotZero(t, s.Port)
assert.Regexp(t, ".+-.+-.+-.+-.+", s.AllocID)

// Clear randomized fields
s.ID = ""
s.Node = ""
s.Port = 0
s.AllocID = ""
}
// Clear randomized fields
s.ID = ""
s.Node = ""
s.Port = 0
s.AllocID = ""
}

assert.Equal(t, tc.exp, act)
Expand Down
11 changes: 4 additions & 7 deletions dependency/nomad_var_get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,15 +249,12 @@ func TestNVGetQuery_Fetch(t *testing.T) {
dataCh := make(chan interface{}, 1)
errCh := make(chan error, 1)
go func() {
for {
data, _, err := d.Fetch(testClients, &QueryOptions{WaitIndex: qm.LastIndex})
if err != nil {
errCh <- err
return
}
dataCh <- data
data, _, err := d.Fetch(testClients, &QueryOptions{WaitIndex: qm.LastIndex})
if err != nil {
errCh <- err
return
}
dataCh <- data
}()

_ = testNomad.CreateVariable("test-kv-get/path", nvmap{"bar": "barp", "car": "carp"}, nil)
Expand Down
11 changes: 4 additions & 7 deletions dependency/nomad_var_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,15 +313,12 @@ func TestNVListQuery_Fetch(t *testing.T) {
dataCh := make(chan interface{}, 1)
errCh := make(chan error, 1)
go func() {
for {
data, _, err := d.Fetch(testClients, &QueryOptions{WaitIndex: qm.LastIndex})
if err != nil {
errCh <- err
return
}
dataCh <- data
data, _, err := d.Fetch(testClients, &QueryOptions{WaitIndex: qm.LastIndex})
if err != nil {
errCh <- err
return
}
dataCh <- data
}()

_ = testNomad.CreateVariable("test-kv-list/prefix/foo", nvmap{"new-bar": "new-barp"}, nil)
Expand Down
11 changes: 4 additions & 7 deletions dependency/vault_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,12 @@ func TestVaultListQuery_Fetch(t *testing.T) {
dataCh := make(chan interface{}, 1)
errCh := make(chan error, 1)
go func() {
for {
data, _, err := d.Fetch(clients, &QueryOptions{WaitIndex: qm.LastIndex})
if err != nil {
errCh <- err
return
}
dataCh <- data
data, _, err := d.Fetch(clients, &QueryOptions{WaitIndex: qm.LastIndex})
if err != nil {
errCh <- err
return
}
dataCh <- data
}()

select {
Expand Down
22 changes: 8 additions & 14 deletions dependency/vault_read_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,15 +210,12 @@ func TestVaultReadQuery_Fetch_KVv1(t *testing.T) {
dataCh := make(chan interface{}, 1)
errCh := make(chan error, 1)
go func() {
for {
data, _, err := d.Fetch(clients, &QueryOptions{WaitIndex: qm.LastIndex})
if err != nil {
errCh <- err
return
}
dataCh <- data
data, _, err := d.Fetch(clients, &QueryOptions{WaitIndex: qm.LastIndex})
if err != nil {
errCh <- err
return
}
dataCh <- data
}()

select {
Expand Down Expand Up @@ -495,15 +492,12 @@ func TestVaultReadQuery_Fetch_KVv2(t *testing.T) {
dataCh := make(chan interface{}, 1)
errCh := make(chan error, 1)
go func() {
for {
data, _, err := d.Fetch(clients, &QueryOptions{WaitIndex: qm.LastIndex})
if err != nil {
errCh <- err
return
}
dataCh <- data
data, _, err := d.Fetch(clients, &QueryOptions{WaitIndex: qm.LastIndex})
if err != nil {
errCh <- err
return
}
dataCh <- data
}()

select {
Expand Down
6 changes: 0 additions & 6 deletions dependency/vault_write.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,6 @@ func sha1Map(m map[string]interface{}) string {
return fmt.Sprintf("%.4x", h.Sum(nil))
}

func (d *VaultWriteQuery) printWarnings(warnings []string) {
for _, w := range warnings {
log.Printf("[WARN] %s: %s", d, w)
}
}

func (d *VaultWriteQuery) writeSecret(clients *ClientSet, opts *QueryOptions) (*api.Secret, error) {
log.Printf("[TRACE] %s: PUT %s", d, &url.URL{
Path: "/v1/" + d.path,
Expand Down
11 changes: 4 additions & 7 deletions dependency/vault_write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,15 +306,12 @@ func TestVaultWriteQuery_Fetch(t *testing.T) {
dataCh := make(chan interface{}, 1)
errCh := make(chan error, 1)
go func() {
for {
data, _, err := d.Fetch(clients, &QueryOptions{WaitIndex: qm.LastIndex})
if err != nil {
errCh <- err
return
}
dataCh <- data
data, _, err := d.Fetch(clients, &QueryOptions{WaitIndex: qm.LastIndex})
if err != nil {
errCh <- err
return
}
dataCh <- data
}()

select {
Expand Down
4 changes: 2 additions & 2 deletions manager/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,7 @@ func (r *Runner) init(clients *dep.ClientSet) error {
dep.SetVaultLeaseRenewalThreshold(*r.config.Vault.LeaseRenewalThreshold)

// Create the watcher
r.watcher = newWatcher(r.config, clients, r.config.Once)
r.watcher = newWatcher(r.config, clients)

numTemplates := len(*r.config.Templates)
templates := make([]*template.Template, 0, numTemplates)
Expand Down Expand Up @@ -1398,7 +1398,7 @@ func NewClientSet(c *config.Config) (*dep.ClientSet, error) {
}

// newWatcher creates a new watcher.
func newWatcher(c *config.Config, clients *dep.ClientSet, once bool) *watch.Watcher {
func newWatcher(c *config.Config, clients *dep.ClientSet) *watch.Watcher {
log.Printf("[INFO] (runner) creating watcher")

return watch.NewWatcher(&watch.NewWatcherInput{
Expand Down

0 comments on commit a3e4db1

Please sign in to comment.