Skip to content
This repository has been archived by the owner on Nov 11, 2020. It is now read-only.

chore: bump jx #1

Open
wants to merge 1 commit 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
12 changes: 6 additions & 6 deletions CONTRIBUTING.MD
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ A test is unencapsulated (not isolated) if it cannot be run (with repeatable suc
### Mocking / Stubbing
Mocking or stubbing methods in your unit tests will get you a long way towards test isolation. Coupled with the use of interface based APIs you should be able to make your methods easily testable and useful to other packages that may need to import them.
https://github.com/petergtz/pegomock Is our current mocking library of choice, mainly because it is very easy to use and doesn't require you to write your own mocks (Yay!)
We place all interfaces for each package in a file called `interface.go` in the relevant folder. So you can find all interfaces for `github.com/jenkins-x/jx/pkg/util` in `github.com/jenkins-x/jx/pkg/util/interface.go`
We place all interfaces for each package in a file called `interface.go` in the relevant folder. So you can find all interfaces for `github.com/jenkins-x/jx/v2/pkg/util` in `github.com/jenkins-x/jx/v2/pkg/util/interface.go`
Generating/Regenerating a mock for a given interface is easy, just go to the `interface.go` file that corresponds with the interface you would like to mock and add a comment directly above your interface definition that will look something like this:
```
// CommandInterface defines the interface for a Command
//go:generate pegomock generate github.com/jenkins-x/jx/pkg/util CommandInterface -o mocks/command_interface.go
//go:generate pegomock generate github.com/jenkins-x/jx/v2/pkg/util CommandInterface -o mocks/command_interface.go
type CommandInterface interface {
DidError() bool
DidFail() bool
Expand All @@ -146,7 +146,7 @@ type CommandInterface interface {
SetExponentialBackOff(*backoff.ExponentialBackOff)
}
```
In the example you can see that we pass the generator to use: `pegomock generate` the package path name: `github.com/jenkins-x/jx/pkg/util` the name of the interface: `CommandInterface` and finally an output directive to write the generated file to a mock subfolder. To keep things nice and tidy it's best to write each mocked interface to a separate file in this folder. So in this case: `-o mocks/command_interface.go`
In the example you can see that we pass the generator to use: `pegomock generate` the package path name: `github.com/jenkins-x/jx/v2/pkg/util` the name of the interface: `CommandInterface` and finally an output directive to write the generated file to a mock subfolder. To keep things nice and tidy it's best to write each mocked interface to a separate file in this folder. So in this case: `-o mocks/command_interface.go`

Now simply run:
```
Expand All @@ -167,8 +167,8 @@ import (
"errors"
"testing"

"github.com/jenkins-x/jx/pkg/util"
mocks "github.com/jenkins-x/jx/pkg/util/mocks"
"github.com/jenkins-x/jx/v2/pkg/util"
mocks "github.com/jenkins-x/jx/v2/pkg/util/mocks"
. "github.com/petergtz/pegomock"
"github.com/stretchr/testify/assert"
)
Expand All @@ -185,7 +185,7 @@ func TestJXBinaryLocationSuccess(t *testing.T) {
```
Here we're importing the mock we need in our import declaration:
```
mocks "github.com/jenkins-x/jx/pkg/util/mocks"
mocks "github.com/jenkins-x/jx/v2/pkg/util/mocks"
```
Then inside the test we're instantiating `NewMockCommandInterface` which was automatically generated for us by pegomock.

Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
module github.com/jenkins-x-labs/trigger-pipeline

require (
github.com/google/btree v1.0.0 // indirect
github.com/jenkins-x/golang-jenkins v0.0.0-20180919102630-65b83ad42314
github.com/jenkins-x/jx v1.3.981-0.20200605070345-2c10fe601319
github.com/jenkins-x/jx/v2 v2.1.59
github.com/magiconair/properties v1.8.0
github.com/pkg/errors v0.8.1
github.com/spf13/cobra v0.0.5
Expand Down
119 changes: 119 additions & 0 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/jenkins-x-labs/trigger-pipeline/pkg/cmd/server"
"github.com/jenkins-x-labs/trigger-pipeline/pkg/cmd/trigger"
"github.com/jenkins-x-labs/trigger-pipeline/pkg/common"
"github.com/jenkins-x/jx/pkg/log"
"github.com/jenkins-x/jx/v2/pkg/log"
"github.com/spf13/cobra"
)

Expand Down
10 changes: 5 additions & 5 deletions pkg/cmd/server/server_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import (
"github.com/jenkins-x-labs/trigger-pipeline/pkg/common"
"github.com/jenkins-x-labs/trigger-pipeline/pkg/jenkinsutil"
"github.com/jenkins-x-labs/trigger-pipeline/pkg/jenkinsutil/factory"
"github.com/jenkins-x/jx/pkg/cmd/helper"
"github.com/jenkins-x/jx/pkg/cmd/templates"
"github.com/jenkins-x/jx/pkg/kube/naming"
"github.com/jenkins-x/jx/pkg/log"
"github.com/jenkins-x/jx/pkg/util"
"github.com/jenkins-x/jx/v2/pkg/cmd/helper"
"github.com/jenkins-x/jx/v2/pkg/cmd/templates"
"github.com/jenkins-x/jx/v2/pkg/kube/naming"
"github.com/jenkins-x/jx/v2/pkg/log"
"github.com/jenkins-x/jx/v2/pkg/util"
"github.com/pkg/errors"
"github.com/spf13/cobra"
corev1 "k8s.io/api/core/v1"
Expand Down
8 changes: 4 additions & 4 deletions pkg/cmd/server/server_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
"github.com/jenkins-x-labs/trigger-pipeline/pkg/common"
"github.com/jenkins-x-labs/trigger-pipeline/pkg/jenkinsutil"
"github.com/jenkins-x-labs/trigger-pipeline/pkg/jenkinsutil/factory"
"github.com/jenkins-x/jx/pkg/cmd/helper"
"github.com/jenkins-x/jx/pkg/cmd/templates"
"github.com/jenkins-x/jx/pkg/log"
"github.com/jenkins-x/jx/pkg/util"
"github.com/jenkins-x/jx/v2/pkg/cmd/helper"
"github.com/jenkins-x/jx/v2/pkg/cmd/templates"
"github.com/jenkins-x/jx/v2/pkg/log"
"github.com/jenkins-x/jx/v2/pkg/util"
"github.com/pkg/errors"
"github.com/spf13/cobra"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down
6 changes: 3 additions & 3 deletions pkg/cmd/server/server_jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"github.com/jenkins-x-labs/trigger-pipeline/pkg/common"
"github.com/jenkins-x-labs/trigger-pipeline/pkg/jenkinsutil"
"github.com/jenkins-x-labs/trigger-pipeline/pkg/jenkinsutil/factory"
"github.com/jenkins-x/jx/pkg/cmd/helper"
"github.com/jenkins-x/jx/pkg/cmd/templates"
"github.com/jenkins-x/jx/pkg/table"
"github.com/jenkins-x/jx/v2/pkg/cmd/helper"
"github.com/jenkins-x/jx/v2/pkg/cmd/templates"
"github.com/jenkins-x/jx/v2/pkg/table"
"github.com/spf13/cobra"
)

Expand Down
10 changes: 5 additions & 5 deletions pkg/cmd/server/server_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import (
"github.com/jenkins-x-labs/trigger-pipeline/pkg/common"
"github.com/jenkins-x-labs/trigger-pipeline/pkg/jenkinsutil"
"github.com/jenkins-x-labs/trigger-pipeline/pkg/jenkinsutil/factory"
"github.com/jenkins-x/jx/pkg/cmd/helper"
"github.com/jenkins-x/jx/pkg/cmd/templates"
"github.com/jenkins-x/jx/pkg/log"
"github.com/jenkins-x/jx/pkg/table"
"github.com/jenkins-x/jx/pkg/util"
"github.com/jenkins-x/jx/v2/pkg/cmd/helper"
"github.com/jenkins-x/jx/v2/pkg/cmd/templates"
"github.com/jenkins-x/jx/v2/pkg/log"
"github.com/jenkins-x/jx/v2/pkg/table"
"github.com/jenkins-x/jx/v2/pkg/util"
"github.com/spf13/cobra"
)

Expand Down
18 changes: 9 additions & 9 deletions pkg/cmd/trigger/trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import (
"github.com/jenkins-x-labs/trigger-pipeline/pkg/jenkinsutil"
"github.com/jenkins-x-labs/trigger-pipeline/pkg/jenkinsutil/factory"
gojenkins "github.com/jenkins-x/golang-jenkins"
"github.com/jenkins-x/jx/pkg/cmd/helper"
"github.com/jenkins-x/jx/pkg/gits"

"github.com/jenkins-x/jx/pkg/cmd/templates"
"github.com/jenkins-x/jx/pkg/jenkins"
"github.com/jenkins-x/jx/pkg/jenkinsfile"
"github.com/jenkins-x/jx/pkg/log"
"github.com/jenkins-x/jx/pkg/util"
"github.com/jenkins-x/jx/v2/pkg/cmd/helper"
"github.com/jenkins-x/jx/v2/pkg/gits"

"github.com/jenkins-x/jx/v2/pkg/cmd/templates"
"github.com/jenkins-x/jx/v2/pkg/jenkins"
"github.com/jenkins-x/jx/v2/pkg/jenkinsfile"
"github.com/jenkins-x/jx/v2/pkg/log"
"github.com/jenkins-x/jx/v2/pkg/util"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -170,7 +170,7 @@ func (o *TriggerOptions) TriggerPipeline(jenkinsClient gojenkins.JenkinsClient,
return err
}
} else {
gitURL := gitInfo.HttpCloneURL()
gitURL := gitInfo.HttpURL()
log.Logger().Infof("Using git URL %s and branch %s", util.ColorInfo(gitURL), util.ColorInfo(branch))

err = helpers.Retry(3, time.Second*10, func() error {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/trigger/trigger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/jenkins-x-labs/trigger-pipeline/pkg/cmd/trigger"
"github.com/jenkins-x-labs/trigger-pipeline/pkg/jenkinsutil/fake"
"github.com/jenkins-x/jx/pkg/gits"
"github.com/jenkins-x/jx/v2/pkg/gits"
"github.com/magiconair/properties/assert"
"github.com/stretchr/testify/require"
)
Expand Down
6 changes: 3 additions & 3 deletions pkg/common/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"os"
"strconv"

"github.com/jenkins-x/jx/pkg/cmd/opts"
"github.com/jenkins-x/jx/pkg/log"
"github.com/jenkins-x/jx/pkg/util"
"github.com/jenkins-x/jx/v2/pkg/cmd/opts"
"github.com/jenkins-x/jx/v2/pkg/log"
"github.com/jenkins-x/jx/v2/pkg/util"
"github.com/spf13/cobra"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/helpers/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"time"

"github.com/jenkins-x/jx/pkg/log"
"github.com/jenkins-x/jx/v2/pkg/log"
)

// Retry executes a given function and reties 'attempts' times with a delay of 'sleep' between the executions
Expand Down
8 changes: 4 additions & 4 deletions pkg/jenkinsutil/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"net/url"

gojenkins "github.com/jenkins-x/golang-jenkins"
"github.com/jenkins-x/jx/pkg/kube"
"github.com/jenkins-x/jx/pkg/kube/services"
"github.com/jenkins-x/jx/pkg/log"
"github.com/jenkins-x/jx/pkg/util"
"github.com/jenkins-x/jx/v2/pkg/kube"
"github.com/jenkins-x/jx/v2/pkg/kube/services"
"github.com/jenkins-x/jx/v2/pkg/log"
"github.com/jenkins-x/jx/v2/pkg/util"
"github.com/pkg/errors"
v1 "k8s.io/api/core/v1"
"k8s.io/client-go/kubernetes"
Expand Down
2 changes: 1 addition & 1 deletion pkg/jenkinsutil/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"sort"

"github.com/jenkins-x-labs/trigger-pipeline/pkg/common"
"github.com/jenkins-x/jx/pkg/log"
"github.com/jenkins-x/jx/v2/pkg/log"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down
2 changes: 1 addition & 1 deletion pkg/jenkinsutil/factory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package factory

import (
"github.com/jenkins-x-labs/trigger-pipeline/pkg/jenkinsutil"
"github.com/jenkins-x/jx/pkg/jxfactory"
"github.com/jenkins-x/jx/v2/pkg/jxfactory"
"k8s.io/client-go/rest"
)

Expand Down
10 changes: 5 additions & 5 deletions pkg/jenkinsutil/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import (
"time"

gojenkins "github.com/jenkins-x/golang-jenkins"
"github.com/jenkins-x/jx/pkg/builds"
"github.com/jenkins-x/jx/pkg/gits"
jxjenkins "github.com/jenkins-x/jx/pkg/jenkins"
"github.com/jenkins-x/jx/pkg/log"
"github.com/jenkins-x/jx/pkg/util"
"github.com/jenkins-x/jx/v2/pkg/builds"
"github.com/jenkins-x/jx/v2/pkg/gits"
jxjenkins "github.com/jenkins-x/jx/v2/pkg/jenkins"
"github.com/jenkins-x/jx/v2/pkg/log"
"github.com/jenkins-x/jx/v2/pkg/util"
"github.com/spf13/cobra"
)

Expand Down