Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add options to test setup function #305

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,18 @@ if err != nil {

## Testing

To run only unit tests:

go test

To run unit and integration tests:

INTEGRATION=true go test

By default, integration tests connect to `http://localhost:8080` using the username `admin` and the password `admin`. To modify this behaviour, override the test options:

INTEGRATION=true go test -addr "http://jenkins:8080" -user "jenkins" -password "secret1"

## Contribute

All Contributions are welcome. The todo list is on the bottom of this README. Feel free to send a pull request.
Expand Down
11 changes: 10 additions & 1 deletion credentials_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package gojenkins

import (
"context"
"flag"
"fmt"
"os"
"testing"
Expand All @@ -21,6 +22,10 @@ var (
scope = "GLOBAL"
)

var jenkinsAddr = flag.String("addr", "http://localhost:8080", "Jenkins address")
var jenkinsUsername = flag.String("user", "admin", "Jenkins username")
var jenkinsPassword = flag.String("password", "admin", "Jenkins password")

func TestCreateUsernameCredentials(t *testing.T) {
if _, ok := os.LookupEnv(integration_test); !ok {
return
Expand Down Expand Up @@ -69,6 +74,7 @@ func TestCreateFileCredentials(t *testing.T) {
assert.Equal(t, cred.Filename, cred.Filename, "Filename is not equal")
}

// TestCreateDockerCredentials requires Docker Commons plugin
func TestCreateDockerCredentials(t *testing.T) {
if _, ok := os.LookupEnv(integration_test); !ok {
return
Expand Down Expand Up @@ -134,10 +140,13 @@ func TestCreateSSHCredentialsFullFlow(t *testing.T) {

}

// TestMain setups the Jenkins client for all tests.
// Available options are: -addr -user -password
func TestMain(m *testing.M) {
//setup
flag.Parse()
ctx := context.Background()
jenkins := CreateJenkins(nil, "http://localhost:8080", "admin", "admin")
jenkins := CreateJenkins(nil, *jenkinsAddr, *jenkinsUsername, *jenkinsPassword)
jenkins.Init(ctx)

cm = &CredentialsManager{J: jenkins}
Expand Down
2 changes: 1 addition & 1 deletion jenkins_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestInit(t *testing.T) {
return
}
ctx := context.Background()
jenkins = CreateJenkins(nil, "http://localhost:8080", "admin", "admin")
jenkins = CreateJenkins(nil, *jenkinsAddr, *jenkinsUsername, *jenkinsPassword)
_, err := jenkins.Init(ctx)
assert.Nil(t, err, "Jenkins Initialization should not fail")
}
Expand Down