Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RSDK-8759] - Add tests to CI flow #11

Merged
merged 2 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: test config and do_commands on each commit

on:
push:
branches:
- main
paths:
- '**/**.go'
- 'Makefile'
- '.github/workflows/test.yml'
pull_request:
paths:
- '**/**.go'
- 'Makefile'
- '.github/workflows/test.yml'

jobs:
tests:
runs-on: buildjet-8vcpu-ubuntu-2204-arm
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.21.13
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the correct version post the bugfix we care about?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y libx264-dev git-lfs
- name: Run tests
run: make test
30 changes: 23 additions & 7 deletions tests/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"bytes"
"context"
"fmt"
"os"
"path/filepath"
"testing"
"time"

Expand All @@ -18,7 +20,7 @@ import (
)

const (
moduleBinPath = "/host/bin/linux-arm64/video-store"
moduleBinPath = "bin/linux-arm64/video-store"
videoStoreComponentName = "video-store-1"
testStoragePath = "/tmp/video-storage"
testUploadPath = "/tmp/video-upload"
Expand All @@ -39,7 +41,21 @@ func setupViamServer(ctx context.Context, configStr string) (robot.Robot, error)
return r, nil
}

func getModuleBinPath() (string, error) {
currentDir, err := os.Getwd()
if err != nil {
return "", err
}
fullModuleBinPath := filepath.Join(currentDir, "..", moduleBinPath)
return fullModuleBinPath, nil
}

func TestModuleConfiguration(t *testing.T) {
fullModuleBinPath, err := getModuleBinPath()
if err != nil {
t.Fatalf("Failed to get module binary path: %v", err)
}

// Full configuration
config1 := fmt.Sprintf(`
{
Expand Down Expand Up @@ -105,7 +121,7 @@ func TestModuleConfiguration(t *testing.T) {
"log_level": "debug"
}
]
}`, videoStoreComponentName, testStoragePath, testUploadPath, moduleBinPath)
}`, videoStoreComponentName, testStoragePath, testUploadPath, fullModuleBinPath)

// no camera specified
config2 := fmt.Sprintf(`
Expand Down Expand Up @@ -150,7 +166,7 @@ func TestModuleConfiguration(t *testing.T) {
"log_level": "debug"
}
]
}`, moduleBinPath)
}`, fullModuleBinPath)

// Storage NOT specified
config3 := fmt.Sprintf(`
Expand Down Expand Up @@ -211,7 +227,7 @@ func TestModuleConfiguration(t *testing.T) {
"log_level": "debug"
}
]
}`, moduleBinPath)
}`, fullModuleBinPath)

// size_gb NOT specified
config4 := fmt.Sprintf(`
Expand Down Expand Up @@ -277,7 +293,7 @@ func TestModuleConfiguration(t *testing.T) {
"log_level": "debug"
}
]
}`, moduleBinPath)
}`, fullModuleBinPath)

// cam_props NOT specified
config5 := fmt.Sprintf(`
Expand Down Expand Up @@ -339,7 +355,7 @@ func TestModuleConfiguration(t *testing.T) {
"log_level": "debug"
}
]
}`, moduleBinPath)
}`, fullModuleBinPath)

// dat_manager NOT specified
config6 := fmt.Sprintf(`
Expand Down Expand Up @@ -391,7 +407,7 @@ func TestModuleConfiguration(t *testing.T) {
"log_level": "debug"
}
]
}`, moduleBinPath)
}`, fullModuleBinPath)

t.Run("Valid Configuration Successful", func(t *testing.T) {
timeoutCtx, cancel := context.WithTimeout(context.Background(), time.Minute)
Expand Down
6 changes: 5 additions & 1 deletion tests/fetch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ func TestFetchDoCommand(t *testing.T) {
if err != nil {
t.Fatalf("Failed to get absolute path: %v", err)
}
fullModuleBinPath, err := getModuleBinPath()
if err != nil {
t.Fatalf("Failed to get module bin path: %v", err)
}

config1 := fmt.Sprintf(`
{
Expand Down Expand Up @@ -81,7 +85,7 @@ func TestFetchDoCommand(t *testing.T) {
"log_level": "debug"
}
]
}`, videoStoreComponentName, testUploadPath, storagePath, moduleBinPath)
}`, videoStoreComponentName, testUploadPath, storagePath, fullModuleBinPath)

// Valid time range. Under grpc limit.
fetchCmd1 := map[string]interface{}{
Expand Down
7 changes: 5 additions & 2 deletions tests/save_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ import (
)

func TestSaveDoCommand(t *testing.T) {
// Create absolute path to the test storage dir
storageRelativePath := "./video-storage"
storagePath, err := filepath.Abs(storageRelativePath)
if err != nil {
t.Fatalf("Failed to get absolute path: %v", err)
}
fullModuleBinPath, err := getModuleBinPath()
if err != nil {
t.Fatalf("Failed to get module bin path: %v", err)
}

config1 := fmt.Sprintf(`
{
Expand Down Expand Up @@ -83,7 +86,7 @@ func TestSaveDoCommand(t *testing.T) {
"log_level": "debug"
}
]
}`, videoStoreComponentName, testUploadPath, storagePath, moduleBinPath)
}`, videoStoreComponentName, testUploadPath, storagePath, fullModuleBinPath)

// Valid time range
saveCmd1 := map[string]interface{}{
Expand Down
Loading