Skip to content

Commit

Permalink
Merge pull request #11 from viam-modules/RSDK-8759
Browse files Browse the repository at this point in the history
[RSDK-8759] - Add tests to CI flow
  • Loading branch information
seanavery authored Sep 16, 2024
2 parents 59d6ecf + 908deb3 commit c1f7426
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 10 deletions.
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

- 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

0 comments on commit c1f7426

Please sign in to comment.