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 unit testing to the provider #662

Merged
merged 10 commits into from
Oct 7, 2023
Merged

Add unit testing to the provider #662

merged 10 commits into from
Oct 7, 2023

Conversation

t0yv0
Copy link
Member

@t0yv0 t0yv0 commented Oct 6, 2023

Fixes #661

The reason I'm working on this now is that I'd like to really move upgrade tests out of examples and under provider/ in AWS (and soon GCP). pulumi/pulumi-aws#2855

@t0yv0 t0yv0 requested a review from a team October 6, 2023 02:03
(cd provider && go build $(PULUMI_PROVIDER_BUILD_PARALLELISM) -o $(WORKING_DIR)/bin/$(PROVIDER) -ldflags "-X $(PROJECT)/$(VERSION_PATH)=$(VERSION)#{{if .Config.providerVersion}}# -X #{{ .Config.providerVersion }}#=$(VERSION)#{{end}}#" $(PROJECT)/$(PROVIDER_PATH)/cmd/$(PROVIDER))

test:
cd examples && go test -v -tags=all -parallel $(TESTPARALLELISM) -timeout 2h

test_provider: tfgen
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested this without tfgen dependency on pulumi-azuread, but it breaks because of go:embed files. That's really not great. I wonder if we could fix that up so that code compiles and is able to test itself even if generated files are not present yet. For now leaving this in.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which go:embed files are missing? I don't think we had that problem with pulumi-aws. We should definitely make sure we don't need the : tfgen long term.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it was the bridge-metadata one.

(cd provider && go build $(PULUMI_PROVIDER_BUILD_PARALLELISM) -o $(WORKING_DIR)/bin/$(PROVIDER) -ldflags "-X $(PROJECT)/$(VERSION_PATH)=$(VERSION)#{{if .Config.providerVersion}}# -X #{{ .Config.providerVersion }}#=$(VERSION)#{{end}}#" $(PROJECT)/$(PROVIDER_PATH)/cmd/$(PROVIDER))

test:
cd examples && go test -v -tags=all -parallel $(TESTPARALLELISM) -timeout 2h

test_provider: tfgen
@echo ""
@echo "== test_provider ==================================================================="
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the visual marker really easy to get lost in the tfgen noise.

(cd provider && go build $(PULUMI_PROVIDER_BUILD_PARALLELISM) -o $(WORKING_DIR)/bin/$(PROVIDER) -ldflags "-X $(PROJECT)/$(VERSION_PATH)=$(VERSION)#{{if .Config.providerVersion}}# -X #{{ .Config.providerVersion }}#=$(VERSION)#{{end}}#" $(PROJECT)/$(PROVIDER_PATH)/cmd/$(PROVIDER))

test:
cd examples && go test -v -tags=all -parallel $(TESTPARALLELISM) -timeout 2h

test_provider: tfgen
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which go:embed files are missing? I don't think we had that problem with pulumi-aws. We should definitely make sure we don't need the : tfgen long term.

@@ -119,12 +119,18 @@ install_plugins: .pulumi/bin/pulumi
lint_provider: provider
cd provider && golangci-lint run -c ../.golangci.yml

provider: tfgen install_plugins
provider: tfgen install_plugins test_provider
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems inverted. I generally expect that test_provider: provider but not vice versa.

Instead of making provider depend on test_provider, can we just add a step in run-acceptence-tests.yml (probably prerequisites) that calls make test_provider?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reasoning here is that provider builds a binary from go sources. Those sources better be tested first.

can we just add a step in run-acceptence-tests.yml

Sad here that run-acceptance-tests.yml is duplicated N ways. I'd have to refactor it first to pull out the common bits. I can give this a look.

@iwahbe
Copy link
Member

iwahbe commented Oct 6, 2023

FYI: If you want to get tests working "right now", you can add the extra test to extraTests and run make ci-mgmt. We already have an existing extra test for pulumi-aws:

https://github.com/pulumi/pulumi-aws/blob/0b33b02036fcf1cae354aae98a9d278e957e0199/.ci-mgmt.yaml#L69-L94

@t0yv0
Copy link
Member Author

t0yv0 commented Oct 6, 2023

This simpler version seems to work in:

https://github.com/pulumi/pulumi-azuread/actions/runs/6437059888/job/17481565040#step:10:37

By running tests after building as a separate step, this bypasses the need to model the dependency in Make. A bit awkward but the least evil quick option at the moment it seems like. Locally, you just have to "know" you need to run tfgen before.

@iwahbe another look?

@t0yv0 t0yv0 requested a review from iwahbe October 6, 2023 22:33
Copy link
Member

@iwahbe iwahbe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Nit: It would be great to add a comment in the Makefile explaining that test_provider needs tfgen, but we haven't modeled the dependency because of performance reasons.

@t0yv0
Copy link
Member Author

t0yv0 commented Oct 7, 2023

I think in the ideal state it really should not need tfgen. There is the issue with go:embed pointing to non-existing files; this is really a papercut, this can be worked around. Beyond that, why should testing the provider depend on tfgen?

@t0yv0 t0yv0 merged commit 8765da6 into master Oct 7, 2023
@t0yv0 t0yv0 deleted the t0yv0/unit-test-provider branch October 7, 2023 00:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Run GO tests for bridged providers
2 participants