Skip to content

Commit

Permalink
adding typescript interfaces for type hinting and testing
Browse files Browse the repository at this point in the history
some code reformatting
adding tests for services and components.
cleanup of unused dependencies in components.
refactor dashboard service so that wrapper is removed before data is passed to component. (no more this.data.data...).
refactored components so that variable names are consistent (dashboardService vs smartService).
ensure argument and return types are specified everywhere.
adding tests for pipes.

adding ng test to ci steps.

change dir before running npm install.

trying to install nodejs in continer.

test frontend separately.

upload coverage for frontend and backend.

upload coverage for frontend and backend.

testing coverage file locations.

retry file upload.
  • Loading branch information
AnalogJ committed Jul 9, 2022
1 parent 0e2fec4 commit b71d666
Show file tree
Hide file tree
Showing 37 changed files with 1,897 additions and 449 deletions.
47 changes: 40 additions & 7 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,25 @@ name: CI
on: [pull_request]

jobs:
test:
name: Test
test-frontend:
name: Test Frontend
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Test Frontend
run: |
make binary-frontend-test-coverage
- name: Upload coverage
uses: actions/upload-artifact@v3
with:
name: coverage
path: ${{ github.workspace }}/webapp/frontend/coverage/lcov.info
retention-days: 1
test-backend:
name: Test Backend
runs-on: ubuntu-latest
container: ghcr.io/packagrio/packagr:latest-golang

# Service containers to run with `build` (Required for end-to-end testing)
services:
influxdb:
Expand All @@ -22,7 +36,6 @@ jobs:
ports:
- 8086:8086
env:
PROJECT_PATH: /go/src/github.com/analogj/scrutiny
STATIC: true
steps:
- name: Git
Expand All @@ -32,16 +45,36 @@ jobs:
git --version
- name: Checkout
uses: actions/checkout@v2
- name: Test
- name: Test Backend
run: |
make binary-clean binary-test-coverage
- name: Generate coverage report
- name: Upload coverage
uses: actions/upload-artifact@v3
with:
name: coverage
path: ${{ github.workspace }}/coverage.txt
retention-days: 1
test-coverage:
name: Test Coverage Upload
needs:
- test-backend
- test-frontend
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Download coverage reports
uses: actions/download-artifact@v3
with:
name: coverage
- name: Upload coverage reports
uses: codecov/codecov-action@v2
with:
files: ${{ github.workspace }}/coverage.txt
files: ${{ github.workspace }}/coverage.txt,${{ github.workspace }}/lcov.info
flags: unittests
fail_ci_if_error: true
verbose: true

build:
name: Build ${{ matrix.cfg.goos }}/${{ matrix.cfg.goarch }}
runs-on: ${{ matrix.cfg.on }}
Expand Down
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ ifneq ($(OS),Windows_NT)
./$(WEB_BINARY_NAME) || true
endif

########################################################################################################################
# Binary
########################################################################################################################

.PHONY: binary-frontend
# reduce logging, disable angular-cli analytics for ci environment
binary-frontend: export NPM_CONFIG_LOGLEVEL = warn
Expand All @@ -100,6 +104,12 @@ binary-frontend:
npm ci
npm run build:prod -- --output-path=$(CURDIR)/dist

.PHONY: binary-frontend-test-coverage
# reduce logging, disable angular-cli analytics for ci environment
binary-frontend-test-coverage:
cd webapp/frontend
npm ci
npx ng test --watch=false --browsers=ChromeHeadless --code-coverage

########################################################################################################################
# Docker
Expand Down
1 change: 1 addition & 0 deletions webapp/backend/pkg/web/handler/get_devices_summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func GetDevicesSummary(c *gin.Context) {
return
}

//this must match DeviceSummaryWrapper (webapp/backend/pkg/models/device_summary.go)
c.JSON(http.StatusOK, gin.H{
"success": true,
"data": map[string]interface{}{
Expand Down
2 changes: 2 additions & 0 deletions webapp/frontend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,5 @@ testem.log
Thumbs.db

/dist

/coverage
4 changes: 2 additions & 2 deletions webapp/frontend/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ module.exports = function (config)
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
dir : require('path').join(__dirname, './coverage/treo'),
reports : ['html', 'lcovonly', 'text-summary'],
dir: require('path').join(__dirname, './coverage'),
reports: ['html', 'lcovonly', 'text-summary'],
fixWebpackSourcePaths: true
},
reporters : ['progress', 'kjhtml'],
Expand Down
18 changes: 12 additions & 6 deletions webapp/frontend/src/app/core/config/app.config.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
import { Layout } from 'app/layout/layout.types';
import {Layout} from 'app/layout/layout.types';

// Theme type
export type Theme = 'light' | 'dark' | 'system';

// Device title to display on the dashboard
export type DashboardDisplay = 'name' | 'serial_id' | 'uuid' | 'label'

export type DashboardSort = 'status' | 'title' | 'age'

export type TemperatureUnit = 'celsius' | 'fahrenheit'

/**
* AppConfig interface. Update this interface to strictly type your config
* object.
*/
export interface AppConfig
{
export interface AppConfig {
theme: Theme;
layout: Layout;

// Dashboard options
dashboardDisplay: string;
dashboardSort: string;
dashboardDisplay: DashboardDisplay;
dashboardSort: DashboardSort;

temperatureUnit: string;
temperatureUnit: TemperatureUnit;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {DeviceModel} from 'app/core/models/device-model';
import {SmartModel} from 'app/core/models/measurements/smart-model';
import {AttributeMetadataModel} from 'app/core/models/thresholds/attribute-metadata-model';

// maps to webapp/backend/pkg/models/device_summary.go
export interface DeviceDetailsResponseWrapper {
success: boolean;
errors?: any[];
data: {
device: DeviceModel;
smart_results: SmartModel[];
},
metadata: { [key: string]: AttributeMetadataModel } | { [key: number]: AttributeMetadataModel };
}
8 changes: 4 additions & 4 deletions webapp/frontend/src/app/core/models/device-model.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// maps to webapp/backend/pkg/models/device.go
export interface DeviceModel {
wwn: string;
device_name: string;
device_uuid: string;
device_serial_id: string;
device_label: string;
device_name?: string;
device_uuid?: string;
device_serial_id?: string;
device_label?: string;

manufacturer: string;
model_name: string;
Expand Down
16 changes: 16 additions & 0 deletions webapp/frontend/src/app/core/models/device-summary-model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {DeviceModel} from 'app/core/models/device-model';
import {SmartTemperatureModel} from 'app/core/models/measurements/smart-temperature-model';

// maps to webapp/backend/pkg/models/device_summary.go
export interface DeviceSummaryModel {
device: DeviceModel;
smart?: SmartSummary;
temp_history?: SmartTemperatureModel[];
}

export interface SmartSummary {
collector_date?: string,
temp?: number
power_on_hours?: number
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {DeviceSummaryModel} from 'app/core/models/device-summary-model';

// maps to webapp/backend/pkg/models/device_summary.go
export interface DeviceSummaryResponseWrapper {
success: boolean;
errors: any[];
data: {
summary: { [key: string]: DeviceSummaryModel }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {SmartTemperatureModel} from './measurements/smart-temperature-model';

export interface DeviceSummaryTempResponseWrapper {
success: boolean;
errors: any[];
data: {
temp_history: { [key: string]: SmartTemperatureModel[]; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// maps to webapp/backend/pkg/models/measurements/smart_ata_attribute.go
// maps to webapp/backend/pkg/models/measurements/smart_nvme_attribute.go
// maps to webapp/backend/pkg/models/measurements/smart_scsi_attribute.go
export interface SmartAttributeModel {
attribute_id: number | string
value: number
thresh: number
worst?: number
raw_value?: number
raw_string?: string
when_failed?: string

transformed_value: number
status: number
status_reason?: string
failure_rate?: number

chartData?: any[]
}
13 changes: 13 additions & 0 deletions webapp/frontend/src/app/core/models/measurements/smart-model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// maps to webapp/backend/pkg/models/measurements/smart.go
import {SmartAttributeModel} from './smart-attribute-model';

export interface SmartModel {
date: string;
device_wwn: string;
device_protocol: string;

temp: number;
power_on_hours: number;
power_cycle_count: number
attrs: { [key: string]: SmartAttributeModel }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// maps to webapp/backend/pkg/models/measurements/smart_temperature.go
export interface SmartTemperatureModel {
date: string;
temp: number;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// map to webapp/backend/pkg/thresholds/ata_attribute_metadata.go
// map to webapp/backend/pkg/thresholds/nvme_attribute_metadata.go
// map to webapp/backend/pkg/thresholds/scsi_attribute_metadata.go
export interface AttributeMetadataModel {
display_name: string
ideal: string
critical: boolean
description: string

transform_value_unit?: string
observed_thresholds?: any[]
display_type: string
}

0 comments on commit b71d666

Please sign in to comment.