Skip to content

Commit

Permalink
Improves logging (#97)
Browse files Browse the repository at this point in the history
* Improves logging

- Credential configuring message now only prints if there are any
bindings instead of always
- Now print the number of custom credential managers that were
configured

* Adds log line to integration tests
  • Loading branch information
ForestEckhardt authored Feb 17, 2022
1 parent 8c932c0 commit 261356f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
10 changes: 8 additions & 2 deletions git_credential_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,18 @@ func NewGitCredentialManager(bindingResolver BindingResolver, executable Executa
}

func (g GitCredentialManager) Setup(workingDir, platformDir string) error {
g.logs.Process("Configuring credentials")

bindings, err := g.bindingResolver.Resolve("git-credentials", "", platformDir)
if err != nil {
return err
}

if len(bindings) == 0 {
// If there are no bindings then we are done
return nil
}

g.logs.Process("Configuring credentials")

uniqueContext := map[string]interface{}{}

for _, b := range bindings {
Expand Down Expand Up @@ -80,6 +85,7 @@ func (g GitCredentialManager) Setup(workingDir, platformDir string) error {

}

g.logs.Process("Added %d custom git credential manager(s) to the git config", len(uniqueContext))
g.logs.Break()
return nil
}
8 changes: 8 additions & 0 deletions git_credential_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ func testGitCredentialManager(t *testing.T, context spec.G, it spec.S) {

Expect(bindingResolver.ResolveCall.Receives.PlatformDir).To(Equal(platformDir))
Expect(executable.ExecuteCall.CallCount).To(Equal(0))

Expect(buffer.String()).ToNot(ContainSubstring("Configuring credentials"))
})
})

Expand Down Expand Up @@ -91,6 +93,9 @@ func testGitCredentialManager(t *testing.T, context spec.G, it spec.S) {
"credential.helper",
fmt.Sprintf("!f() { cat %q; }; f", filepath.Join("some-path", "credentials")),
}))

Expect(buffer.String()).To(ContainSubstring("Configuring credentials"))
Expect(buffer.String()).To(ContainSubstring("Added 1 custom git credential manager(s) to the git config"))
})
})

Expand Down Expand Up @@ -164,6 +169,9 @@ func testGitCredentialManager(t *testing.T, context spec.G, it spec.S) {
"credential.https://example.com.helper",
fmt.Sprintf("!f() { cat %q; }; f", filepath.Join("other-path", "credentials")),
}))

Expect(buffer.String()).To(ContainSubstring("Configuring credentials"))
Expect(buffer.String()).To(ContainSubstring("Added 2 custom git credential manager(s) to the git config"))
})
})

Expand Down
1 change: 1 addition & 0 deletions integration/credential_configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func testCredentialConfiguration(t *testing.T, context spec.G, it spec.S) {
` REVISION -> "2df6ac40991b695cc6c31faa79926980ff7dc0ff"`,
"",
" Configuring credentials",
" Added 1 custom git credential manager(s) to the git config",
"",
"Paketo Credential Fill Buildpack",
"protocol=https",
Expand Down

0 comments on commit 261356f

Please sign in to comment.