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

PMM-4879: defaults-file param #171

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open

PMM-4879: defaults-file param #171

wants to merge 15 commits into from

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)

@@ -110,3 +113,63 @@ func TestReadFile(t *testing.T) {
require.Empty(t, certificate)
})
}

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
Member

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)

@@ -160,3 +162,92 @@ func TestRun(t *testing.T) {
}
})
}

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)

@@ -69,6 +73,10 @@ type Command interface {
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

@@ -160,3 +164,87 @@ func TestRun(t *testing.T) {
}
})
}

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.

@@ -184,6 +193,37 @@ func (e errFromNginx) GoString() string {
return fmt.Sprintf("errFromNginx(%q)", string(e))
}

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

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

"strings"
"testing"

"gopkg.in/ini.v1"

Copy link
Member

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

@@ -110,3 +113,63 @@ func TestReadFile(t *testing.T) {
require.Empty(t, certificate)
})
}

type cmdWithDefaultsApply struct {
applyDefaultCalled bool
Copy link
Member

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
Member

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
Member

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
Member

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