-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain_smoke_test.go
More file actions
140 lines (128 loc) · 3.89 KB
/
Copy pathmain_smoke_test.go
File metadata and controls
140 lines (128 loc) · 3.89 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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package main
import (
"encoding/json"
"path/filepath"
"testing"
"github.com/grafana/plugin-ci-workflows/tests/act/internal/act"
"github.com/grafana/plugin-ci-workflows/tests/act/internal/workflow"
"github.com/grafana/plugin-ci-workflows/tests/act/internal/workflow/ci"
"github.com/stretchr/testify/require"
)
type testAndBuildOutput struct {
ID string `json:"id"`
Version string `json:"version"`
HasBackend string `json:"has-backend"`
Executable string `json:"executable"`
}
func TestSmoke(t *testing.T) {
type cas struct {
folder string
exp testAndBuildOutput
}
for _, tc := range []cas{
{
folder: "simple-frontend",
exp: testAndBuildOutput{
ID: "grafana-simplefrontend-panel",
Version: "1.0.0",
HasBackend: "false",
Executable: "null",
},
},
{
folder: "simple-frontend-yarn",
exp: testAndBuildOutput{
ID: "grafana-simplefrontendyarn-panel",
Version: "1.0.0",
HasBackend: "false",
Executable: "null",
},
},
{
folder: "simple-frontend-pnpm",
exp: testAndBuildOutput{
ID: "grafana-simplefrontendpnpm-panel",
Version: "1.0.0",
HasBackend: "false",
Executable: "null",
},
},
{
folder: "simple-backend",
exp: testAndBuildOutput{
ID: "grafana-simplebackend-datasource",
Version: "1.0.0",
HasBackend: "true",
Executable: "gpx_simple_backend",
},
},
} {
t.Run(tc.folder, func(t *testing.T) {
t.Parallel()
runner, err := act.NewRunner(t)
require.NoError(t, err)
wf, err := ci.NewWorkflow(
ci.WithWorkflowInputs(ci.WorkflowInputs{
PluginDirectory: workflow.Input(filepath.Join("tests", tc.folder)),
DistArtifactsPrefix: workflow.Input(tc.folder + "-"),
RunPlaywright: workflow.Input(false),
}),
)
require.NoError(t, err)
r, err := runner.Run(wf, act.NewPushEventPayload("main"))
require.NoError(t, err)
require.True(t, r.Success, "workflow should succeed")
// Assert outputs
var pluginOutput testAndBuildOutput
rawOutput, ok := r.Outputs.Get("test-and-build", "outputs", "plugin")
require.True(t, ok, "plugin output should be present")
err = json.Unmarshal([]byte(rawOutput), &pluginOutput)
require.NoError(t, err, "unmarshal plugin output JSON")
require.Equal(t, tc.exp, pluginOutput)
// Sanity check the artifacts content (plugin ZIP files)
hasBackend := tc.exp.HasBackend == "true"
runID, err := r.GetTestingWorkflowRunID()
require.NoError(t, err)
distArtifacts, err := runner.ArtifactsStorage.GetFolder(runID, tc.folder+"-dist-artifacts")
require.NoError(t, err)
t.Cleanup(func() { require.NoError(t, distArtifacts.Close()) })
anyZipFn := anyZipFileName(tc.exp.ID, tc.exp.Version)
expFns := []string{
anyZipFn,
anyZipFn + ".md5",
anyZipFn + ".sha1",
}
if hasBackend {
// Additional zips for os/arch combos
for _, osArch := range osArchCombos {
osArchFn := osArchZipFileName(tc.exp.ID, tc.exp.Version, osArch)
expFns = append(expFns, osArchFn, osArchFn+".md5", osArchFn+".sha1")
}
}
require.NoError(t, checkFilesExist(distArtifacts.Fs, expFns, checkFilesExistOptions{strict: true}))
// Sanity check the content of the "any" zip file
zfs, err := distArtifacts.OpenZIP(anyZipFn)
require.NoError(t, err)
require.NoError(t, checkFilesExist(zfs, []string{
filepath.Join(tc.exp.ID, "plugin.json"),
filepath.Join(tc.exp.ID, "module.js"),
}))
if hasBackend {
for _, osArch := range osArchCombos {
osArchFnSuffix := osArch.String()
if osArch.os == "windows" {
osArchFnSuffix += ".exe"
}
require.NoError(t, checkFilesExist(zfs, []string{
filepath.Join(tc.exp.ID, tc.exp.Executable+"_"+osArchFnSuffix),
}))
}
}
require.NoError(
t,
checkFilesDontExist(zfs, []string{filepath.Join(tc.exp.ID, "MANIFEST.txt")}),
"plugin should not be signed",
)
})
}
}