-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test workflow + unit tests (#54)
* Add test workflow * Add .mockery.yaml file, generate all interface mocks * Add file module unit tests * Add config module unit tests * Use t.TempDir() instead of os.TempDir() for tests * Cancel in progress workflows * Remove test * Fix component controller test * Fix testutils
- Loading branch information
1 parent
a3e9ff0
commit 066fd34
Showing
42 changed files
with
3,096 additions
and
749 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
name: Test | ||
|
||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
env: | ||
GOLANG_VERSION: "1.21" | ||
NODE_VERSION: "16.x" | ||
|
||
jobs: | ||
test-go: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Setup go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version-file: go.mod | ||
|
||
- name: Install Wails | ||
run: go install github.com/wailsapp/wails/v2/cmd/wails@latest | ||
shell: bash | ||
|
||
- name: Install Linux Wails deps | ||
run: sudo apt-get update && sudo apt-get install libgtk-3-0 libwebkit2gtk-4.0-dev gcc-aarch64-linux-gnu | ||
shell: bash | ||
|
||
- name: Build | ||
run: | | ||
mkdir build | ||
cp -r assets build/assets | ||
wails build | ||
shell: bash | ||
|
||
- name: Run tests | ||
uses: robherley/go-test-action@v0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
dir: "{{.InterfaceDir}}/mocks" | ||
mockname: "Mock{{.InterfaceName}}" | ||
outpkg: "mocks" | ||
with-expecter: True | ||
all: True | ||
packages: | ||
github.com/scanoss/scanoss.lui: | ||
config: | ||
recursive: True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
backend/main/pkg/common/config/repository/config_repository_json_impl_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package repository | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/scanoss/scanoss.lui/backend/main/pkg/common/config/entities" | ||
"github.com/scanoss/scanoss.lui/backend/main/pkg/utils" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestNewConfigJsonRepository(t *testing.T) { | ||
path := "config.json" | ||
repo := NewConfigJsonRepository(path) | ||
assert.Equal(t, path, repo.configPath) | ||
} | ||
|
||
func TestConfigJsonRepository_Init(t *testing.T) { | ||
path := "config.json" | ||
repo := NewConfigJsonRepository(path) | ||
|
||
err := repo.Init() | ||
assert.NoError(t, err) | ||
|
||
fileExists := utils.FileExist(path) | ||
assert.NoError(t, fileExists) | ||
|
||
os.Remove(path) | ||
} | ||
|
||
func TestConfigJsonRepository_Save(t *testing.T) { | ||
path := t.TempDir() + "config.json" | ||
repo := NewConfigJsonRepository(path) | ||
|
||
err := repo.Init() | ||
assert.NoError(t, err) | ||
|
||
config := &entities.Config{ | ||
ApiUrl: "https://api.scanoss.org", | ||
ApiToken: "test-token", | ||
} | ||
|
||
repo.Save(config) | ||
|
||
fileData, err := os.ReadFile(path) | ||
assert.NoError(t, err) | ||
|
||
savedData, err := utils.JSONParse[map[string]string](fileData) | ||
assert.NoError(t, err) | ||
|
||
assert.NoError(t, err) | ||
assert.Equal(t, config.ApiUrl, savedData["apiUrl"]) | ||
assert.Equal(t, config.ApiToken, savedData["apiToken"]) | ||
|
||
os.Remove(path) | ||
} | ||
|
||
func TestConfigJsonRepository_Read(t *testing.T) { | ||
path := t.TempDir() + "config.json" | ||
repo := NewConfigJsonRepository(path) | ||
config := &entities.Config{ | ||
ApiUrl: "https://api.scanoss.org", | ||
ApiToken: "test-token", | ||
} | ||
|
||
err := repo.Init() | ||
assert.NoError(t, err) | ||
|
||
repo.Save(config) | ||
|
||
readConfig, err := repo.Read() | ||
|
||
assert.NoError(t, err) | ||
assert.Equal(t, config.ApiUrl, readConfig.ApiUrl) | ||
assert.Equal(t, config.ApiToken, readConfig.ApiToken) | ||
|
||
os.Remove(path) | ||
} | ||
|
||
func TestConfigJsonRepository_createConfigFile(t *testing.T) { | ||
path := "/tmp/test_config.json" | ||
repo := NewConfigJsonRepository(path) | ||
|
||
err := repo.createConfigFile() | ||
assert.NoError(t, err) | ||
|
||
fileExists := utils.FileExist(path) | ||
assert.NoError(t, fileExists) | ||
|
||
os.Remove(path) | ||
} | ||
|
||
func TestGetDefaultConfigFile(t *testing.T) { | ||
defaultConfig := getDefaultConfigFile() | ||
|
||
workingDir, _ := os.Getwd() | ||
expectedResultFilePath := filepath.Join(workingDir, ".scanoss", "results.json") | ||
expectedScanSettingsFilePath := filepath.Join(workingDir, "scanoss.json") | ||
|
||
assert.Equal(t, "", defaultConfig.ScanRoot) | ||
assert.Equal(t, expectedResultFilePath, defaultConfig.ResultFilePath) | ||
assert.Equal(t, "", defaultConfig.ApiToken) | ||
assert.Equal(t, "https://api.osskb.org", defaultConfig.ApiUrl) | ||
assert.Equal(t, expectedScanSettingsFilePath, defaultConfig.ScanSettingsFilePath) | ||
} |
Oops, something went wrong.