Skip to content
This repository was archived by the owner on Jun 1, 2022. It is now read-only.

PMM-4879: defaults-file param#171

Open
ritbl wants to merge 15 commits intomainfrom
PMM-4879
Open

PMM-4879: defaults-file param#171
ritbl wants to merge 15 commits intomainfrom
PMM-4879

Conversation

@ritbl
Copy link
Contributor

@ritbl ritbl commented Dec 23, 2021

Jira Ticket and related ticket
FB

  • provides extension point to process default params by implementing commands.ApplyDefaults
  • username and password set via CLI flag have higher priority (e.g. values from defaults file are used only if values are not initialized)

}

type cmdWithDefaultsApply struct {
applyDefaultCalled bool
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

used for tests only

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why don't use mock libraries?


cmd := &addMySQLCommand{}

commands.ConfigureDefaults(file.Name(), cmd)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
Error return value of commands.ConfigureDefaults is not checked (errcheck)

Password: "default-password",
}

commands.ConfigureDefaults(file.Name(), cmd)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
Error return value of commands.ConfigureDefaults is not checked (errcheck)

Password: "default-password",
}

commands.ConfigureDefaults(file.Name(), cmd)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
Error return value of commands.ConfigureDefaults is not checked (errcheck)

})
}

func TestApplyDefaults(t *testing.T) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
Function 'TestApplyDefaults' is too long (86 > 60) (funlen)

Run() (Result, error)
}

type ApplyDefaults interface {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
exported type ApplyDefaults should have comment or be unexported (golint)

}

func TestConfigureDefaults(t *testing.T) {
t.Run("ApplyDefaults is called if command supports it", func(t *testing.T) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
Function TestConfigureDefaults has missing the call to method parallel in the test run (paralleltest)

assert.Equal(t, "toor", cmd.password)
})

t.Run("ApplyDefaults is not called if pass is not setup", func(t *testing.T) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
Function TestConfigureDefaults has missing the call to method parallel in the test run (paralleltest)

})
}

func TestExpandPath(t *testing.T) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
Function TestExpandPath missing the call to method parallel (paralleltest)

}

func TestExpandPath(t *testing.T) {
t.Run("relative to userhome", func(t *testing.T) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
Function TestExpandPath has missing the call to method parallel in the test run (paralleltest)


assert.Equal(t, usr.HomeDir, actual)
})
t.Run("relative to userhome", func(t *testing.T) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
Function TestExpandPath has missing the call to method parallel in the test run (paralleltest)


func TestConfigureDefaults(t *testing.T) {
t.Run("ApplyDefaults is called if command supports it", func(t *testing.T) {
file, e := os.Open("../testdata/.my.cnf")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BupycHuk you were asking for it. I use real file in cmd test, but tmp files for commands/management/add_mysql.go

})
}

func TestApplyDefaults(t *testing.T) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
Function 'TestApplyDefaults' is too long (81 > 60) (funlen)

@ritbl ritbl marked this pull request as ready for review December 23, 2021 12:19
@@ -0,0 +1,5 @@
[client]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return fmt.Sprintf("errFromNginx(%q)", string(e))
}

func ConfigureDefaults(config string, cmd ApplyDefaults) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think its better to rename it to configPath

"testing"

"gopkg.in/ini.v1"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's remove this blank line

}

type cmdWithDefaultsApply struct {
applyDefaultCalled bool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why don't use mock libraries?


assert.Equal(t, usr.HomeDir, actual)
})
t.Run("relative to userhome", func(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it doesn't look relative to userhome

Comment on lines +24 to +29
"github.com/sirupsen/logrus"

"gopkg.in/ini.v1"

"github.com/percona/pmm-admin/agentlocal"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please fix imports to split them in 3 blocks

  1. go libs
  2. 3rd party libs
  3. local packages

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here and in other files

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants