Skip to content

Commit

Permalink
chore(PL-2578): make e2e test internal
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmdm committed Apr 9, 2024
1 parent 0a089d3 commit 8923b39
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 24 deletions.
22 changes: 17 additions & 5 deletions .github/workflows/build-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
work-dir: chart
args: --namespace my-namespace --release my-release --app-version 1.0.0 --chart-version 1.0.0

test-app:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -36,11 +36,21 @@ jobs:
- name: Setup dependencies
run: go mod download
- name: Run tests
run: go test -race ./...

internal-tests:
runs-on: ubuntu-latest
steps:
- name: Dispatch workflow
env:
GH_USER: nestobot
GH_TOKEN: ${{ secrets.TESTING_TOKEN }}
CATALOG_URL: https://github.com/nestoca/catalog
run: go test ./...
GH_TOKEN: ${{ github.token }}
run: |
gh workflow run --repo nestoca/catalog -f ref=${{ github.ref }} joy-generator-test
workflowId=$(gh run ls --repo nestoca/catalog --workflow joy-generator-test --json databaseId -q '.[0].databaseId')
gh run watch --exit-status --repo nestoca/catalog $workflowId
build:
runs-on: ubuntu-latest
steps:
Expand All @@ -54,11 +64,13 @@ jobs:
push: false
cache-from: type=gha
cache-to: type=gha,mode=max

publish:
if: github.ref == 'refs/heads/master'
needs:
- test-app
- test-chart
- internal-tests
- build
runs-on: ubuntu-latest
permissions:
Expand Down
43 changes: 24 additions & 19 deletions cmd/server/api_get_params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ package main

import (
"bytes"
"cmp"
"encoding/json"
"fmt"
"io"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"strconv"
"strings"
"testing"

"github.com/davidmdm/conf"
"github.com/rs/zerolog"
"github.com/stretchr/testify/require"

Expand All @@ -21,26 +22,31 @@ import (
)

func TestGetParamsE2E(t *testing.T) {
logs := &TestLogOutputs{}
if ok, _ := strconv.ParseBool(os.Getenv("INTERNAL_TESTING")); !ok {
t.Skip("skip internal test")
}

logger := zerolog.New(logs)
var (
user github.User
catalog github.RepoMetadata
)

user := github.User{
Name: os.Getenv("GH_USER"),
Token: os.Getenv("GH_TOKEN"),
}
conf.Var(conf.Environ, &catalog.Path, "CATALOG_PATH", conf.Default(filepath.Join(os.TempDir(), "catalog")))
conf.Var(conf.Environ, &catalog.URL, "CATALOG_URL", conf.Required[string](true))
conf.Var(conf.Environ, &catalog.TargetRevision, "CATALOG_REVISION", conf.Default("master"))
conf.Var(conf.Environ, &user.Name, "GH_USER", conf.Required[string](true))
conf.Var(conf.Environ, &user.Token, "GH_TOKEN", conf.Required[string](true))

catalog := github.RepoMetadata{
Path: cmp.Or(os.Getenv("CATALOG_PATH"), filepath.Join(os.TempDir(), "catalog-test")),
URL: os.Getenv("CATALOG_URL"),
TargetRevision: os.Getenv("CATALOG_REVISION"),
}
require.NoError(t, conf.Environ.Parse())

require.NoError(t, os.RemoveAll(catalog.Path))

repo, err := user.NewRepo(catalog)
require.NoError(t, err, "failed to create repo for user: %s", user.Name)

logs := &TestLogOutputs{}
logger := zerolog.New(logs)

repo = repo.WithLogger(logger)

handler := Handler(HandlerParams{
Expand Down Expand Up @@ -76,13 +82,12 @@ func TestGetParamsE2E(t *testing.T) {

require.Greater(t, len(response.Output.Parameters), 0)

// TODO UNCOMMENT ONCE WE GET PASSED THIS CATALOG BUMP
// for _, result := range response.Output.Parameters {
// chart := jsonUnmarshalTo[map[string]string](t, result.Release.Spec.Chart)
// require.NotEmpty(t, chart["version"])
// require.NotEmpty(t, chart["repoUrl"])
// require.NotEmpty(t, chart["name"])
// }
for _, result := range response.Output.Parameters {
chart := jsonUnmarshalTo[map[string]string](t, result.Release.Spec.Chart)
require.NotEmpty(t, chart["version"])
require.NotEmpty(t, chart["repoUrl"])
require.NotEmpty(t, chart["name"])
}

require.Greater(t, len(logs.Records), 0)
for _, record := range logs.Records {
Expand Down

0 comments on commit 8923b39

Please sign in to comment.