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

Rework integration and e2e tests #136

Merged
merged 1 commit into from
Feb 25, 2021
Merged
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
4 changes: 0 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,6 @@ commands:
chmod +x ${GOPATH}/bin/mc
mc config host add helm-s3-minio http://${AWS_ENDPOINT} ${AWS_ACCESS_KEY_ID} ${AWS_SECRET_ACCESS_KEY}
mc mb helm-s3-minio/test-bucket
- run:
name: Run (legacy) integration tests
command: |
./hack/integration-tests.sh
- run:
name: Run e2e tests
command: |
Expand Down
14 changes: 14 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,17 @@ the plugin from source:

If you see no messages - build was successful. Try to run some helm commands
that involve the plugin, or jump straight into plugin development.

## Testing

Run unit tests:

```shell
make test-unit
```

Run e2e tests locally:

```shell
make test-e2e-local
```
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ install:
test-unit:
go test $$(go list ./... | grep -v e2e)

.PHONY: test-integration
test-integration:
@./hack/integration-tests-local.sh

.PHONY: test-e2e
test-e2e:
go test -v ./tests/e2e/...

.PHONY: test-e2e-local
test-e2e-local:
@./hack/test-e2e-local.sh
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ and others. To configure the plugin to work alternative S3 backend, just define
$ export AWS_ENDPOINT=localhost:9000
$ export AWS_DISABLE_SSL=true

See [these integration tests](https://github.com/hypnoglow/helm-s3/blob/master/hack/integration-tests-local.sh#L10) that use local minio docker container for a complete example.
See [these integration tests](https://github.com/hypnoglow/helm-s3/blob/master/hack/test-e2e-local.sh) that use local minio docker container for a complete example.

## Using S3 bucket ServerSide Encryption

Expand Down
158 changes: 0 additions & 158 deletions hack/integration-tests.sh

This file was deleted.

2 changes: 1 addition & 1 deletion hack/integration-tests-local.sh → hack/test-e2e-local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ go build -o bin/helms3 ./cmd/helms3

## Test

$(dirname ${BASH_SOURCE[0]})/integration-tests.sh
go test -v ./tests/e2e/...
if [ $? -eq 0 ] ; then
echo -e "\nAll tests passed!"
fi
71 changes: 71 additions & 0 deletions tests/e2e/delete_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package e2e

import (
"fmt"
"testing"

"github.com/minio/minio-go/v6"
"github.com/stretchr/testify/assert"
)

func TestDelete(t *testing.T) {
t.Log("Test basic delete action")

const (
repoName = "test-delete"
repoDir = "charts"
chartName = "foo"
chartVersion = "1.2.3"
chartFilename = "foo-1.2.3.tgz"
chartFilepath = "testdata/" + chartFilename
chartObjectName = repoDir + "/" + chartFilename
)

setupRepo(t, repoName, repoDir)
defer teardownRepo(t, repoName)

// Push chart to be deleted.

cmd, stdout, stderr := command(fmt.Sprintf("helm s3 push %s %s", chartFilepath, repoName))
err := cmd.Run()
assert.NoError(t, err)
assertEmptyOutput(t, stdout, stderr)

// Check that pushed chart exists in the bucket.

obj, err := mc.StatObject(repoName, chartObjectName, minio.StatObjectOptions{})
assert.NoError(t, err)
assert.Equal(t, chartObjectName, obj.Key)

// Check that pushed chart can be searched, which means it exists in the index.

cmd, stdout, stderr = command(makeSearchCommand(repoName, chartName))
err = cmd.Run()
assert.NoError(t, err)
assertEmptyOutput(t, nil, stderr)

expected := `test-delete/foo 1.2.3 1.2.3 A Helm chart for Kubernetes`
assert.Contains(t, stdout.String(), expected)

// Delete chart.

cmd, stdout, stderr = command(fmt.Sprintf("helm s3 delete %s --version %s %s", chartName, chartVersion, repoName))
err = cmd.Run()
assert.NoError(t, err)
assertEmptyOutput(t, stdout, stderr)

// Check that chart was actually deleted from the bucket.

_, err = mc.StatObject(repoName, chartObjectName, minio.StatObjectOptions{})
assert.Equal(t, "NoSuchKey", minio.ToErrorResponse(err).Code)

// Check that deleted chart cannot be searched, which means it was deleted from the index.

cmd, stdout, stderr = command(makeSearchCommand(repoName, chartName))
err = cmd.Run()
assert.NoError(t, err)
assertEmptyOutput(t, nil, stderr)

expected = `No results found`
assert.Contains(t, stdout.String(), expected)
}
53 changes: 53 additions & 0 deletions tests/e2e/init_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package e2e

import (
"fmt"
"testing"

"github.com/minio/minio-go/v6"
"github.com/stretchr/testify/assert"
)

func TestInit(t *testing.T) {
t.Log("Test basic init action")

const (
repoName = "test-init"
repoDir = "charts"
indexObjectName = repoDir + "/index.yaml"
uri = "s3://test-init/charts"
)

setupBucket(t, repoName)
defer teardownBucket(t, repoName)

// Run init.

cmd, stdout, stderr := command(fmt.Sprintf("helm s3 init %s", uri))
err := cmd.Run()
assert.NoError(t, err)
assertEmptyOutput(t, nil, stderr)
assert.Contains(t, stdout.String(), "Initialized empty repository at s3://test-init/charts")

// Check that initialized repository has index file.

obj, err := mc.StatObject(repoName, indexObjectName, minio.StatObjectOptions{})
assert.NoError(t, err)
assert.Equal(t, indexObjectName, obj.Key)

// Check that `helm repo add` works.

cmd, stdout, stderr = command(fmt.Sprintf("helm repo add %s %s", repoName, uri))
err = cmd.Run()
assert.NoError(t, err)
assertEmptyOutput(t, nil, stderr)
assert.Contains(t, stdout.String(), `"test-init" has been added to your repositories`)

// Check that `helm repo remove` works.

cmd, stdout, stderr = command(fmt.Sprintf("helm repo remove %s", repoName))
err = cmd.Run()
assert.NoError(t, err)
assertEmptyOutput(t, nil, stderr)
assert.Contains(t, stdout.String(), `"test-init" has been removed from your repositories`)
}
Loading