---
title: "Unit Testing Pulumi Programs with Components in Go"
description: "An example that applies unit testing to Go and component resources."
url: "https://www.pulumi.com/dev/examples/testing-unit-go-components/"
image: "https://www.pulumi.com/assets/og/dev/examples/testing-unit-go-components.png"
---

# Unit Testing Pulumi Programs with Components in Go

An example that applies unit testing to Go and component resources.

- Source on GitHub: https://github.com/pulumi/examples/tree/master/testing-unit-go-components

## Get started with this example

This example lives in the [pulumi/examples](https://github.com/pulumi/examples/tree/master/testing-unit-go-components) repo. Pull down just this directory to follow along:

```bash
git clone --filter=blob:none --sparse https://github.com/pulumi/examples pulumi-examples
git -C pulumi-examples sparse-checkout set testing-unit-go-components
cd pulumi-examples/testing-unit-go-components
```

An example of writing mock-based unit tests written in Go, involving Pulumi Components such as Helm Chart v4.

The program code to be tested (main.go:NewNginxComponent) consists of a code block that creates a Helm Chart resource,
locates the Service resource that is created by the chart, and then extracts the assigned ingress IP for later use.
The test program uses mocking to simulate the behavior of the Helm Chart resource.

## Prerequisites

[Install Go](https://golang.org/doc/install).

## Running the tests

2.  Run the tests:

    ```
    $ go test

    PASS
    ok  	testing-unit-go-components	0.400s
    ```

## Further steps

Learn more about testing Pulumi programs:

- [Testing Guide](https://www.pulumi.com/docs/guides/testing/)
- [Unit Testing Guide](https://www.pulumi.com/docs/guides/testing/unit/)
