Skip to content

Commit

Permalink
VS Code extension update - now generate github test pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
0xMartin committed Aug 13, 2024
1 parent ef4816f commit ca97a7d
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 26 deletions.
40 changes: 17 additions & 23 deletions natt-vscode-extension/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@

The **NATT Configuration Editor** is a Visual Studio Code extension developed as part of a project at **[TBU FAI](https://www.utb.cz/en/)**. This extension facilitates the creation, editing, and execution of test configuration using the **Network Application Testing Tool (NATT)**. The tool allows users to perform black box testing on various types of software applications.

## 📜 Network Application Testing Tool (NATT)
> **Video tutorial on YouTube: [How to use NATT?](https://youtu.be/QWM2mg2x6cA)**
NATT was created as part of a thesis at TBU FAI. It is a black box testing tool designed for automating the testing and evaluation of tasks. The tool's key features include:

- **🌐 Universality:** Supports testing various types of software applications regardless of their implementation details.
- **🔍 Separation:** Emphasizes the separation of the evaluation application and its internal logic from the tested tasks.
- **🔌 Independence:** Operates independently of external network resources, allowing it to create virtual servers and clients for testing purposes.
- **🛠️ Flexibility:** Users can easily define new test sets using specific keywords in the configuration.
- **📦 Plugin Support:** The tool supports the creation of custom plugins, allowing users to define their own keywords, communication modules or more for enhanced functionality. Tutorial is available [here](https://github.com/0xMartin/NetworkAppTestingTool/tree/main/examples/plugin-example).
> For more information about **NATT**, visit the [NATT GitHub repository](https://github.com/0xMartin/NetworkAppTestingTool).
> **Documentation for all keywords that are used in configuration [NATT keywords](https://github.com/0xMartin/NetworkAppTestingTool/blob/main/keywords.md).**
>
### 🔍 What Does the Tool Allow You to Test?

- Simple **email** sending applications
Expand All @@ -23,18 +19,15 @@ NATT was created as part of a thesis at TBU FAI. It is a black box testing tool
- **Web crawlers**
- Applications through the **standard stream**

The tested applications can be written in any language.

> For more information about **NATT**, visit the [NATT GitHub repository](https://github.com/0xMartin/NetworkAppTestingTool).
> **Documentation for all keywords that are used in configuration [NATT keywords](https://github.com/0xMartin/NetworkAppTestingTool/blob/main/keywords.md).**
> The tested applications can be written in any language.
## 🌟 Features of the NATT Configuration Editor

- **📝 Intuitive Configuration Editor:** Easily create and modify test configurations with code autocomplete.
- **🧪 Execute Tests:** Directly execute and manage tests from within the extension, streamlining your workflow and providing immediate feedback.
- **📊 Test Report Viewer:** View detailed test reports within VS Code, allowing you to analyze results without leaving your development environment.
- **💡 Code Snippets:** Quickly insert common test configuration snippets to speed up the writing process.
- **🔧 Automated Setup for Local and CI Testing:** Automatically prepare all necessary files for testing on `localhost` as well as in `GitLab/GitHub` pipelines. While the pipeline setup is automated, it allows for minor adjustments, such as changing JDK versions or other specific configurations.

## 🔧 Commands

Expand All @@ -47,16 +40,6 @@ The extension provides several commands to facilitate testing:
- **✅ NATT Validate:** Validates the configuration file for syntax errors.
- **🔄 NATT Reload:** Reloads the keywords list (snippets, descriptions, etc.).

## 📸 Screenshots

The primary side bar contains the main control panel for the extension, with buttons for "Initialize," "Run Test," "Stop Test," and "Validate." The lower section includes a list of keywords used in the NATT configuration.

<img alt="NATT Extension 1" src="https://raw.githubusercontent.com/0xMartin/NetworkAppTestingTool/main/natt-vscode-extension/doc/vs_code_extension_1.png" width="50%" />

The VS Code editor showing the configuration file on the left and the test results report on the right. Users can see the outcome of their software tests in the detailed report.

<img alt="NATT Extension 2" src="https://raw.githubusercontent.com/0xMartin/NetworkAppTestingTool/main/natt-vscode-extension/doc/vs_code_extension_2.png" width="100%" />

## 🚀 Installation

1. **Install the Extension:** Search for "NATT Configuration Editor" in the Visual Studio Code extensions marketplace and install it.
Expand All @@ -68,3 +51,14 @@ The VS Code editor showing the configuration file on the left and the test resul

> It is recommended to set the **Tab Display Size** on **4**
## 📸 Extension UI

The primary side bar contains the main control panel for the extension, with buttons for `Initialize`, `Run Test`, `Stop Test`, `Show Report`, `Validate` and `Reload`. The lower section includes a list of keywords used in the NATT configuration. This list is automatically generated by current version of **NATT.jar** in project directory.

<img alt="NATT Extension 1" src="https://raw.githubusercontent.com/0xMartin/NetworkAppTestingTool/main/natt-vscode-extension/doc/vs_code_extension_1.png" width="50%" />

The VS Code editor showing the configuration file on the left and the test results report on the right. Users can see the outcome of their software tests in the detailed report.

<img alt="NATT Extension 2" src="https://raw.githubusercontent.com/0xMartin/NetworkAppTestingTool/main/natt-vscode-extension/doc/vs_code_extension_2.png" width="100%" />


21 changes: 21 additions & 0 deletions natt-vscode-extension/out/extension.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion natt-vscode-extension/out/extension.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion natt-vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"publisher": "0xM4R71N",
"repository": "https://github.com/0xMartin/NetworkAppTestingTool",
"description": "Test scenario configuration editor for black box network application testing tool.",
"version": "1.2.8",
"version": "1.2.9",
"engines": {
"vscode": "^1.91.1"
},
Expand Down
71 changes: 71 additions & 0 deletions natt-vscode-extension/resources/github-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Java CI

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

- name: Cache Gradle packages
uses: actions/cache@v3
with:
path: ~/.gradle
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Checkout code
uses: actions/checkout@v3

- name: Build with Gradle
run: ./gradlew build

- name: Save build artifacts
if: success()
uses: actions/upload-artifact@v3
with:
name: app-libs
path: app/build/libs/*.jar

test:
runs-on: ubuntu-latest
needs: build

steps:
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

- name: Checkout code
uses: actions/checkout@v3

- name: Download build artifacts
uses: actions/download-artifact@v3
with:
name: app-libs
path: app/build/libs

- name: Run black box tests
run: java -jar NATT.jar -c test-config.yaml

- name: Save test report
if: success()
uses: actions/upload-artifact@v3
with:
name: test-report
path: test_report.html
26 changes: 25 additions & 1 deletion natt-vscode-extension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function registerKeywordSnippets(context: vscode.ExtensionContext, viewProvider:
meta: `${keyword.kwGroup} - ${keyword.description}`
};
});

function getExampleValue(type: string): string {
switch (type) {
case 'STRING':
Expand Down Expand Up @@ -149,6 +149,7 @@ export function activate(context: vscode.ExtensionContext) {

vscode.window.showInformationMessage('NATT initialization started!');

/****************************************************************************************************************************** */
const sourceYamlPath = path.join(context.extensionPath, 'resources', 'test-config.yaml');
const destYamlPath = path.join(projectPath, 'test-config.yaml');

Expand All @@ -160,6 +161,7 @@ export function activate(context: vscode.ExtensionContext) {
vscode.window.showInformationMessage('test-config.yaml already exists, skipping copy.');
}

/****************************************************************************************************************************** */
const sourceGitLabYamlPath = path.join(context.extensionPath, 'resources', '.gitlab-ci.yml');
const destGitLabYamlPath = path.join(projectPath, '.gitlab-ci.yml');

Expand All @@ -170,6 +172,27 @@ export function activate(context: vscode.ExtensionContext) {
} else {
vscode.window.showInformationMessage('.gitlab-ci.yml already exists, skipping copy.');
}

/****************************************************************************************************************************** */
const sourceGithubYamlPath = path.join(context.extensionPath, 'resources', 'github-ci.yml');
const destGithubFolder = path.join(projectPath, '.github', 'workflows');
const destGithubYamlPath = path.join(destGithubFolder, 'github-ci.yml');

// Check if the .github/workflows folder exists, if not, create it
if (!fs.existsSync(destGithubFolder)) {
fs.mkdirSync(destGithubFolder, { recursive: true });
vscode.window.showInformationMessage('.github/workflows folder created successfully!');
}

// Check if the github-ci.yml file already exists
if (!fs.existsSync(destGithubYamlPath)) {
fs.copyFileSync(sourceGithubYamlPath, destGithubYamlPath);
vscode.window.showInformationMessage('github-ci.yml copied successfully!');
} else {
vscode.window.showInformationMessage('github-ci.yml already exists, skipping copy.');
}

/****************************************************************************************************************************** */
// Define the URL and destination path for the JAR file
const config = vscode.workspace.getConfiguration('natt-configuration-editor');
const jarUrl = config.get<string>('nattJarUrl', 'https://github.com/0xMartin/NetworkAppTestingTool/releases/download/1.6.6/NATT.jar');
Expand Down Expand Up @@ -197,6 +220,7 @@ export function activate(context: vscode.ExtensionContext) {
});
};

/****************************************************************************************************************************** */
try {
// Use vscode.window.withProgress to show a loading bar during the download
await vscode.window.withProgress({
Expand Down

0 comments on commit ca97a7d

Please sign in to comment.