Skip to content

Commit

Permalink
Initial effort on making tests immutable
Browse files Browse the repository at this point in the history
  • Loading branch information
erikzaadi committed Nov 4, 2024
1 parent 029b87a commit adcd2f2
Show file tree
Hide file tree
Showing 5 changed files with 355 additions and 181 deletions.
13 changes: 11 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,17 @@ jobs:
run: go clean -testcache

- name: Test
run: go test -v ./...
run: go run gotest.tools/gotestsum@latest -f github-actions --junitfile ./test-results/junit.xml .
env:
PORT_CLIENT_ID: ${{ secrets.PORT_CLIENT_ID }}
PORT_CLIENT_SECRET: ${{ secrets.PORT_CLIENT_SECRET }}
PORT_BASE_URL: https://api.stg-01.getport.io
PORT_BASE_URL: https://api.stg-01.getport.io

- name: Publish Test Report
uses: mikepenz/action-junit-report@v4
if: ${{ always() }}
with:
report_paths: './test-results/junit.xml'
include_passed: true
require_tests: true
fail_on_failure: true
20 changes: 20 additions & 0 deletions pkg/defaults/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ type Fixture struct {
stateKey string
}

func tearDownFixture(
t *testing.T,
f *Fixture,
) {
t.Logf("Deleting default resources for %s", f.stateKey)
deleteDefaultResources(f.portClient, f.stateKey)
}

func NewFixture(t *testing.T) *Fixture {
stateKey := guuid.NewString()
portClient := cli.New(config.ApplicationConfig)
Expand Down Expand Up @@ -57,6 +65,8 @@ func deleteDefaultResources(portClient *cli.PortClient, stateKey string) {

func Test_InitIntegration_InitDefaults(t *testing.T) {
f := NewFixture(t)
defer tearDownFixture(t, f)
defer tearDownFixture(t, f)
e := InitIntegration(f.portClient, &port.Config{
StateKey: f.stateKey,
EventListenerType: "POLLING",
Expand Down Expand Up @@ -85,6 +95,7 @@ func Test_InitIntegration_InitDefaults(t *testing.T) {

func Test_InitIntegration_InitDefaults_CreateDefaultResources_False(t *testing.T) {
f := NewFixture(t)
defer tearDownFixture(t, f)
e := InitIntegration(f.portClient, &port.Config{
StateKey: f.stateKey,
EventListenerType: "POLLING",
Expand All @@ -100,6 +111,7 @@ func Test_InitIntegration_InitDefaults_CreateDefaultResources_False(t *testing.T

func Test_InitIntegration_BlueprintExists(t *testing.T) {
f := NewFixture(t)
defer tearDownFixture(t, f)
if _, err := blueprint.NewBlueprint(f.portClient, port.Blueprint{
Identifier: "workload",
Title: "Workload",
Expand Down Expand Up @@ -128,6 +140,7 @@ func Test_InitIntegration_BlueprintExists(t *testing.T) {

func Test_InitIntegration_PageExists(t *testing.T) {
f := NewFixture(t)
defer tearDownFixture(t, f)
if err := page.CreatePage(f.portClient, port.Page{
Identifier: "workload_overview_dashboard",
Title: "Workload Overview Dashboard",
Expand All @@ -153,6 +166,7 @@ func Test_InitIntegration_PageExists(t *testing.T) {

func Test_InitIntegration_ExistingIntegration(t *testing.T) {
f := NewFixture(t)
defer tearDownFixture(t, f)
err := integration.CreateIntegration(f.portClient, f.stateKey, "", nil)
if err != nil {
t.Errorf("Error creating Port integration: %s", err.Error())
Expand All @@ -172,6 +186,7 @@ func Test_InitIntegration_ExistingIntegration(t *testing.T) {

func Test_InitIntegration_LocalResourcesConfiguration(t *testing.T) {
f := NewFixture(t)
defer tearDownFixture(t, f)
err := integration.CreateIntegration(f.portClient, f.stateKey, "", nil)
if err != nil {
t.Errorf("Error creating Port integration: %s", err.Error())
Expand Down Expand Up @@ -213,6 +228,7 @@ func Test_InitIntegration_LocalResourcesConfiguration(t *testing.T) {

func Test_InitIntegration_LocalResourcesConfiguration_ExistingIntegration_EmptyConfiguration(t *testing.T) {
f := NewFixture(t)
defer tearDownFixture(t, f)
err := integration.CreateIntegration(f.portClient, f.stateKey, "POLLING", nil)
if err != nil {
t.Errorf("Error creating Port integration: %s", err.Error())
Expand All @@ -234,6 +250,8 @@ func Test_InitIntegration_LocalResourcesConfiguration_ExistingIntegration_EmptyC

func Test_InitIntegration_LocalResourcesConfiguration_ExistingIntegration_WithConfiguration_WithOverwriteConfigurationOnRestartFlag(t *testing.T) {
f := NewFixture(t)
defer tearDownFixture(t, f)

expectedConfig := &port.IntegrationAppConfig{
Resources: []port.Resource{
{
Expand Down Expand Up @@ -276,4 +294,6 @@ func Test_InitIntegration_LocalResourcesConfiguration_ExistingIntegration_WithCo
assert.Equal(t, expectedConfig.Resources, i.Config.Resources)

testUtils.CheckResourcesExistence(false, f.portClient, f.t, []string{"workload", "namespace", "cluster"}, []string{"workload_overview_dashboard", "availability_scorecard_dashboard"}, []string{})
defer tearDownFixture(t, f)

}
Loading

0 comments on commit adcd2f2

Please sign in to comment.