DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Extending the Salesforce CLI with a Custom Plugin
  • Implementing ROS Communication Patterns
  • Creating a Web Project: Refactoring
  • Essential GitHub Enterprise Admin Commands

Trending

  • Introducing Graph Concepts in Java With Eclipse JNoSQL
  • The Evolution of Scalable and Resilient Container Infrastructure
  • How To Introduce a New API Quickly Using Quarkus and ChatGPT
  • Building a Real-Time Audio Transcription System With OpenAI’s Realtime API
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. SonarQube Analysis With Ginkgo on Mac

SonarQube Analysis With Ginkgo on Mac

Ginkgo is the testing framework of choice for many projects developed in Golang. Find out how to setup SonarQube analysis for Golang projects on Mac.

By 
Barzana Panayotova user avatar
Barzana Panayotova
·
Nov. 02, 21 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
8.9K Views

Join the DZone community and get the full member experience.

Join For Free

Ginkgo is the testing framework of choice for many projects developed in Golang. Here is an example setup for SonarQube project analysis.

Prerequisites

  • SonarQube server installation: For the purpose of the tutorial I have a docker image running on my machine on http://localhost:9000.
  • SonarQube project: For the purpose of the tutorial I have created a project with project key com.bdpanajotova.golang-sonar-example and name Golang Sonar Example.
  • Golang project for analysis with Ginkgo tests: Here is the example project I use in GitHub.

Here is the documentation for the fast local setup of SonarQube.

My environment is macOS Big Sur 11.3.

Step 1: Setup sonar-scanner

Download the respective version of SonarScanner for your system: sonar-scanner.

Unzip the downloaded file and export it in your PATH.

Shell
 
% unzip sonar-scanner-cli-4.6.2.2472-macosx.zip
Archive:  sonar-scanner-cli-4.6.2.2472-macosx.zip
   creating: sonar-scanner-4.6.2.2472-macosx/
...

% pwd
/Users/barzana.nikolova/Downloads
% export PATH=$PATH:/Users/barzana.nikolova/Downloads/sonar-scanner-4.6.2.2472-macosx/bin
% sonar-scanner -h
INFO:
INFO: usage: sonar-scanner [options]
INFO:
INFO: Options:
INFO:  -D,--define <arg>     Define property
INFO:  -h,--help             Display help information
INFO:  -v,--version          Display version information
INFO:  -X,--debug            Produce execution debug output

Step 2:  Create sonar-scanner.properties File

Create a sonar-scanner.properties file in your project root directory.

Properties files
 
#----- SonarQube Analysis Setup
sonar.host.url=http://localhost:9000
sonar.projectKey=com.bdpanajotova.golang-sonar-example
sonar.projectName=Golang Sonar Example
sonar.login=b58b1848e45247651387fe23dd580e464e67be49 
# Generated token in SonarQube - http://localhost:9000/account/security/

sonar.sources=.
sonar.exclusions=**/*_test.go

sonar.tests=.
sonar.test.inclusions=**/*_test.go

sonar.go.coverage.reportPaths=.coverage/coverage.out

This configuration expects a single coverage report in folder .coverage/coverage.out.

Step 3: Generate Coverage Report 

From the root project directory, execute the following to generate a coverage report file:

Shell
 
% ginkgo -cover -coverprofile=coverage.out -outputdir=.coverage ./...                
Running Suite: Animal Suite
===========================
Random Seed: 1634367783
Will run 2 of 2 specs

••
Ran 2 of 2 Specs in 0.000 seconds
SUCCESS! -- 2 Passed | 0 Failed | 0 Pending | 0 Skipped
PASS
coverage: 66.7% of statements
path is /Users/barzana.nikolova/GolandProjects/golang-sonar-example/.coverage
All profiles combined

Ginkgo ran 1 suite in 4.455071542s
Test Suite Passed
barzana.nikolova@Krasimirs-MacBook-Pro golang-sonar-example % 

This command combines all the test coverage output in one file that will be used by sonar-scanner when analyzing your project.

Step 4: Run sonar-scanner

To analyze your project, run the following command:

Shell
 
% sonar-scanner -Dproject.settings=sonar-scanner.properties                          
INFO: Scanner configuration file: /Users/barzana.nikolova/sonar-scanner/conf/sonar-scanner.properties
INFO: Project root configuration file: /Users/barzana.nikolova/GolandProjects/golang-sonar-example/sonar-scanner.properties
INFO: SonarScanner 4.6.2.2472
INFO: Java 11.0.11 AdoptOpenJDK (64-bit)
INFO: Mac OS X 11.3 x86_64
...
INFO: ANALYSIS SUCCESSFUL, you can browse http://localhost:9000/dashboard?id=com.bdpanajotova.golang-sonar-example
INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
INFO: More about the report processing at http://localhost:9000/api/ce/task?id=AXyH7DsT6By06DIoRBpH
INFO: Analysis total time: 5.955 s
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
INFO: Total time: 7.804s
INFO: Final Memory: 14M/54M
INFO: ------------------------------------------------------------------------
barzana.nikolova@Krasimirs-MacBook-Pro golang-sonar-example % 

Step 5: See the Project Analysis in SonarQube

Here is the overall status of the project:

Project Analysis in SonarQube

Here is the uploaded code coverage report:

Uploaded code coverage report


I hope it has become clear how to configure simple sonar scans for Golang Ginkgo projects.

I welcome your thoughts and feedback.

Code coverage Golang shell Testing Directory Command (computing) GitHub

Opinions expressed by DZone contributors are their own.

Related

  • Extending the Salesforce CLI with a Custom Plugin
  • Implementing ROS Communication Patterns
  • Creating a Web Project: Refactoring
  • Essential GitHub Enterprise Admin Commands

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!