-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expand test coverage, reinforce mocks (#16)
* Expand test coverage, reinforce mocks * A little more coverage around config
- Loading branch information
Showing
10 changed files
with
90 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,45 @@ | ||
package jenkins | ||
|
||
import ( | ||
"io" | ||
"io/ioutil" | ||
|
||
jenkins "github.com/bndr/gojenkins" | ||
) | ||
|
||
type jenkinsClient interface { | ||
CreateJobInFolder(config string, jobName string, parentIDs ...string) (*jenkins.Job, error) | ||
Credentials() *jenkins.CredentialsManager | ||
DeleteJob(name string) (bool, error) | ||
GetJob(id string, parentIDs ...string) (*jenkins.Job, error) | ||
} | ||
|
||
// jenkinsAdapter wraps the Jenkins client, enabling additional functionality | ||
type jenkinsAdapter struct { | ||
*jenkins.Jenkins | ||
} | ||
|
||
// Config is the set of parameters needed to configure the Jenkins provider. | ||
type Config struct { | ||
ServerURL string | ||
CACert string | ||
CACert io.Reader | ||
Username string | ||
Password string | ||
} | ||
|
||
func newJenkinsClient(c *Config) (*jenkins.Jenkins, error) { | ||
func newJenkinsClient(c *Config) *jenkinsAdapter { | ||
client := jenkins.CreateJenkins(nil, c.ServerURL, c.Username, c.Password) | ||
if c.CACert != "" { | ||
if c.CACert != nil { | ||
// provide CA certificate if server is using self-signed certificate | ||
client.Requester.CACert, _ = ioutil.ReadFile(c.CACert) | ||
} | ||
_, err := client.Init() | ||
if err != nil { | ||
return nil, err | ||
client.Requester.CACert, _ = ioutil.ReadAll(c.CACert) | ||
} | ||
|
||
// return the Jenkins API client | ||
return client, nil | ||
return &jenkinsAdapter{Jenkins: client} | ||
} | ||
|
||
func (j *jenkinsAdapter) Credentials() *jenkins.CredentialsManager { | ||
return &jenkins.CredentialsManager{ | ||
J: j.Jenkins, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters