Skip to content

Commit b2e552f

Browse files
feat/pm-298: Modified tests and provider to run tests in ci/cd pipeline (#123)
1 parent 81c54b6 commit b2e552f

File tree

8 files changed

+40
-32
lines changed

8 files changed

+40
-32
lines changed

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ build:
4343

4444
# acceptance tests
4545
.PHONY: test
46-
test: build
46+
test:
4747
cd v2 && \
48-
TF_ACC=1 go test -v ./... && \
48+
TF_ACC=1 TF_CLI_CONFIG_FILE="${PWD}/dev.tfrc" go test -v ./... && \
4949
cd -
5050

5151
.PHONY: test-run
52-
test-run: build
52+
test-run:
5353
cd v2 && \
5454
go vet ./... && \
55-
TF_ACC=1 go test -v ./... -run $(case) && \
55+
TF_ACC=1 TF_CLI_CONFIG_FILE="${PWD}/dev.tfrc" go test -v ./... -run $(case) && \
5656
cd -
5757

5858
.PHONY: udpatedeps

v2/resources/provider.go

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818

1919
var (
2020
version string = "dev"
21+
defaultURL string = "zedcontrol.local.zededa.net"
2122
)
2223

2324
func Provider() *schema.Provider {
@@ -28,8 +29,7 @@ func Provider() *schema.Provider {
2829
Type: schema.TypeString,
2930
Optional: true,
3031
Description: "ZEDCloud url. Ex: https://zedcontrol.zededa.net",
31-
Default: "zedcontrol.local.zededa.net",
32-
DefaultFunc: schema.EnvDefaultFunc("TF_VAR_zedcloud_url", nil),
32+
DefaultFunc: schema.EnvDefaultFunc("TF_VAR_zedcloud_url", defaultURL),
3333
},
3434
"zedcloud_token": {
3535
Type: schema.TypeString,
@@ -87,16 +87,21 @@ func NewHttpTransportWrapper(rt http.RoundTripper) *HttpTransportWrapper {
8787
if err != nil {
8888
wrapper.providerVersion = "v0.0.0"
8989
} else {
90-
execNameParts := strings.Split(execName, "_")
91-
if len(execNameParts) != 2 {
92-
if version != "dev" {
93-
wrapper.providerVersion = fmt.Sprintf("v%s", version)
90+
if !strings.Contains(execName, "resources.test") {
91+
execNameParts := strings.Split(execName, "_")
92+
if len(execNameParts) != 2 {
93+
if version != "dev" {
94+
wrapper.providerVersion = fmt.Sprintf("v%s", version)
95+
} else {
96+
wrapper.providerVersion = "v0.0.0"
97+
}
9498
} else {
95-
wrapper.providerVersion = "v0.0.0"
99+
wrapper.providerVersion = execNameParts[1]
96100
}
97101
} else {
98-
wrapper.providerVersion = execNameParts[1]
102+
wrapper.providerVersion = "testbuild"
99103
}
104+
100105
}
101106

102107
return wrapper
@@ -110,7 +115,10 @@ func (h *HttpTransportWrapper) RoundTrip(req *http.Request) (*http.Response, err
110115
}
111116

112117
func ProviderConfigure(ctx context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) {
113-
zedCloudURL := d.Get("zedcloud_url").(string)
118+
zedCloudURL, urlIsSet := d.Get("zedcloud_url").(string)
119+
if !urlIsSet || zedCloudURL == "" {
120+
return nil, diag.FromErr(errors.New("zedcloud URL must be set"))
121+
}
114122

115123
token, tokenIsSet := d.Get("zedcloud_token").(string)
116124
if !tokenIsSet || token == "" {

v2/resources/testdata/application/create.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ resource "zedcloud_application" "test_tf_provider" {
2121
depends_on = [
2222
zedcloud_project.test_tf_provider
2323
]
24-
name = "ubuntu-all-ip"
25-
title = "ubuntu-all-ip"
26-
description = "ubuntu-all-ip"
24+
name = "test_tf_provider-ubuntu-all-ip"
25+
title = "test_tf_provider-ubuntu-all-ip"
26+
description = "test_tf_provider-ubuntu-all-ip"
2727
user_defined_version = "1.1"
2828
origin_type = "ORIGIN_LOCAL"
2929
project_access_list = [zedcloud_project.test_tf_provider.id]

v2/resources/testdata/application/create.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cpus: 2
2-
description: ubuntu-all-ip
2+
description: test_tf_provider-ubuntu-all-ip
33
drives: 1
44
id: 5ff2ba22-827c-427f-92b9-93673569eeab
55
isimported: false
@@ -100,7 +100,7 @@ manifest:
100100
value: "1024000"
101101
vmmode: HV_HVM
102102
memory: 1024000
103-
name: ubuntu-all-ip
103+
name: test_tf_provider-ubuntu-all-ip
104104
networks: 1
105105
origintype: ORIGIN_LOCAL
106106
parentdetail:
@@ -116,5 +116,5 @@ revision:
116116
updatedat: "2023-02-12T14:45:49.847Z"
117117
updatedby: us.root@zededa.com
118118
storage: 0
119-
title: ubuntu-all-ip
119+
title: test_tf_provider-ubuntu-all-ip
120120
userdefinedversion: "1.1"

v2/resources/testdata/application/create_from_file.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
resource "zedcloud_application" "test_tf_provider" {
2-
name = "ubuntu-all-ip"
3-
title = "ubuntu-all-ip"
4-
description = "ubuntu-all-ip"
2+
name = "test_tf_provider-ubuntu-all-ip"
3+
title = "test_tf_provider-ubuntu-all-ip"
4+
description = "test_tf_provider-ubuntu-all-ip"
55
manifest_file = "./testdata/application/create_manifest.json"
66
user_defined_version = "1.1"
77
origin_type = "ORIGIN_LOCAL"

v2/resources/testdata/application/create_from_file.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cpus: 2
2-
description: ubuntu-all-ip
2+
description: test_tf_provider-ubuntu-all-ip
33
drives: 1
44
id: 179a7fda-eadd-4047-95a2-cd936fffa4e6
55
isimported: false
@@ -83,7 +83,7 @@ manifest:
8383
value: "1024000"
8484
vmmode: ""
8585
memory: 1024000
86-
name: ubuntu-all-ip
86+
name: test_tf_provider-ubuntu-all-ip
8787
networks: 1
8888
origintype: ORIGIN_LOCAL
8989
parentdetail:
@@ -100,5 +100,5 @@ revision:
100100
updatedat: "2023-02-12T14:45:19.575Z"
101101
updatedby: us.root@zededa.com
102102
storage: 0
103-
title: ubuntu-all-ip
103+
title: test_tf_provider-ubuntu-all-ip
104104
userdefinedversion: "1.1"

v2/resources/testdata/application_instance/create.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ resource "zedcloud_datastore" "test_tf_provider" {
2525
ds_fqdn = "my-datastore.my-company.com"
2626
ds_path = "download/AMD64"
2727
ds_type = "DATASTORE_TYPE_AZUREBLOB"
28-
name = "test"
29-
title = "title"
28+
name = "test_tf_provider-test-datastore"
29+
title = "test_tf_provider-title"
3030
description = "description"
3131
region = "eu"
3232
project_access_list = [zedcloud_project.test_tf_provider.id]
@@ -145,8 +145,8 @@ data "zedcloud_edgenode" "test_tf_provider" {
145145

146146
resource "zedcloud_application" "test_tf_provider" {
147147
name = "test_tf_provider"
148-
title = "ubuntu-all-ip"
149-
description = "ubuntu-all-ip"
148+
title = "test_tf_provider-ubuntu-all-ip"
149+
description = "test_tf_provider-ubuntu-all-ip"
150150
user_defined_version = "1.1"
151151
origin_type = "ORIGIN_LOCAL"
152152
manifest {

v2/resources/testdata/iam/user.create.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
resource "zedcloud_role" "test_tf_provider" {
2-
name = "test-role"
3-
title = "test-role"
4-
type = "USER_ROLE_SYSTEM_DEFINED"
2+
name = "test_tf_provider-test-role"
3+
title = "test_tf_provider-test-role"
4+
type = "USER_ROLE_USER_DEFINED"
55
state = "ROLE_STATE_ACTIVE"
66
scopes {
77
enterprise_filter = []

0 commit comments

Comments
 (0)