-
Notifications
You must be signed in to change notification settings - Fork 0
/
Daggerpipeline_test.go
81 lines (71 loc) · 2.37 KB
/
Daggerpipeline_test.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
package main
import (
"os"
"os/exec"
"strings"
"testing"
)
// Main test function to verify the pipeline
func TestDaggerPipeline(t *testing.T) {
if shouldRunPipeline() {
t.Log("Generated files not found. Running 'go run Daggerpipeline.go' to build the necessary artifacts.")
runDaggerPipeline(t)
} else {
t.Log("Required artifacts already exist. Skipping 'go run Daggerpipeline.go'.")
}
// Always run verification tests regardless of whether we executed the pipeline or not
verifyExecutableBuilds(t)
verifyDockerTarExported(t)
verifyTagNameAndVersion(t)
verifyRunContainerScript(t)
}
// Function to determine whether to run Daggerpipeline.go
func shouldRunPipeline() bool {
// Check if the Docker tar file or the executables exist
_, tarErr := os.Stat("dagger-excuse-deno.tar")
_, linuxErr := os.Stat("excuse-linux")
_, macErr := os.Stat("excuse-mac")
_, winErr := os.Stat("excuse-win.exe")
// If any of the files do not exist, we need to run the pipeline
return os.IsNotExist(tarErr) || os.IsNotExist(linuxErr) || os.IsNotExist(macErr) || os.IsNotExist(winErr)
}
// Function to run Daggerpipeline.go
func runDaggerPipeline(t *testing.T) {
cmd := exec.Command("go", "run", "Daggerpipeline.go")
output, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("Failed to run Daggerpipeline.go: %v\nOutput: %s", err, string(output))
}
}
func verifyExecutableBuilds(t *testing.T) {
executables := []string{"excuse-linux", "excuse-mac", "excuse-win.exe"}
for _, executable := range executables {
if _, err := exec.Command("ls", executable).Output(); err != nil {
t.Errorf("Expected executable %s not found", executable)
}
}
}
func verifyDockerTarExported(t *testing.T) {
tarFileName := "dagger-excuse-deno.tar"
if _, err := os.Stat(tarFileName); os.IsNotExist(err) {
t.Errorf("Expected Docker tar file %s not found", tarFileName)
}
}
func verifyTagNameAndVersion(t *testing.T) {
tagName := "dagger-excuse-deno:latest"
cmd := exec.Command("docker", "inspect", tagName)
output, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("Failed to inspect docker image: %v", err)
}
if !strings.Contains(string(output), tagName) {
t.Errorf("Expected tag name %s not found", tagName)
}
}
func verifyRunContainerScript(t *testing.T) {
cmd := exec.Command("./run-container.sh")
err := cmd.Run()
if err != nil {
t.Errorf("run-container.sh failed to execute: %v", err)
}
}