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

Package Structure #11

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft

Package Structure #11

wants to merge 2 commits into from

Conversation

amigus
Copy link
Contributor

@amigus amigus commented May 7, 2022

Adopt the standard cmd/, pkg/ structure and update the tests accordingly.

amigus added 2 commits May 7, 2022 15:23
- Move main.go into cmd/example
- Move vault into pkg/
- Create better configuration processing logic
- Update tests accordingly
- Refactor tests
var dsv *vault.Vault

if config, err := vault.GetConfigFromEnv(); err != nil {
log.Fatalf("[ERROR] DSV_SDK_CONFIG or DSV_SDK_CONFIG_File must be set")
Copy link
Collaborator

Choose a reason for hiding this comment

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

typo: "DSV_SDK_CONFIG_File" -> "DSV_SDK_CONFIG_FILE"

Copy link
Collaborator

Choose a reason for hiding this comment

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

error returned by GetConfigFromEnv() should not be ignored

}

func ParseConfig(filePath string) (*Configuration, error) {
if content, err := ioutil.ReadFile(filePath); err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

It is recommended to use os.ReadFile() in a new code. Please change to os.ReadFile(filePath)

ConfigFileEnvVar = "DSV_SDK_CONFIG_FILE"
)

func UnmarshalConfig(configJson []byte) (*Configuration, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this func should not be exported.

}
}

func ParseConfig(filePath string) (*Configuration, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this func should not be exported.

})
t.Run("Delete", func(t *testing.T) {
if client, err := vault.Client(id); err != nil {
t.Errorf("calling clients.Client(\"%s\"): %s", id, err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

typo: "calling clients.Client(" -> "calling vault.Client("

Copy link
Collaborator

Choose a reason for hiding this comment

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

it is better to use %q instead of \"%s\"

})
t.Run("Get", func(t *testing.T) {
if client, err := vault.Client(id); err != nil {
t.Errorf("calling clients.Client(\"%s\"): %s", id, err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

typo: "calling clients.Client(" -> "calling vault.Client("

Copy link
Collaborator

Choose a reason for hiding this comment

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

it is better to use %q instead of \"%s\"

client := &Client{clientResource: clientResource{RoleName: roleName}}

if err := vault.New(client); err != nil {
t.Errorf("calling clients.New(\"%s\"): %s", roleName, err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

typo: "calling clients.New(" -> "calling vault.New("

Copy link
Collaborator

Choose a reason for hiding this comment

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

it is better to use %q instead of \"%s\"

} else if v := os.Getenv(ConfigFileEnvVar); v != "" {
return ParseConfig(v)
} else {
return nil, nil
Copy link
Collaborator

Choose a reason for hiding this comment

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

probably should return non-nil error in this case

@amigus amigus marked this pull request as draft May 9, 2022 14:42
@amigus amigus requested a review from EndlessTrax May 9, 2022 14:43
@amigus
Copy link
Contributor Author

amigus commented May 9, 2022

Thanks for your suggestions. I will accept them all, however, I'm sorry, but I mistakenly submitted this PR. I meant to mark it draft and should have submitted it as an issue first, anyway.

I won't delete the PR now that the discussion is here but I have marked it as a draft.

@EndlessTrax EndlessTrax linked an issue May 10, 2022 that may be closed by this pull request
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.

Insufficient documentation on unit test configuration
2 participants