diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..1407050 --- /dev/null +++ b/.github/workflows/test.yml @@ -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 diff --git a/tests/config_test.go b/tests/config_test.go index dd6c397..2320190 100644 --- a/tests/config_test.go +++ b/tests/config_test.go @@ -4,6 +4,8 @@ import ( "bytes" "context" "fmt" + "os" + "path/filepath" "testing" "time" @@ -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" @@ -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(` { @@ -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(` @@ -150,7 +166,7 @@ func TestModuleConfiguration(t *testing.T) { "log_level": "debug" } ] - }`, moduleBinPath) + }`, fullModuleBinPath) // Storage NOT specified config3 := fmt.Sprintf(` @@ -211,7 +227,7 @@ func TestModuleConfiguration(t *testing.T) { "log_level": "debug" } ] - }`, moduleBinPath) + }`, fullModuleBinPath) // size_gb NOT specified config4 := fmt.Sprintf(` @@ -277,7 +293,7 @@ func TestModuleConfiguration(t *testing.T) { "log_level": "debug" } ] - }`, moduleBinPath) + }`, fullModuleBinPath) // cam_props NOT specified config5 := fmt.Sprintf(` @@ -339,7 +355,7 @@ func TestModuleConfiguration(t *testing.T) { "log_level": "debug" } ] - }`, moduleBinPath) + }`, fullModuleBinPath) // dat_manager NOT specified config6 := fmt.Sprintf(` @@ -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) diff --git a/tests/fetch_test.go b/tests/fetch_test.go index cd444f7..343ee45 100644 --- a/tests/fetch_test.go +++ b/tests/fetch_test.go @@ -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(` { @@ -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{}{ diff --git a/tests/save_test.go b/tests/save_test.go index af899e2..dfaa205 100644 --- a/tests/save_test.go +++ b/tests/save_test.go @@ -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(` { @@ -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{}{