-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathe2e.go
86 lines (69 loc) · 2.35 KB
/
e2e.go
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
Copyright 2016 Google
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package remote
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"time"
"github.com/golang/glog"
)
// E2ERemote is type for GCE PD CSI Driver Remote E2E Tests
type E2ERemote struct{}
// InitE2ERemote initializes the GCE PD CSI Driver remote E2E suite
func InitE2ERemote() TestSuite {
return &E2ERemote{}
}
// SetupTestPackage sets up the test package with binaries k8s required for node e2e tests
func (n *E2ERemote) SetupTestPackage(tardir string) error {
// Make sure we can find the newly built binaries
gopath, ok := os.LookupEnv("GOPATH")
if !ok {
return fmt.Errorf("Could not find gopath")
}
// TODO(dyzz): build the gce driver tests instead.
cmd := exec.Command("ginkgo", "build", "test/e2e")
err := cmd.Run()
if err != nil {
return fmt.Errorf("Failed to ginkgo build test: %v", err)
}
cmd = exec.Command("cp", "test/e2e/e2e.test", "bin")
err = cmd.Run()
if err != nil {
return fmt.Errorf("Failed to copy: %v", err)
}
buildOutputDir := filepath.Join(gopath, "src/sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/bin")
// Copy binaries
requiredBins := []string{"e2e.test"}
for _, bin := range requiredBins {
source := filepath.Join(buildOutputDir, bin)
if _, err := os.Stat(source); err != nil {
return fmt.Errorf("failed to locate test binary %s: %v", bin, err)
}
out, err := exec.Command("cp", source, filepath.Join(tardir, bin)).CombinedOutput()
if err != nil {
return fmt.Errorf("failed to copy %q: %v Output: %q", bin, err, out)
}
}
return nil
}
// RunTest runs test on the node.
func (n *E2ERemote) RunTest(host, workspace, results, testArgs, ginkgoArgs string, timeout time.Duration) (string, error) {
glog.V(2).Infof("Starting tests on %q", host)
cmd := getSSHCommand(" && ",
fmt.Sprintf("cd %s", workspace),
fmt.Sprintf("./e2e.test"),
)
return SSH(host, "sh", "-c", cmd)
}