Skip to content

Commit b1684bc

Browse files
author
Julien Pivotto
committed
Move isRunningInCE and isRunningInEE in their own helper
Signed-off-by: Julien Pivotto <[email protected]>
1 parent c28275f commit b1684bc

File tree

3 files changed

+41
-26
lines changed

3 files changed

+41
-26
lines changed

README.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,9 @@ Using the provider
3838
----------------------
3939
## Fill in for each provider
4040

41-
Developing the Provider
42-
---------------------------
41+
# Developing the Provider
4342

44-
If you wish to work on the provider, you'll first need [Go](http://www.golang.org) installed on your machine (version 1.11+ is *required*). You'll also need to correctly setup a [GOPATH](http://golang.org/doc/code.html#GOPATH), as well as adding `$GOPATH/bin` to your `$PATH`.
43+
If you wish to work on the provider, you'll first need [Go](http://www.golang.org) installed on your machine (version 1.14+ is *required*).
4544

4645
To compile the provider, run `make build`. This will build the provider and put the provider binary in the `$GOPATH/bin` directory.
4746

@@ -53,7 +52,8 @@ $ $GOPATH/bin/terraform-provider-gitlab
5352
```
5453

5554
### Running tests
56-
The Terraform Provider only has acceptance tests, these can run against a gitlab instance where you have a token with administrator permissions (likely not gitlab.com).
55+
56+
The Terraform Provider only has acceptance tests, these can run against a gitlab instance where you have a token with administrator permissions (likely not gitlab.com).
5757
There is excellent documentation on [how to run gitlab from docker at gitlab.com](https://docs.gitlab.com/omnibus/docker/)
5858

5959
In order to run the full suite of acceptance tests, export the environment variables:
@@ -66,3 +66,13 @@ and run `make testacc`.
6666
```sh
6767
$ make testacc
6868
```
69+
70+
### Gitlab Community Edition and Gitlab Entreprise Edition
71+
72+
This module supports both Gitlab CE and Gitlab EE. We run tests on Gitlab EE,
73+
but can't run them on pull requests from forks.
74+
75+
Features that only work on one flavour can use the following helpers as
76+
SkipFunc: `isRunningInEE` and `isRunningInCE`. You can see an exemple of this
77+
for [gitlab_project_push_rules](gitlab/resource_gitlab_project_push_rules_test.go)
78+
tests.

gitlab/helper_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package gitlab
22

33
import (
4+
"errors"
45
"fmt"
6+
"strings"
57

68
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
9+
"github.com/xanzy/go-gitlab"
710
)
811

912
// testAccCompareGitLabAttribute compares an attribute in two ResourceData's for
@@ -36,3 +39,27 @@ func testAccIsSkippedAttribute(needle string, haystack []string) bool {
3639
}
3740
return false
3841
}
42+
43+
// Returns true if the acceptance test is running Gitlab EE.
44+
// Meant to be used as SkipFunc to skip tests that work only on Gitlab CE.
45+
func isRunningInEE() (bool, error) {
46+
if conn, ok := testAccProvider.Meta().(*gitlab.Client); ok {
47+
version, _, err := conn.Version.GetVersion()
48+
if err != nil {
49+
return false, err
50+
}
51+
if strings.Contains(version.String(), "-ee") {
52+
return true, nil
53+
}
54+
} else {
55+
return false, errors.New("Provider not initialized, unable to get GitLab connection")
56+
}
57+
return false, nil
58+
}
59+
60+
// Returns true if the acceptance test is running Gitlab CE.
61+
// Meant to be used as SkipFunc to skip tests that work only on Gitlab EE.
62+
func isRunningInCE() (bool, error) {
63+
isEE, err := isRunningInEE()
64+
return !isEE, err
65+
}

gitlab/resource_gitlab_project_push_rules_test.go

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package gitlab
22

33
import (
4-
"errors"
54
"fmt"
6-
"strings"
75
"testing"
86

97
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
@@ -13,26 +11,6 @@ import (
1311
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
1412
)
1513

16-
func isRunningInEE() (bool, error) {
17-
if conn, ok := testAccProvider.Meta().(*gitlab.Client); ok {
18-
version, _, err := conn.Version.GetVersion()
19-
if err != nil {
20-
return false, err
21-
}
22-
if strings.Contains(version.String(), "-ee") {
23-
return true, nil
24-
}
25-
} else {
26-
return false, errors.New("Provider not initialized, unable to get GitLab connection")
27-
}
28-
return false, nil
29-
}
30-
31-
func isRunningInCE() (bool, error) {
32-
isEE, err := isRunningInEE()
33-
return !isEE, err
34-
}
35-
3614
func TestAccGitlabProjectPushRules_basic(t *testing.T) {
3715
var pushRules gitlab.ProjectPushRules
3816
rInt := acctest.RandInt()

0 commit comments

Comments
 (0)