storj/lib/uplinkc/testdata_test.go
Cameron Ayer 6fae361c31 replace planet.Start in tests with planet.Run
planet.Start starts a testplanet system, whereas planet.Run starts a testplanet
and runs a test against it with each DB backend (cockroach compat).

Change-Id: I39c9da26d9619ee69a2b718d24ab00271f9e9bc2
2019-12-10 16:55:54 +00:00

76 lines
1.8 KiB
Go

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package main
import (
"os"
"os/exec"
"path/filepath"
"testing"
"time"
"github.com/stretchr/testify/require"
"storj.io/storj/private/testcontext"
"storj.io/storj/private/testplanet"
)
func TestC(t *testing.T) {
ctx := testcontext.NewWithTimeout(t, 5*time.Minute)
defer ctx.Cleanup()
libuplinkInclude := ctx.CompileShared(t, "uplink", "storj.io/storj/lib/uplinkc")
currentdir, err := os.Getwd()
require.NoError(t, err)
definition := testcontext.Include{
Header: filepath.Join(currentdir, "uplink_definitions.h"),
}
ctests, err := filepath.Glob(filepath.Join("testdata", "*_test.c"))
require.NoError(t, err)
t.Run("ALL", func(t *testing.T) {
for _, ctest := range ctests {
ctest := ctest
testName := filepath.Base(ctest)
t.Run(testName, func(t *testing.T) {
t.Parallel()
testexe := ctx.CompileC(t, testcontext.CompileCOptions{
Dest: testName,
Sources: []string{ctest},
Includes: []testcontext.Include{
libuplinkInclude,
definition,
testcontext.CLibMath,
},
})
testplanet.Run(t, testplanet.Config{
SatelliteCount: 1, StorageNodeCount: 5, UplinkCount: 1,
Reconfigure: testplanet.DisablePeerCAWhitelist,
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
cmd := exec.Command(testexe)
cmd.Dir = filepath.Dir(testexe)
cmd.Env = append(os.Environ(),
"SATELLITE_0_ADDR="+planet.Satellites[0].Addr(),
"GATEWAY_0_API_KEY="+planet.Uplinks[0].APIKey[planet.Satellites[0].ID()].Serialize(),
"TMP_DIR"+ctx.Dir("c_temp"),
)
out, err := cmd.CombinedOutput()
if err != nil {
t.Error(string(out))
t.Fatal(err)
} else {
t.Log(string(out))
}
})
})
}
})
}