-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathrun_test.go
More file actions
52 lines (43 loc) · 1.52 KB
/
run_test.go
File metadata and controls
52 lines (43 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright func-e contributors
// SPDX-License-Identifier: Apache-2.0
package func_e_test
import (
"bytes"
"fmt"
"os"
"os/exec"
"testing"
"github.com/stretchr/testify/require"
func_e "github.com/tetratelabs/func-e"
"github.com/tetratelabs/func-e/api"
"github.com/tetratelabs/func-e/internal"
"github.com/tetratelabs/func-e/internal/run"
"github.com/tetratelabs/func-e/internal/test/build"
)
// TestFuncERun_InvalidConfig takes care to not duplicate test/e2e/testrun.go,
// but still give some coverage.
func TestFuncERun_InvalidConfig(t *testing.T) {
var stdout, stderr bytes.Buffer
err := func_e.Run(t.Context(), []string{},
api.EnvoyVersion("1.0.0"), // intentional invalid to avoid a runtime lookup
api.HomeDir(t.TempDir()), //nolint:staticcheck // intentional use of deprecated API for legacy mode testing
run.EnvoyPath(fakeEnvoyBin),
api.Out(&stdout),
api.EnvoyOut(&stdout),
api.EnvoyErr(&stderr))
var exitErr *exec.ExitError
require.ErrorAs(t, err, &exitErr)
require.Equal(t, 1, exitErr.ExitCode())
require.Contains(t, stdout.String(), fakeEnvoyBin)
require.Contains(t, stderr.String(), "At least one of --config-path or --config-yaml")
}
// fakeEnvoyBin holds a path to the compiled internal.FakeEnvoySrcPath
var fakeEnvoyBin string
func TestMain(m *testing.M) {
var err error
if fakeEnvoyBin, err = build.GoBuild(internal.FakeEnvoySrcPath, os.TempDir()); err != nil {
fmt.Fprintf(os.Stderr, `failed to start api tests due to build error: %v\n`, err) //nolint:errcheck
os.Exit(1)
}
os.Exit(m.Run())
}