From 97ed490b290c3671c6a46fa6a764a0a549a694ea Mon Sep 17 00:00:00 2001 From: agustin Date: Wed, 15 May 2024 17:02:13 +0200 Subject: [PATCH 1/3] test(api) exclude test report if the actor is dependabot --- .github/workflows/api-unit-test.yml | 2 +- .github/workflows/cli-unit-test.yml | 2 +- API/controllers/entity_test.go | 31 ++++++++++++++--------------- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/.github/workflows/api-unit-test.yml b/.github/workflows/api-unit-test.yml index 33eee1d8a..f9ec06c2c 100644 --- a/.github/workflows/api-unit-test.yml +++ b/.github/workflows/api-unit-test.yml @@ -52,7 +52,7 @@ jobs: - name: Test Report uses: dorny/test-reporter@v1 - if: always() # run this step even if previous steps failed + if: github.actor != 'dependabot[bot]' with: name: API Tests Report # Name of the check run which will be created path: ./API/tests-api.xml # Path to test results diff --git a/.github/workflows/cli-unit-test.yml b/.github/workflows/cli-unit-test.yml index 9bd7ef999..8f4ff27db 100644 --- a/.github/workflows/cli-unit-test.yml +++ b/.github/workflows/cli-unit-test.yml @@ -49,7 +49,7 @@ jobs: - name: Test Report uses: dorny/test-reporter@v1 - if: always() # run this step even if previous steps failed + if: github.actor != 'dependabot[bot]' with: name: CLI Tests Report # Name of the check run which will be created path: ./CLI/tests-cli.xml # Path to test results diff --git a/API/controllers/entity_test.go b/API/controllers/entity_test.go index 787c93468..7afb70614 100644 --- a/API/controllers/entity_test.go +++ b/API/controllers/entity_test.go @@ -10,7 +10,6 @@ import ( test_utils "p3/test/utils" "p3/utils" "slices" - "strings" "testing" "time" @@ -614,21 +613,21 @@ func TestGetLayersObjectsWithSimpleFilter(t *testing.T) { assert.True(t, condition) } -func TestGetLayersObjectsWithDoubleFilter(t *testing.T) { - endpoint := test_utils.GetEndpoint("layersObjects", "racks-1-layer") - expectedMessage := "successfully processed request" - response := e2e.ValidateManagedRequest(t, "GET", endpoint+"?root=site-no-temperature.building-1.room-*", nil, http.StatusOK, expectedMessage) +// func TestGetLayersObjectsWithDoubleFilter(t *testing.T) { +// endpoint := test_utils.GetEndpoint("layersObjects", "racks-1-layer") +// expectedMessage := "successfully processed request" +// response := e2e.ValidateManagedRequest(t, "GET", endpoint+"?root=site-no-temperature.building-1.room-*", nil, http.StatusOK, expectedMessage) - data, exists := response["data"].([]any) - assert.True(t, exists) - assert.Equal(t, 2, len(data)) +// data, exists := response["data"].([]any) +// assert.True(t, exists) +// assert.Equal(t, 2, len(data)) - condition := true - for _, rack := range data { - condition = condition && strings.HasPrefix(rack.(map[string]any)["parentId"].(string), "site-no-temperature.building-1.room-") - condition = condition && rack.(map[string]any)["category"] == "rack" - condition = condition && rack.(map[string]any)["name"] == "rack-1" - } +// condition := true +// for _, rack := range data { +// condition = condition && strings.HasPrefix(rack.(map[string]any)["parentId"].(string), "site-no-temperature.building-1.room-") +// condition = condition && rack.(map[string]any)["category"] == "rack" +// condition = condition && rack.(map[string]any)["name"] == "rack-1" +// } - assert.True(t, condition) -} +// assert.True(t, condition) +// } From dbe48a028f6573ba8d672c2d12a85c32116bbce5 Mon Sep 17 00:00:00 2001 From: agustin Date: Wed, 15 May 2024 17:19:01 +0200 Subject: [PATCH 2/3] test(api) change cli coverage badge upload branch --- .github/workflows/api-unit-test.yml | 4 +- .github/workflows/cli-unit-test.yml | 6 +-- CLI/controllers/commandController_test.go | 46 +++++++++++------------ 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/.github/workflows/api-unit-test.yml b/.github/workflows/api-unit-test.yml index f9ec06c2c..3e0a377bd 100644 --- a/.github/workflows/api-unit-test.yml +++ b/.github/workflows/api-unit-test.yml @@ -76,7 +76,7 @@ jobs: defaults: run: working-directory: ./ - if: github.ref == 'refs/heads/main' && github.event.head_commit.author.name != 'GitHubActions' + # if: github.ref == 'refs/heads/main' && github.event.head_commit.author.name != 'GitHubActions' steps: - uses: actions/checkout@v4 @@ -102,7 +102,7 @@ jobs: defaults: run: working-directory: ./ - if: github.ref == 'refs/heads/main' && github.event.head_commit.author.name != 'GitHubActions' + # if: github.ref == 'refs/heads/main' && github.event.head_commit.author.name != 'GitHubActions' steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/cli-unit-test.yml b/.github/workflows/cli-unit-test.yml index 8f4ff27db..d58706bcf 100644 --- a/.github/workflows/cli-unit-test.yml +++ b/.github/workflows/cli-unit-test.yml @@ -73,7 +73,7 @@ jobs: defaults: run: working-directory: ./ - if: github.ref == 'refs/heads/main' && github.event.head_commit.author.name != 'GitHubActions' + # if: github.ref == 'refs/heads/main' && github.event.head_commit.author.name != 'GitHubActions' steps: - uses: actions/checkout@v4 @@ -99,7 +99,7 @@ jobs: defaults: run: working-directory: ./ - if: github.ref == 'refs/heads/main' && github.event.head_commit.author.name != 'GitHubActions' + # if: github.ref == 'refs/heads/main' && github.event.head_commit.author.name != 'GitHubActions' steps: - uses: actions/checkout@v4 @@ -111,5 +111,5 @@ jobs: with: BADGE_ARTIFACT_NAME: cli_coverage_badge BADGE_FILE_NAME: cli_coverage_badge.svg - BRANCH_NAME: coverage_badges + BRANCH_NAME: cli_coverage_badge github_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/CLI/controllers/commandController_test.go b/CLI/controllers/commandController_test.go index 1fabc6452..5ca6af61d 100644 --- a/CLI/controllers/commandController_test.go +++ b/CLI/controllers/commandController_test.go @@ -777,29 +777,29 @@ func TestIsEntityDrawableObjectNotFound(t *testing.T) { assert.Equal(t, "object not found", err.Error()) } -func TestIsEntityDrawable(t *testing.T) { - tests := []struct { - name string - drawableObjects []int - expectedIsDrawable bool - }{ - {"CategoryIsNotDrawable", []int{models.EntityStrToInt("device")}, false}, - {"CategoryIsDrawable", []int{models.EntityStrToInt("rack")}, true}, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - controller, mockAPI, _ := layersSetup(t) - controllers.State.DrawableObjs = tt.drawableObjects - - test_utils.MockGetObject(mockAPI, rack1) - - isDrawable, err := controller.IsEntityDrawable(models.PhysicalPath + "BASIC/A/R1/A01") - assert.Equal(t, tt.expectedIsDrawable, isDrawable) - assert.Nil(t, err) - }) - } -} +// func TestIsEntityDrawable(t *testing.T) { +// tests := []struct { +// name string +// drawableObjects []int +// expectedIsDrawable bool +// }{ +// {"CategoryIsNotDrawable", []int{models.EntityStrToInt("device")}, false}, +// {"CategoryIsDrawable", []int{models.EntityStrToInt("rack")}, true}, +// } + +// for _, tt := range tests { +// t.Run(tt.name, func(t *testing.T) { +// controller, mockAPI, _ := layersSetup(t) +// controllers.State.DrawableObjs = tt.drawableObjects + +// test_utils.MockGetObject(mockAPI, rack1) + +// isDrawable, err := controller.IsEntityDrawable(models.PhysicalPath + "BASIC/A/R1/A01") +// assert.Equal(t, tt.expectedIsDrawable, isDrawable) +// assert.Nil(t, err) +// }) +// } +// } // Tests IsAttrDrawable (and IsCategoryAttrDrawable) func TestIsAttrDrawableObjectNotFound(t *testing.T) { From d3f8d05270a7be8f74ac9767f3fd2d0c3b945df7 Mon Sep 17 00:00:00 2001 From: agustin Date: Wed, 15 May 2024 17:23:37 +0200 Subject: [PATCH 3/3] test(api) Update README --- .github/workflows/api-unit-test.yml | 4 +- .github/workflows/cli-unit-test.yml | 4 +- API/controllers/entity_test.go | 31 +++++++-------- CLI/controllers/commandController_test.go | 46 +++++++++++------------ README.md | 2 +- 5 files changed, 44 insertions(+), 43 deletions(-) diff --git a/.github/workflows/api-unit-test.yml b/.github/workflows/api-unit-test.yml index 3e0a377bd..f9ec06c2c 100644 --- a/.github/workflows/api-unit-test.yml +++ b/.github/workflows/api-unit-test.yml @@ -76,7 +76,7 @@ jobs: defaults: run: working-directory: ./ - # if: github.ref == 'refs/heads/main' && github.event.head_commit.author.name != 'GitHubActions' + if: github.ref == 'refs/heads/main' && github.event.head_commit.author.name != 'GitHubActions' steps: - uses: actions/checkout@v4 @@ -102,7 +102,7 @@ jobs: defaults: run: working-directory: ./ - # if: github.ref == 'refs/heads/main' && github.event.head_commit.author.name != 'GitHubActions' + if: github.ref == 'refs/heads/main' && github.event.head_commit.author.name != 'GitHubActions' steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/cli-unit-test.yml b/.github/workflows/cli-unit-test.yml index d58706bcf..e3cafeca8 100644 --- a/.github/workflows/cli-unit-test.yml +++ b/.github/workflows/cli-unit-test.yml @@ -73,7 +73,7 @@ jobs: defaults: run: working-directory: ./ - # if: github.ref == 'refs/heads/main' && github.event.head_commit.author.name != 'GitHubActions' + if: github.ref == 'refs/heads/main' && github.event.head_commit.author.name != 'GitHubActions' steps: - uses: actions/checkout@v4 @@ -99,7 +99,7 @@ jobs: defaults: run: working-directory: ./ - # if: github.ref == 'refs/heads/main' && github.event.head_commit.author.name != 'GitHubActions' + if: github.ref == 'refs/heads/main' && github.event.head_commit.author.name != 'GitHubActions' steps: - uses: actions/checkout@v4 diff --git a/API/controllers/entity_test.go b/API/controllers/entity_test.go index 7afb70614..787c93468 100644 --- a/API/controllers/entity_test.go +++ b/API/controllers/entity_test.go @@ -10,6 +10,7 @@ import ( test_utils "p3/test/utils" "p3/utils" "slices" + "strings" "testing" "time" @@ -613,21 +614,21 @@ func TestGetLayersObjectsWithSimpleFilter(t *testing.T) { assert.True(t, condition) } -// func TestGetLayersObjectsWithDoubleFilter(t *testing.T) { -// endpoint := test_utils.GetEndpoint("layersObjects", "racks-1-layer") -// expectedMessage := "successfully processed request" -// response := e2e.ValidateManagedRequest(t, "GET", endpoint+"?root=site-no-temperature.building-1.room-*", nil, http.StatusOK, expectedMessage) +func TestGetLayersObjectsWithDoubleFilter(t *testing.T) { + endpoint := test_utils.GetEndpoint("layersObjects", "racks-1-layer") + expectedMessage := "successfully processed request" + response := e2e.ValidateManagedRequest(t, "GET", endpoint+"?root=site-no-temperature.building-1.room-*", nil, http.StatusOK, expectedMessage) -// data, exists := response["data"].([]any) -// assert.True(t, exists) -// assert.Equal(t, 2, len(data)) + data, exists := response["data"].([]any) + assert.True(t, exists) + assert.Equal(t, 2, len(data)) -// condition := true -// for _, rack := range data { -// condition = condition && strings.HasPrefix(rack.(map[string]any)["parentId"].(string), "site-no-temperature.building-1.room-") -// condition = condition && rack.(map[string]any)["category"] == "rack" -// condition = condition && rack.(map[string]any)["name"] == "rack-1" -// } + condition := true + for _, rack := range data { + condition = condition && strings.HasPrefix(rack.(map[string]any)["parentId"].(string), "site-no-temperature.building-1.room-") + condition = condition && rack.(map[string]any)["category"] == "rack" + condition = condition && rack.(map[string]any)["name"] == "rack-1" + } -// assert.True(t, condition) -// } + assert.True(t, condition) +} diff --git a/CLI/controllers/commandController_test.go b/CLI/controllers/commandController_test.go index 5ca6af61d..1fabc6452 100644 --- a/CLI/controllers/commandController_test.go +++ b/CLI/controllers/commandController_test.go @@ -777,29 +777,29 @@ func TestIsEntityDrawableObjectNotFound(t *testing.T) { assert.Equal(t, "object not found", err.Error()) } -// func TestIsEntityDrawable(t *testing.T) { -// tests := []struct { -// name string -// drawableObjects []int -// expectedIsDrawable bool -// }{ -// {"CategoryIsNotDrawable", []int{models.EntityStrToInt("device")}, false}, -// {"CategoryIsDrawable", []int{models.EntityStrToInt("rack")}, true}, -// } - -// for _, tt := range tests { -// t.Run(tt.name, func(t *testing.T) { -// controller, mockAPI, _ := layersSetup(t) -// controllers.State.DrawableObjs = tt.drawableObjects - -// test_utils.MockGetObject(mockAPI, rack1) - -// isDrawable, err := controller.IsEntityDrawable(models.PhysicalPath + "BASIC/A/R1/A01") -// assert.Equal(t, tt.expectedIsDrawable, isDrawable) -// assert.Nil(t, err) -// }) -// } -// } +func TestIsEntityDrawable(t *testing.T) { + tests := []struct { + name string + drawableObjects []int + expectedIsDrawable bool + }{ + {"CategoryIsNotDrawable", []int{models.EntityStrToInt("device")}, false}, + {"CategoryIsDrawable", []int{models.EntityStrToInt("rack")}, true}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + controller, mockAPI, _ := layersSetup(t) + controllers.State.DrawableObjs = tt.drawableObjects + + test_utils.MockGetObject(mockAPI, rack1) + + isDrawable, err := controller.IsEntityDrawable(models.PhysicalPath + "BASIC/A/R1/A01") + assert.Equal(t, tt.expectedIsDrawable, isDrawable) + assert.Nil(t, err) + }) + } +} // Tests IsAttrDrawable (and IsCategoryAttrDrawable) func TestIsAttrDrawableObjectNotFound(t *testing.T) { diff --git a/README.md b/README.md index de0505fcc..49ce8617a 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=ditrit_OGrEE-Core&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=ditrit_OGrEE-Core) [![API Coverage](https://raw.githubusercontent.com/ditrit/OGrEE-Core/coverage_badges/api_coverage_badge.svg)](https://github.com/ditrit/OGrEE-Core/actions/workflows/api-unit-test.yml) -[![CLI Coverage](https://raw.githubusercontent.com/ditrit/OGrEE-Core/coverage_badges/cli_coverage_badge.svg)](https://github.com/ditrit/OGrEE-Core/actions/workflows/cli-unit-test.yml) +[![CLI Coverage](https://raw.githubusercontent.com/ditrit/OGrEE-Core/cli_coverage_badge/cli_coverage_badge.svg)](https://github.com/ditrit/OGrEE-Core/actions/workflows/cli-unit-test.yml) [![⚙️ Build - Publish](https://github.com/ditrit/OGrEE-Core/actions/workflows/build-deploy.yaml/badge.svg)](https://github.com/ditrit/OGrEE-Core/actions/workflows/build-deploy.yaml)