From 2f3034ba5d096b7627fd00e5026e4c64153cbc41 Mon Sep 17 00:00:00 2001 From: agustin Date: Wed, 15 May 2024 10:27:26 +0200 Subject: [PATCH 01/21] test(api) change api workflow --- .github/workflows/api-unit-test.yml | 43 +++++++-- API/controllers/entity_test.go | 31 ++++--- assets/badge_generator/generate_badge.py | 108 +++++++++++++++++++++++ assets/badge_generator/requirements.txt | 13 +++ 4 files changed, 173 insertions(+), 22 deletions(-) create mode 100644 assets/badge_generator/generate_badge.py create mode 100644 assets/badge_generator/requirements.txt diff --git a/.github/workflows/api-unit-test.yml b/.github/workflows/api-unit-test.yml index 38574983c..c37f8be90 100644 --- a/.github/workflows/api-unit-test.yml +++ b/.github/workflows/api-unit-test.yml @@ -68,7 +68,7 @@ jobs: name: coverage_api_xml path: ./API/coverage_api.xml - coverage-badge: + generate-coverage-badge: needs: api-unit-test runs-on: ubuntu-latest permissions: @@ -76,20 +76,22 @@ 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 with: fetch-depth: 0 - ref: coverage_badges - uses: actions/setup-python@v5 with: python-version: '3.8' - - name: Install genbadge - run: pip install genbadge[coverage] + - name: Install requests + run: pip install requests + + - name: Install pycobertura + run: pip install pycobertura - name: Download line coverage reports uses: actions/download-artifact@v4 @@ -97,7 +99,36 @@ jobs: name: coverage_api_xml - name: Generate badge - run: genbadge coverage -i coverage_api.xml -n "API coverage" -o api_coverage_badge.svg + run: python assets/badge_generator/generate_badge.py --label "API coverage" --output api_coverage_badge.svg --input-report coverage_api.xml --red-limit 50 --green-limit 65 + + - uses: actions/upload-artifact@v4 + with: + name: api_coverage_badge + path: api_coverage_badge.svg + + upload-coverage-badge: + needs: generate-coverage-badge + runs-on: ubuntu-latest + permissions: + contents: write + defaults: + run: + working-directory: ./ + # if: github.ref == 'refs/heads/main' && github.event.head_commit.author.name != 'GitHubActions' + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + ref: coverage_badges + + - name: Download coverage badge + uses: actions/download-artifact@v4 + with: + name: api_coverage_badge + + - name: Local ls + run: ls - name: Verify Changed files uses: tj-actions/verify-changed-files@v16 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) +// } diff --git a/assets/badge_generator/generate_badge.py b/assets/badge_generator/generate_badge.py new file mode 100644 index 000000000..1d0c79281 --- /dev/null +++ b/assets/badge_generator/generate_badge.py @@ -0,0 +1,108 @@ +import sys +import argparse +import requests +import pycobertura + +DEFAULT_RED_LIMIT=50 +DEFAULT_GREEN_LIMIT=65 +DEFAULT_LABEL = "Coverage" + +def check_valid_percentage_range(percentage): + return 0 <= percentage <= 100 + +def get_limit_values(red_limit, green_limit): + """It returns the red and green limits that defines the percentage values in which the coverage change color from + red to orange and from orange to green""" + red_limit = red_limit or DEFAULT_RED_LIMIT + green_limit = green_limit or DEFAULT_GREEN_LIMIT + + if not check_valid_percentage_range(red_limit) or not check_valid_percentage_range(green_limit): + raise ValueError("Invalid value for Red Limit or Green Limit. They should be between 0 and 100") + if red_limit >= green_limit: + raise ValueError(f"Invalid limit value. Green limit ({green_limit}) should be greater than Red Limit ({red_limit}) ") + return [red_limit, green_limit] + +def parse_coverage_from_report(report_path): + """It tries to open the coverage xml report and parses it to get the line rate. It returns the line coverage percentage""" + try: + coverage_report = pycobertura.Cobertura(report_path) + return round(coverage_report.line_rate() * 100, 2) + except: + raise ValueError("Invalid file path or invalid file format") + +def parse_coverage(coverage): + """Given a coverage percentage string, it parses it and checks if it is a valid percentage value. + It returns the percentage as a float""" + percentage = coverage + if not coverage: + raise ValueError("Percentage should not be empty") + if coverage[-1] == "%": + percentage = coverage[:-1] + # we try to convert it to float + try: + percentage = float(percentage) + if not check_valid_percentage_range(percentage): + raise ValueError("Invalid percentage value") + return percentage + except ValueError: + raise ValueError(f"Invalid percentage data provided: {coverage}. The value is not a valid percentage number") + +def get_color(percentage, limits): + """Returns the corresponding color depending on the percentage value and the corresponding limits""" + red_limit, green_limit = limits + if percentage >= green_limit: + return "green" + elif red_limit <= percentage < green_limit: + return "orange" + return "red" + +def get_label(label): + """Returns the label by replacing the spaces with _""" + if not label: + return DEFAULT_LABEL + return label.replace(" ","_") + +def get_destination_path(path): + if not path: + # We will save the image in the local directory + return "coverage.svg" + return path + +def download_image(label, percentage, color, path): + """It downloads the coverage badge generated by img.shields.io""" + url = f"https://img.shields.io/badge/{label}-{percentage}%25-{color}" + response = requests.get(url) + if response.status_code >= 400: + raise RuntimeError("An error ocurred while getting the badge") + with open(path, mode="wb") as file: + file.write(response.content) + +def parse_opt(): + parser = argparse.ArgumentParser(prog='Generate Badge', description='This script generates a coverage badge') + parser.add_argument('--coverage', type=str, help='Coverage percentage. If defined, input-report will be ignored. Example: 75%%') + parser.add_argument('--input-report', type=str, default="coverage.xml", help="Path to the xml coverage report") + parser.add_argument('--label', type=str, default=DEFAULT_LABEL, help='Left side label') + parser.add_argument('--output', type=str, help="Path to save the badge created") + parser.add_argument('--red-limit', type=float, default=DEFAULT_RED_LIMIT, help="Limit value to red status. It indicates the limit value in which the status change from red to orange") + parser.add_argument('--green-limit', type=float, default=DEFAULT_GREEN_LIMIT, help="Limit value to green status. It indicates the limit value in which the status change from orange to green") + + opt = parser.parse_args() + return vars(opt) + +def run(arguments): + coverage_input = arguments.get("coverage", "") + coverage_report_path = arguments.get("input_report", "") + if coverage_input: + percentage = parse_coverage(coverage_input) + else: + percentage = parse_coverage_from_report(coverage_report_path) + + limits = get_limit_values(arguments.get("red_limit", 0), arguments.get("green_limit", 0)) + color = get_color(percentage, limits) + label = get_label(arguments.get("label", "")) + destination_path = get_destination_path(arguments.get("output", "")) + download_image(label, percentage, color, destination_path) + +if __name__ == '__main__': + opt = parse_opt() + run(opt) diff --git a/assets/badge_generator/requirements.txt b/assets/badge_generator/requirements.txt new file mode 100644 index 000000000..51f7488e9 --- /dev/null +++ b/assets/badge_generator/requirements.txt @@ -0,0 +1,13 @@ +certifi==2024.2.2 +charset-normalizer==3.3.2 +click==8.1.7 +idna==3.7 +jinja2==3.1.4 +lxml==5.2.2 +MarkupSafe==2.1.5 +pycobertura==3.3.1 +requests==2.31.0 +ruamel.yaml==0.18.6 +ruamel.yaml.clib==0.2.8 +tabulate==0.9.0 +urllib3==2.2.1 From e8d5548c30b92d6bd98bfd38a5f709a22a3467a9 Mon Sep 17 00:00:00 2001 From: agustin Date: Wed, 15 May 2024 10:42:53 +0200 Subject: [PATCH 02/21] test(api) change api and cli workflow --- .github/workflows/api-unit-test.yml | 9 ++--- .github/workflows/cli-unit-test.yml | 48 ++++++++++++++++++----- API/controllers/entity_test.go | 31 ++++++++------- CLI/controllers/commandController_test.go | 46 +++++++++++----------- 4 files changed, 82 insertions(+), 52 deletions(-) diff --git a/.github/workflows/api-unit-test.yml b/.github/workflows/api-unit-test.yml index c37f8be90..a88f23ab2 100644 --- a/.github/workflows/api-unit-test.yml +++ b/.github/workflows/api-unit-test.yml @@ -14,6 +14,8 @@ jobs: api-unit-test: runs-on: ubuntu-latest + permissions: + contents: write defaults: run: working-directory: ./API @@ -76,7 +78,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 @@ -114,7 +116,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 @@ -127,9 +129,6 @@ jobs: with: name: api_coverage_badge - - name: Local ls - run: ls - - name: Verify Changed files uses: tj-actions/verify-changed-files@v16 id: verify-changed-files diff --git a/.github/workflows/cli-unit-test.yml b/.github/workflows/cli-unit-test.yml index 10a25efba..435c9bb33 100644 --- a/.github/workflows/cli-unit-test.yml +++ b/.github/workflows/cli-unit-test.yml @@ -11,6 +11,8 @@ name: 🕵️‍♂️ CLI Unit Tests jobs: cli-unit-test: runs-on: ubuntu-latest + permissions: + contents: write defaults: run: working-directory: ./CLI @@ -63,28 +65,30 @@ jobs: name: coverage_cli_xml path: ./CLI/coverage_cli.xml - coverage-badge: - needs: cli-unit-test + generate-coverage-badge: + needs: api-unit-test runs-on: ubuntu-latest permissions: contents: write 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 with: fetch-depth: 0 - ref: coverage_badges - uses: actions/setup-python@v5 with: python-version: '3.8' - - name: Install genbadge - run: pip install genbadge[coverage] + - name: Install requests + run: pip install requests + + - name: Install pycobertura + run: pip install pycobertura - name: Download line coverage reports uses: actions/download-artifact@v4 @@ -92,7 +96,33 @@ jobs: name: coverage_cli_xml - name: Generate badge - run: genbadge coverage -i coverage_cli.xml -n "CLI coverage" -o cli_coverage_badge.svg + run: python assets/badge_generator/generate_badge.py --label "CLI coverage" --output cli_coverage_badge.svg --input-report coverage_cli.xml --red-limit 50 --green-limit 65 + + - uses: actions/upload-artifact@v4 + with: + name: cli_coverage_badge + path: cli_coverage_badge.svg + + upload-coverage-badge: + needs: generate-coverage-badge + runs-on: ubuntu-latest + permissions: + contents: write + defaults: + run: + working-directory: ./ + # if: github.ref == 'refs/heads/main' && github.event.head_commit.author.name != 'GitHubActions' + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + ref: coverage_badges + + - name: Download coverage badge + uses: actions/download-artifact@v4 + with: + name: cli_coverage_badge - name: Verify Changed files uses: tj-actions/verify-changed-files@v16 @@ -106,11 +136,11 @@ jobs: git config --local user.email "<>" git config --local user.name "GitHubActions" git add cli_coverage_badge.svg - git commit -m "Add/Update CLI badge" + git commit -m "Add/Update badge" - name: Push badge commit if: steps.verify-changed-files.outputs.files_changed == 'true' uses: ad-m/github-push-action@master with: github_token: ${{ secrets.GITHUB_TOKEN }} - branch: coverage_badges # Dedicated branch to store coverage badges \ No newline at end of file + branch: coverage_badges # Dedicated branch to store coverage badges 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 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 ed0c21d3834d48668b744886ed512ab4e82d4a30 Mon Sep 17 00:00:00 2001 From: agustin Date: Wed, 15 May 2024 10:44:19 +0200 Subject: [PATCH 03/21] test(api) test cli --- CLI/controllers/commandController_test.go | 46 +++++++++++------------ 1 file changed, 23 insertions(+), 23 deletions(-) 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) { From ef314b82fc614324aa10479dc87d6b8c323a5e9c Mon Sep 17 00:00:00 2001 From: agustin Date: Wed, 15 May 2024 10:46:52 +0200 Subject: [PATCH 04/21] test(api) test cli --- .github/workflows/cli-unit-test.yml | 4 +- CLI/controllers/commandController_test.go | 46 +++++++++++------------ assets/badge_generator/generate_badge.py | 2 +- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/.github/workflows/cli-unit-test.yml b/.github/workflows/cli-unit-test.yml index 435c9bb33..babdff7a2 100644 --- a/.github/workflows/cli-unit-test.yml +++ b/.github/workflows/cli-unit-test.yml @@ -11,8 +11,8 @@ name: 🕵️‍♂️ CLI Unit Tests jobs: cli-unit-test: runs-on: ubuntu-latest - permissions: - contents: write + # permissions: + # contents: write defaults: run: working-directory: ./CLI 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) { diff --git a/assets/badge_generator/generate_badge.py b/assets/badge_generator/generate_badge.py index 1d0c79281..f4bed8d73 100644 --- a/assets/badge_generator/generate_badge.py +++ b/assets/badge_generator/generate_badge.py @@ -27,7 +27,7 @@ def parse_coverage_from_report(report_path): try: coverage_report = pycobertura.Cobertura(report_path) return round(coverage_report.line_rate() * 100, 2) - except: + except Exception: raise ValueError("Invalid file path or invalid file format") def parse_coverage(coverage): From 74603997cda0ad6f5730edeabafc1837e068c493 Mon Sep 17 00:00:00 2001 From: agustin Date: Wed, 15 May 2024 10:48:59 +0200 Subject: [PATCH 05/21] test(api) test cli --- .github/workflows/cli-unit-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cli-unit-test.yml b/.github/workflows/cli-unit-test.yml index babdff7a2..b23fee9ba 100644 --- a/.github/workflows/cli-unit-test.yml +++ b/.github/workflows/cli-unit-test.yml @@ -66,7 +66,7 @@ jobs: path: ./CLI/coverage_cli.xml generate-coverage-badge: - needs: api-unit-test + needs: cli-unit-test runs-on: ubuntu-latest permissions: contents: write From 18c585b45f7dbde959dad8c9987ab0b023e53b1b Mon Sep 17 00:00:00 2001 From: agustin Date: Wed, 15 May 2024 10:51:54 +0200 Subject: [PATCH 06/21] test(api) test cli --- .github/workflows/cli-unit-test.yml | 8 ++-- CLI/controllers/commandController_test.go | 46 +++++++++++------------ 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/.github/workflows/cli-unit-test.yml b/.github/workflows/cli-unit-test.yml index b23fee9ba..d191b7667 100644 --- a/.github/workflows/cli-unit-test.yml +++ b/.github/workflows/cli-unit-test.yml @@ -11,8 +11,8 @@ name: 🕵️‍♂️ CLI Unit Tests jobs: cli-unit-test: runs-on: ubuntu-latest - # permissions: - # contents: write + permissions: + contents: write defaults: run: working-directory: ./CLI @@ -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 @@ -111,7 +111,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/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) { From ad94bf173b86e6cec3f3a3aae4995a90b26699d4 Mon Sep 17 00:00:00 2001 From: agustin Date: Wed, 15 May 2024 11:30:06 +0200 Subject: [PATCH 07/21] test(api) create coverage github actions --- .../coverage/generate-badge/action.yaml | 55 ++++++++++++++ .../actions/coverage/upload-badge/action.yaml | 47 ++++++++++++ .github/workflows/api-unit-test.yml | 72 ++++-------------- API/controllers/entity_test.go | 73 +++++++++---------- 4 files changed, 154 insertions(+), 93 deletions(-) create mode 100644 .github/actions/coverage/generate-badge/action.yaml create mode 100644 .github/actions/coverage/upload-badge/action.yaml diff --git a/.github/actions/coverage/generate-badge/action.yaml b/.github/actions/coverage/generate-badge/action.yaml new file mode 100644 index 000000000..c2794fc4a --- /dev/null +++ b/.github/actions/coverage/generate-badge/action.yaml @@ -0,0 +1,55 @@ +name: Coverage Badge Generation +description: Generates a coverage badge and uploades it to an artifact + +inputs: + BADGE_ARTIFACT_NAME: + description: "Name of the Badge artifact" + required: true + COVERAGE_REPORT_ARTIFACT: + description: "Name of the XML coverage report artifact" + required: true + COVERAGE_REPORT_NAME: + description: "Name of the XML coverage report file" + required: true + LABEL: + description: "Badge label" + required: true + OUTPUT_FILE: + description: "Name of the output file" + required: true + RED_LIMIT: + description: "Percentage of the red/orange limit" + default: "50" + GREEN_LIMIT: + description: "Percentage of the orange/green limit" + default: "65" + +runs: + using: "composite" + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - uses: actions/setup-python@v5 + with: + python-version: '3.8' + + - name: Install requests + run: pip install requests + + - name: Install pycobertura + run: pip install pycobertura + + - name: Download line coverage reports + uses: actions/download-artifact@v4 + with: + name: ${{ inputs.COVERAGE_REPORT_ARTIFACT }} + + - name: Generate badge + run: python assets/badge_generator/generate_badge.py --label ${{ inputs.LABEL }} --output ${{ inputs.OUTPUT_FILE }} --input-report ${{ inputs.COVERAGE_REPORT_NAME }} --red-limit ${{ inputs.RED_LIMIT }} --green-limit ${{ inputs.GREEN_LIMIT }} + + - uses: actions/upload-artifact@v4 + with: + name: ${{ inputs.BADGE_ARTIFACT_NAME }} + path: ${{ inputs.OUTPUT_FILE }} diff --git a/.github/actions/coverage/upload-badge/action.yaml b/.github/actions/coverage/upload-badge/action.yaml new file mode 100644 index 000000000..45cce7f31 --- /dev/null +++ b/.github/actions/coverage/upload-badge/action.yaml @@ -0,0 +1,47 @@ +name: Upload Badge +description: Uploads the generated badge to an specific branch + +inputs: + BADGE_ARTIFACT_NAME: + description: "Name of the Badge artifact" + required: true + BADGE_FILE_NAME: + description: "Name of the Badge file" + required: true + BRANCH_NAME: + description: "Name of the branch where you want to add the badge" + required: true + +runs: + using: "composite" + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + ref: ${{ inputs.BRANCH_NAME }} + + - name: Download coverage badge + uses: actions/download-artifact@v4 + with: + name: ${{ inputs.BADGE_ARTIFACT_NAME }} + + - name: Verify Changed files + uses: tj-actions/verify-changed-files@v16 + id: verify-changed-files + with: + files: ${{ inputs.BADGE_FILE_NAME }} + + - name: Commit badge + if: steps.verify-changed-files.outputs.files_changed == 'true' + run: | + git config --local user.email "<>" + git config --local user.name "GitHubActions" + git add ${{ inputs.BADGE_FILE_NAME }} + git commit -m "Add/Update badge" + + - name: Push badge commit + if: steps.verify-changed-files.outputs.files_changed == 'true' + uses: ad-m/github-push-action@master + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + branch: ${{ inputs.BRANCH_NAME }} # Dedicated branch to store coverage badges diff --git a/.github/workflows/api-unit-test.yml b/.github/workflows/api-unit-test.yml index a88f23ab2..65d1e6469 100644 --- a/.github/workflows/api-unit-test.yml +++ b/.github/workflows/api-unit-test.yml @@ -78,35 +78,19 @@ 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 + - name: Generate Badge + uses: ./.github/actions/coverage/generate-badge with: - fetch-depth: 0 - - - uses: actions/setup-python@v5 - with: - python-version: '3.8' - - - name: Install requests - run: pip install requests - - - name: Install pycobertura - run: pip install pycobertura - - - name: Download line coverage reports - uses: actions/download-artifact@v4 - with: - name: coverage_api_xml - - - name: Generate badge - run: python assets/badge_generator/generate_badge.py --label "API coverage" --output api_coverage_badge.svg --input-report coverage_api.xml --red-limit 50 --green-limit 65 - - - uses: actions/upload-artifact@v4 - with: - name: api_coverage_badge - path: api_coverage_badge.svg + COVERAGE_REPORT_ARTIFACT: coverage_api_xml + COVERAGE_REPORT_NAME: coverage_api.xml + LABEL: "API coverage" + OUTPUT_FILE: api_coverage_badge.svg + RED_LIMIT: "50" + GREEN_LIMIT: "65" + BADGE_ARTIFACT_NAME: api_coverage_badge upload-coverage-badge: needs: generate-coverage-badge @@ -116,36 +100,12 @@ 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 - with: - fetch-depth: 0 - ref: coverage_badges - - - name: Download coverage badge - uses: actions/download-artifact@v4 - with: - name: api_coverage_badge - - - name: Verify Changed files - uses: tj-actions/verify-changed-files@v16 - id: verify-changed-files - with: - files: api_coverage_badge.svg - - - name: Commit badge - if: steps.verify-changed-files.outputs.files_changed == 'true' - run: | - git config --local user.email "<>" - git config --local user.name "GitHubActions" - git add api_coverage_badge.svg - git commit -m "Add/Update badge" - - - name: Push badge commit - if: steps.verify-changed-files.outputs.files_changed == 'true' - uses: ad-m/github-push-action@master + - name: Generate Badge + uses: ./.github/actions/coverage/generate-badge with: - github_token: ${{ secrets.GITHUB_TOKEN }} - branch: coverage_badges # Dedicated branch to store coverage badges + BADGE_ARTIFACT_NAME: api_coverage_badge + BADGE_FILE_NAME: api_coverage_badge.svg + BRANCH_NAME: coverage_badges diff --git a/API/controllers/entity_test.go b/API/controllers/entity_test.go index 787c93468..98ba8893f 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" @@ -596,39 +595,39 @@ func TestGetLayersObjectsLayerUnknown(t *testing.T) { assert.Equal(t, http.StatusNotFound, recorder.Code) } -func TestGetLayersObjectsWithSimpleFilter(t *testing.T) { - endpoint := test_utils.GetEndpoint("layersObjects", "racks-layer") - expectedMessage := "successfully processed request" - response := e2e.ValidateManagedRequest(t, "GET", endpoint+"?root=site-no-temperature.building-1.room-1", nil, http.StatusOK, expectedMessage) - - data, exists := response["data"].([]any) - assert.True(t, exists) - assert.Equal(t, 2, len(data)) - - condition := true - for _, rack := range data { - condition = condition && rack.(map[string]any)["parentId"] == "site-no-temperature.building-1.room-1" - condition = condition && rack.(map[string]any)["category"] == "rack" - } - - 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) - - 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" - } - - assert.True(t, condition) -} +// func TestGetLayersObjectsWithSimpleFilter(t *testing.T) { +// endpoint := test_utils.GetEndpoint("layersObjects", "racks-layer") +// expectedMessage := "successfully processed request" +// response := e2e.ValidateManagedRequest(t, "GET", endpoint+"?root=site-no-temperature.building-1.room-1", nil, http.StatusOK, expectedMessage) + +// data, exists := response["data"].([]any) +// assert.True(t, exists) +// assert.Equal(t, 2, len(data)) + +// condition := true +// for _, rack := range data { +// condition = condition && rack.(map[string]any)["parentId"] == "site-no-temperature.building-1.room-1" +// condition = condition && rack.(map[string]any)["category"] == "rack" +// } + +// 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) + +// 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" +// } + +// assert.True(t, condition) +// } From b37e603e2bab1d13ee472761dac1353c3eef4232 Mon Sep 17 00:00:00 2001 From: agustin Date: Wed, 15 May 2024 11:32:21 +0200 Subject: [PATCH 08/21] test(api) create coverage github actions --- .github/workflows/api-unit-test.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/api-unit-test.yml b/.github/workflows/api-unit-test.yml index 65d1e6469..a63d63971 100644 --- a/.github/workflows/api-unit-test.yml +++ b/.github/workflows/api-unit-test.yml @@ -14,8 +14,6 @@ jobs: api-unit-test: runs-on: ubuntu-latest - permissions: - contents: write defaults: run: working-directory: ./API From 8bae7d52e2ce3d988f410bed51132578c89cae95 Mon Sep 17 00:00:00 2001 From: agustin Date: Wed, 15 May 2024 11:49:02 +0200 Subject: [PATCH 09/21] test(api) create coverage github actions --- .github/workflows/api-unit-test.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/api-unit-test.yml b/.github/workflows/api-unit-test.yml index a63d63971..225cd810f 100644 --- a/.github/workflows/api-unit-test.yml +++ b/.github/workflows/api-unit-test.yml @@ -79,6 +79,10 @@ jobs: # if: github.ref == 'refs/heads/main' && github.event.head_commit.author.name != 'GitHubActions' steps: + - uses: actions/checkout@v4 + with: + fetch-depth: "0" + - name: Generate Badge uses: ./.github/actions/coverage/generate-badge with: @@ -101,8 +105,12 @@ jobs: # if: github.ref == 'refs/heads/main' && github.event.head_commit.author.name != 'GitHubActions' steps: + - uses: actions/checkout@v4 + with: + fetch-depth: "0" + - name: Generate Badge - uses: ./.github/actions/coverage/generate-badge + uses: ./.github/actions/coverage/upload-badge with: BADGE_ARTIFACT_NAME: api_coverage_badge BADGE_FILE_NAME: api_coverage_badge.svg From 6e57617b054f37b326bf6df55ecb07221fbe9400 Mon Sep 17 00:00:00 2001 From: agustin Date: Wed, 15 May 2024 12:00:28 +0200 Subject: [PATCH 10/21] test(api) create coverage github actions --- .github/actions/coverage/generate-badge/action.yaml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/actions/coverage/generate-badge/action.yaml b/.github/actions/coverage/generate-badge/action.yaml index c2794fc4a..a3e672e42 100644 --- a/.github/actions/coverage/generate-badge/action.yaml +++ b/.github/actions/coverage/generate-badge/action.yaml @@ -17,12 +17,14 @@ inputs: OUTPUT_FILE: description: "Name of the output file" required: true - RED_LIMIT: + RED_LIMIT: description: "Percentage of the red/orange limit" default: "50" - GREEN_LIMIT: + required: false + GREEN_LIMIT: description: "Percentage of the orange/green limit" default: "65" + required: false runs: using: "composite" @@ -47,7 +49,7 @@ runs: name: ${{ inputs.COVERAGE_REPORT_ARTIFACT }} - name: Generate badge - run: python assets/badge_generator/generate_badge.py --label ${{ inputs.LABEL }} --output ${{ inputs.OUTPUT_FILE }} --input-report ${{ inputs.COVERAGE_REPORT_NAME }} --red-limit ${{ inputs.RED_LIMIT }} --green-limit ${{ inputs.GREEN_LIMIT }} + run: python assets/badge_generator/generate_badge.py --label "${{ inputs.LABEL }}" --output "${{ inputs.OUTPUT_FILE }}" --input-report "${{ inputs.COVERAGE_REPORT_NAME }}" --red-limit "${{ inputs.RED_LIMIT }}" --green-limit "${{ inputs.GREEN_LIMIT }}" - uses: actions/upload-artifact@v4 with: From 2cc59a00c5af0878d8c5c3263420d3dad3749a00 Mon Sep 17 00:00:00 2001 From: agustin Date: Wed, 15 May 2024 12:04:02 +0200 Subject: [PATCH 11/21] test(api) create coverage github actions --- .github/actions/coverage/generate-badge/action.yaml | 3 +++ .github/actions/coverage/upload-badge/action.yaml | 1 + 2 files changed, 4 insertions(+) diff --git a/.github/actions/coverage/generate-badge/action.yaml b/.github/actions/coverage/generate-badge/action.yaml index a3e672e42..6cd4d62e4 100644 --- a/.github/actions/coverage/generate-badge/action.yaml +++ b/.github/actions/coverage/generate-badge/action.yaml @@ -38,9 +38,11 @@ runs: python-version: '3.8' - name: Install requests + shell: bash run: pip install requests - name: Install pycobertura + shell: bash run: pip install pycobertura - name: Download line coverage reports @@ -49,6 +51,7 @@ runs: name: ${{ inputs.COVERAGE_REPORT_ARTIFACT }} - name: Generate badge + shell: bash run: python assets/badge_generator/generate_badge.py --label "${{ inputs.LABEL }}" --output "${{ inputs.OUTPUT_FILE }}" --input-report "${{ inputs.COVERAGE_REPORT_NAME }}" --red-limit "${{ inputs.RED_LIMIT }}" --green-limit "${{ inputs.GREEN_LIMIT }}" - uses: actions/upload-artifact@v4 diff --git a/.github/actions/coverage/upload-badge/action.yaml b/.github/actions/coverage/upload-badge/action.yaml index 45cce7f31..4c47869dc 100644 --- a/.github/actions/coverage/upload-badge/action.yaml +++ b/.github/actions/coverage/upload-badge/action.yaml @@ -33,6 +33,7 @@ runs: - name: Commit badge if: steps.verify-changed-files.outputs.files_changed == 'true' + shell: bash run: | git config --local user.email "<>" git config --local user.name "GitHubActions" From ab35a11dcf0a3441cd7ee39b7876878e6d12a7d9 Mon Sep 17 00:00:00 2001 From: agustin Date: Wed, 15 May 2024 13:33:18 +0200 Subject: [PATCH 12/21] test(api) create coverage github actions --- .../actions/coverage/upload-badge/action.yaml | 5 +- .github/workflows/api-unit-test.yml | 3 +- .github/workflows/cli-unit-test.yml | 8 +-- CLI/controllers/commandController_test.go | 64 +++++++++---------- 4 files changed, 42 insertions(+), 38 deletions(-) diff --git a/.github/actions/coverage/upload-badge/action.yaml b/.github/actions/coverage/upload-badge/action.yaml index 4c47869dc..c34a5d99a 100644 --- a/.github/actions/coverage/upload-badge/action.yaml +++ b/.github/actions/coverage/upload-badge/action.yaml @@ -11,6 +11,9 @@ inputs: BRANCH_NAME: description: "Name of the branch where you want to add the badge" required: true + github_token: + description: "Github token" + required: true runs: using: "composite" @@ -44,5 +47,5 @@ runs: if: steps.verify-changed-files.outputs.files_changed == 'true' uses: ad-m/github-push-action@master with: - github_token: ${{ secrets.GITHUB_TOKEN }} + github_token: ${{ inputs.github_token }} branch: ${{ inputs.BRANCH_NAME }} # Dedicated branch to store coverage badges diff --git a/.github/workflows/api-unit-test.yml b/.github/workflows/api-unit-test.yml index 225cd810f..70036bd67 100644 --- a/.github/workflows/api-unit-test.yml +++ b/.github/workflows/api-unit-test.yml @@ -109,9 +109,10 @@ jobs: with: fetch-depth: "0" - - name: Generate Badge + - name: Upload Badge uses: ./.github/actions/coverage/upload-badge with: BADGE_ARTIFACT_NAME: api_coverage_badge BADGE_FILE_NAME: api_coverage_badge.svg BRANCH_NAME: coverage_badges + inputs: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/cli-unit-test.yml b/.github/workflows/cli-unit-test.yml index d191b7667..b23fee9ba 100644 --- a/.github/workflows/cli-unit-test.yml +++ b/.github/workflows/cli-unit-test.yml @@ -11,8 +11,8 @@ name: 🕵️‍♂️ CLI Unit Tests jobs: cli-unit-test: runs-on: ubuntu-latest - permissions: - contents: write + # permissions: + # contents: write defaults: run: working-directory: ./CLI @@ -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 @@ -111,7 +111,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/CLI/controllers/commandController_test.go b/CLI/controllers/commandController_test.go index 1fabc6452..93e4de1df 100644 --- a/CLI/controllers/commandController_test.go +++ b/CLI/controllers/commandController_test.go @@ -777,42 +777,42 @@ 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) { - controller, mockAPI, _ := layersSetup(t) - path := "/api/hierarchy-objects/BASIC.A.R1.A01" +// func TestIsAttrDrawableObjectNotFound(t *testing.T) { +// controller, mockAPI, _ := layersSetup(t) +// path := "/api/hierarchy-objects/BASIC.A.R1.A01" - test_utils.MockObjectNotFound(mockAPI, path) +// test_utils.MockObjectNotFound(mockAPI, path) - isAttrDrawable, err := controller.IsAttrDrawable(models.PhysicalPath+"BASIC/A/R1/A01", "color") - assert.False(t, isAttrDrawable) - assert.NotNil(t, err) - assert.Equal(t, "object not found", err.Error()) -} +// isAttrDrawable, err := controller.IsAttrDrawable(models.PhysicalPath+"BASIC/A/R1/A01", "color") +// assert.False(t, isAttrDrawable) +// assert.NotNil(t, err) +// assert.Equal(t, "object not found", err.Error()) +// } func TestIsAttrDrawableTemplateJsonIsNil(t *testing.T) { controller, mockAPI, _ := layersSetup(t) From 923c170e0f00c45cdc28d085f0534d47caec7e72 Mon Sep 17 00:00:00 2001 From: agustin Date: Wed, 15 May 2024 13:36:31 +0200 Subject: [PATCH 13/21] test(api) create coverage github actions --- .github/workflows/api-unit-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/api-unit-test.yml b/.github/workflows/api-unit-test.yml index 70036bd67..509c2441e 100644 --- a/.github/workflows/api-unit-test.yml +++ b/.github/workflows/api-unit-test.yml @@ -115,4 +115,4 @@ jobs: BADGE_ARTIFACT_NAME: api_coverage_badge BADGE_FILE_NAME: api_coverage_badge.svg BRANCH_NAME: coverage_badges - inputs: ${{ secrets.GITHUB_TOKEN }} + github_token: ${{ secrets.GITHUB_TOKEN }} From 3fb8c3d08339a5ca3b156bce06dc1b9dcab95405 Mon Sep 17 00:00:00 2001 From: agustin Date: Wed, 15 May 2024 13:41:22 +0200 Subject: [PATCH 14/21] test(api) create coverage github actions --- .github/workflows/api-unit-test.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/api-unit-test.yml b/.github/workflows/api-unit-test.yml index 509c2441e..6a90a7cc5 100644 --- a/.github/workflows/api-unit-test.yml +++ b/.github/workflows/api-unit-test.yml @@ -116,3 +116,7 @@ jobs: BADGE_FILE_NAME: api_coverage_badge.svg BRANCH_NAME: coverage_badges github_token: ${{ secrets.GITHUB_TOKEN }} + + - uses: actions/checkout@v4 + with: + fetch-depth: "0" From 603d9591b12167b4ee430742f0ae5cd24ae3159f Mon Sep 17 00:00:00 2001 From: agustin Date: Wed, 15 May 2024 13:45:27 +0200 Subject: [PATCH 15/21] test(api) create coverage github actions --- .github/actions/coverage/upload-badge/action.yaml | 4 ++++ .github/workflows/api-unit-test.yml | 4 ---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/actions/coverage/upload-badge/action.yaml b/.github/actions/coverage/upload-badge/action.yaml index c34a5d99a..401aad962 100644 --- a/.github/actions/coverage/upload-badge/action.yaml +++ b/.github/actions/coverage/upload-badge/action.yaml @@ -18,6 +18,10 @@ inputs: runs: using: "composite" steps: + - uses: actions/checkout@v4 + with: + fetch-depth: "0" + - uses: actions/checkout@v4 with: fetch-depth: 0 diff --git a/.github/workflows/api-unit-test.yml b/.github/workflows/api-unit-test.yml index 6a90a7cc5..509c2441e 100644 --- a/.github/workflows/api-unit-test.yml +++ b/.github/workflows/api-unit-test.yml @@ -116,7 +116,3 @@ jobs: BADGE_FILE_NAME: api_coverage_badge.svg BRANCH_NAME: coverage_badges github_token: ${{ secrets.GITHUB_TOKEN }} - - - uses: actions/checkout@v4 - with: - fetch-depth: "0" From 31a81b2b145acd04a3b75bf200280d0a21532f13 Mon Sep 17 00:00:00 2001 From: agustin Date: Wed, 15 May 2024 13:49:10 +0200 Subject: [PATCH 16/21] test(api) create coverage github actions --- .github/actions/coverage/upload-badge/action.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/actions/coverage/upload-badge/action.yaml b/.github/actions/coverage/upload-badge/action.yaml index 401aad962..eab5f6fef 100644 --- a/.github/actions/coverage/upload-badge/action.yaml +++ b/.github/actions/coverage/upload-badge/action.yaml @@ -19,8 +19,8 @@ runs: using: "composite" steps: - uses: actions/checkout@v4 - with: - fetch-depth: "0" + with: + fetch-depth: "0" - uses: actions/checkout@v4 with: From d1610413eebc8b885305a625bf9c4cb9b413bf44 Mon Sep 17 00:00:00 2001 From: agustin Date: Wed, 15 May 2024 13:52:23 +0200 Subject: [PATCH 17/21] test(api) create coverage github actions --- .github/actions/coverage/upload-badge/action.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/actions/coverage/upload-badge/action.yaml b/.github/actions/coverage/upload-badge/action.yaml index eab5f6fef..f6be3ffe3 100644 --- a/.github/actions/coverage/upload-badge/action.yaml +++ b/.github/actions/coverage/upload-badge/action.yaml @@ -18,10 +18,6 @@ inputs: runs: using: "composite" steps: - - uses: actions/checkout@v4 - with: - fetch-depth: "0" - - uses: actions/checkout@v4 with: fetch-depth: 0 @@ -53,3 +49,7 @@ runs: with: github_token: ${{ inputs.github_token }} branch: ${{ inputs.BRANCH_NAME }} # Dedicated branch to store coverage badges + + - uses: actions/checkout@v4 # we checkout to main so we have access the actions folder and we can execute the Post Upload + with: + fetch-depth: "0" From e37a5eed212c4be6f9eee77e23325740179ac793 Mon Sep 17 00:00:00 2001 From: agustin Date: Wed, 15 May 2024 13:58:44 +0200 Subject: [PATCH 18/21] test(api) use coverage github actions in cli --- .github/workflows/cli-unit-test.yml | 63 ++++++----------------- API/controllers/entity_test.go | 28 +++++----- CLI/controllers/commandController_test.go | 18 +++---- 3 files changed, 39 insertions(+), 70 deletions(-) diff --git a/.github/workflows/cli-unit-test.yml b/.github/workflows/cli-unit-test.yml index b23fee9ba..834b5e14b 100644 --- a/.github/workflows/cli-unit-test.yml +++ b/.github/workflows/cli-unit-test.yml @@ -78,30 +78,18 @@ jobs: steps: - uses: actions/checkout@v4 with: - fetch-depth: 0 + fetch-depth: "0" - - uses: actions/setup-python@v5 + - name: Generate Badge + uses: ./.github/actions/coverage/generate-badge with: - python-version: '3.8' - - - name: Install requests - run: pip install requests - - - name: Install pycobertura - run: pip install pycobertura - - - name: Download line coverage reports - uses: actions/download-artifact@v4 - with: - name: coverage_cli_xml - - - name: Generate badge - run: python assets/badge_generator/generate_badge.py --label "CLI coverage" --output cli_coverage_badge.svg --input-report coverage_cli.xml --red-limit 50 --green-limit 65 - - - uses: actions/upload-artifact@v4 - with: - name: cli_coverage_badge - path: cli_coverage_badge.svg + COVERAGE_REPORT_ARTIFACT: coverage_cli_xml + COVERAGE_REPORT_NAME: coverage_cli.xml + LABEL: "CLI coverage" + OUTPUT_FILE: cli_coverage_badge.svg + RED_LIMIT: "50" + GREEN_LIMIT: "65" + BADGE_ARTIFACT_NAME: cli_coverage_badge upload-coverage-badge: needs: generate-coverage-badge @@ -116,31 +104,12 @@ jobs: steps: - uses: actions/checkout@v4 with: - fetch-depth: 0 - ref: coverage_badges + fetch-depth: "0" - - name: Download coverage badge - uses: actions/download-artifact@v4 - with: - name: cli_coverage_badge - - - name: Verify Changed files - uses: tj-actions/verify-changed-files@v16 - id: verify-changed-files - with: - files: cli_coverage_badge.svg - - - name: Commit badge - if: steps.verify-changed-files.outputs.files_changed == 'true' - run: | - git config --local user.email "<>" - git config --local user.name "GitHubActions" - git add cli_coverage_badge.svg - git commit -m "Add/Update badge" - - - name: Push badge commit - if: steps.verify-changed-files.outputs.files_changed == 'true' - uses: ad-m/github-push-action@master + - name: Upload Badge + uses: ./.github/actions/coverage/upload-badge with: + BADGE_ARTIFACT_NAME: cli_coverage_badge + BADGE_FILE_NAME: cli_coverage_badge.svg + BRANCH_NAME: coverage_badges github_token: ${{ secrets.GITHUB_TOKEN }} - branch: coverage_badges # Dedicated branch to store coverage badges diff --git a/API/controllers/entity_test.go b/API/controllers/entity_test.go index 98ba8893f..7afb70614 100644 --- a/API/controllers/entity_test.go +++ b/API/controllers/entity_test.go @@ -595,23 +595,23 @@ func TestGetLayersObjectsLayerUnknown(t *testing.T) { assert.Equal(t, http.StatusNotFound, recorder.Code) } -// func TestGetLayersObjectsWithSimpleFilter(t *testing.T) { -// endpoint := test_utils.GetEndpoint("layersObjects", "racks-layer") -// expectedMessage := "successfully processed request" -// response := e2e.ValidateManagedRequest(t, "GET", endpoint+"?root=site-no-temperature.building-1.room-1", nil, http.StatusOK, expectedMessage) +func TestGetLayersObjectsWithSimpleFilter(t *testing.T) { + endpoint := test_utils.GetEndpoint("layersObjects", "racks-layer") + expectedMessage := "successfully processed request" + response := e2e.ValidateManagedRequest(t, "GET", endpoint+"?root=site-no-temperature.building-1.room-1", 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 && rack.(map[string]any)["parentId"] == "site-no-temperature.building-1.room-1" -// condition = condition && rack.(map[string]any)["category"] == "rack" -// } + condition := true + for _, rack := range data { + condition = condition && rack.(map[string]any)["parentId"] == "site-no-temperature.building-1.room-1" + condition = condition && rack.(map[string]any)["category"] == "rack" + } -// assert.True(t, condition) -// } + assert.True(t, condition) +} // func TestGetLayersObjectsWithDoubleFilter(t *testing.T) { // endpoint := test_utils.GetEndpoint("layersObjects", "racks-1-layer") diff --git a/CLI/controllers/commandController_test.go b/CLI/controllers/commandController_test.go index 93e4de1df..5ca6af61d 100644 --- a/CLI/controllers/commandController_test.go +++ b/CLI/controllers/commandController_test.go @@ -802,17 +802,17 @@ func TestIsEntityDrawableObjectNotFound(t *testing.T) { // } // Tests IsAttrDrawable (and IsCategoryAttrDrawable) -// func TestIsAttrDrawableObjectNotFound(t *testing.T) { -// controller, mockAPI, _ := layersSetup(t) -// path := "/api/hierarchy-objects/BASIC.A.R1.A01" +func TestIsAttrDrawableObjectNotFound(t *testing.T) { + controller, mockAPI, _ := layersSetup(t) + path := "/api/hierarchy-objects/BASIC.A.R1.A01" -// test_utils.MockObjectNotFound(mockAPI, path) + test_utils.MockObjectNotFound(mockAPI, path) -// isAttrDrawable, err := controller.IsAttrDrawable(models.PhysicalPath+"BASIC/A/R1/A01", "color") -// assert.False(t, isAttrDrawable) -// assert.NotNil(t, err) -// assert.Equal(t, "object not found", err.Error()) -// } + isAttrDrawable, err := controller.IsAttrDrawable(models.PhysicalPath+"BASIC/A/R1/A01", "color") + assert.False(t, isAttrDrawable) + assert.NotNil(t, err) + assert.Equal(t, "object not found", err.Error()) +} func TestIsAttrDrawableTemplateJsonIsNil(t *testing.T) { controller, mockAPI, _ := layersSetup(t) From 696be6622e7506ea53a2896076168f26dce26925 Mon Sep 17 00:00:00 2001 From: agustin Date: Wed, 15 May 2024 14:02:44 +0200 Subject: [PATCH 19/21] test(api) use coverage github actions in cli --- CLI/controllers/commandController_test.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/CLI/controllers/commandController_test.go b/CLI/controllers/commandController_test.go index 5ca6af61d..93e4de1df 100644 --- a/CLI/controllers/commandController_test.go +++ b/CLI/controllers/commandController_test.go @@ -802,17 +802,17 @@ func TestIsEntityDrawableObjectNotFound(t *testing.T) { // } // Tests IsAttrDrawable (and IsCategoryAttrDrawable) -func TestIsAttrDrawableObjectNotFound(t *testing.T) { - controller, mockAPI, _ := layersSetup(t) - path := "/api/hierarchy-objects/BASIC.A.R1.A01" +// func TestIsAttrDrawableObjectNotFound(t *testing.T) { +// controller, mockAPI, _ := layersSetup(t) +// path := "/api/hierarchy-objects/BASIC.A.R1.A01" - test_utils.MockObjectNotFound(mockAPI, path) +// test_utils.MockObjectNotFound(mockAPI, path) - isAttrDrawable, err := controller.IsAttrDrawable(models.PhysicalPath+"BASIC/A/R1/A01", "color") - assert.False(t, isAttrDrawable) - assert.NotNil(t, err) - assert.Equal(t, "object not found", err.Error()) -} +// isAttrDrawable, err := controller.IsAttrDrawable(models.PhysicalPath+"BASIC/A/R1/A01", "color") +// assert.False(t, isAttrDrawable) +// assert.NotNil(t, err) +// assert.Equal(t, "object not found", err.Error()) +// } func TestIsAttrDrawableTemplateJsonIsNil(t *testing.T) { controller, mockAPI, _ := layersSetup(t) From 21decd732d0206d9f1f2b2ea2641da4607476ca6 Mon Sep 17 00:00:00 2001 From: agustin Date: Wed, 15 May 2024 14:08:58 +0200 Subject: [PATCH 20/21] test(api) use coverage github actions in cli --- .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 | 64 +++++++++++------------ 4 files changed, 52 insertions(+), 51 deletions(-) diff --git a/.github/workflows/api-unit-test.yml b/.github/workflows/api-unit-test.yml index 509c2441e..33eee1d8a 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 834b5e14b..9bd7ef999 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 93e4de1df..1fabc6452 100644 --- a/CLI/controllers/commandController_test.go +++ b/CLI/controllers/commandController_test.go @@ -777,42 +777,42 @@ 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) { -// controller, mockAPI, _ := layersSetup(t) -// path := "/api/hierarchy-objects/BASIC.A.R1.A01" +func TestIsAttrDrawableObjectNotFound(t *testing.T) { + controller, mockAPI, _ := layersSetup(t) + path := "/api/hierarchy-objects/BASIC.A.R1.A01" -// test_utils.MockObjectNotFound(mockAPI, path) + test_utils.MockObjectNotFound(mockAPI, path) -// isAttrDrawable, err := controller.IsAttrDrawable(models.PhysicalPath+"BASIC/A/R1/A01", "color") -// assert.False(t, isAttrDrawable) -// assert.NotNil(t, err) -// assert.Equal(t, "object not found", err.Error()) -// } + isAttrDrawable, err := controller.IsAttrDrawable(models.PhysicalPath+"BASIC/A/R1/A01", "color") + assert.False(t, isAttrDrawable) + assert.NotNil(t, err) + assert.Equal(t, "object not found", err.Error()) +} func TestIsAttrDrawableTemplateJsonIsNil(t *testing.T) { controller, mockAPI, _ := layersSetup(t) From 911a561cfc3e0fa575753606651510039feeff06 Mon Sep 17 00:00:00 2001 From: agustin Date: Wed, 15 May 2024 14:48:33 +0200 Subject: [PATCH 21/21] test(api) add Readme to badge generator script --- assets/badge_generator/ReadMe.md | 39 ++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 assets/badge_generator/ReadMe.md diff --git a/assets/badge_generator/ReadMe.md b/assets/badge_generator/ReadMe.md new file mode 100644 index 000000000..6f527dbe1 --- /dev/null +++ b/assets/badge_generator/ReadMe.md @@ -0,0 +1,39 @@ +# Badge Generator +Script that generates a coverage badge. You can customize the following parameters: + +- The left label that will appear in the badge +- The color range limits. By default, the badge will be red between 0-50%, orange between 50-65% and green if higher than 65 +- The output file name + +The coverage percentage be passed in two different ways: + +- By giving the desired value using the flag `--coverage` +- By indicating the path to the XML coverage report using the flag `--input-report` + +Installation +------------ +```bash +# Generate python virtual environment and activate it +python3 -m venv venv +source venv/bin/activate + +# Install requirements +pip install -r requirements.txt +``` + +Examples +------------ + +```bash +# Run help +python generate_badge.py --help + +# Generate badge with default values and indicating the coverage percentage +python generate_badge.py --coverage 75 + +# Generate with xml report file +python generate_badge.py --input-report coverage.xml + +# Generate badge with multiple parameters +python generate_badge.py --label "API coverage" --input-report coverage.xml --output coverage_api.svg --red-limit 55 --green-limit 70 +```