|
4 | 4 | package main |
5 | 5 |
|
6 | 6 | import ( |
| 7 | + "encoding/json" |
7 | 8 | "fmt" |
8 | | - |
9 | 9 | "io/ioutil" |
10 | 10 | "log" |
11 | 11 | "os" |
12 | 12 | "path/filepath" |
| 13 | + "runtime" |
13 | 14 | "strings" |
14 | 15 | "time" |
15 | 16 |
|
@@ -61,13 +62,15 @@ const ( |
61 | 62 | // Docker registry for porter client container |
62 | 63 | porterRegistry = "ghcr.io/getporter" |
63 | 64 | porterConfigFile = "./tests/integration/operator/testdata/operator_porter_config.yaml" |
| 65 | + |
| 66 | + // The root package name of the plugin repository |
| 67 | + pluginPkg = "get.porter.sh/plugin/kubernetes" |
64 | 68 | ) |
65 | 69 |
|
66 | 70 | // Dirs to watch recursively for build target |
67 | 71 | var ( |
68 | 72 | srcDirs = []string{"cmd/", "pkg/", "go.mod", "magefile.go"} |
69 | 73 | binDir = "bin/plugins/kubernetes/" |
70 | | - pluginPkg = fmt.Sprintf("./cmd/%s", pluginName) |
71 | 74 | supportedClientGOOS = []string{"linux", "darwin", "windows"} |
72 | 75 | // number of nodes for ginkgo parallel test execution (1=sequential) |
73 | 76 | ginkgoNodes = "1" |
@@ -165,6 +168,25 @@ func XBuildAll() { |
165 | 168 | } |
166 | 169 |
|
167 | 170 | releases.PreparePluginForPublish(pluginName) |
| 171 | + verifyVersionStamp() |
| 172 | +} |
| 173 | + |
| 174 | +// verifyVersionStamp checks that the version was set on the cross-compiled binaries |
| 175 | +func verifyVersionStamp() { |
| 176 | + // When this test fails, pluginPkg is set incorrectly or not passed to the releases functions properly |
| 177 | + pluginBinaryPath := filepath.Join(binDir, fmt.Sprintf("dev/kubernetes-%s-amd64", runtime.GOOS)) |
| 178 | + versionOutput, _ := must.OutputV(pluginBinaryPath, "version", "-o=json") |
| 179 | + |
| 180 | + var raw map[string]interface{} |
| 181 | + if err := json.Unmarshal([]byte(versionOutput), &raw); err != nil { |
| 182 | + mgx.Must(fmt.Errorf("error parsing the version command output as json: %w", err)) |
| 183 | + } |
| 184 | + |
| 185 | + meta := releases.LoadMetadata() |
| 186 | + gotVersion := raw["version"].(string) |
| 187 | + if gotVersion != meta.Version { |
| 188 | + mgx.Must(fmt.Errorf("the version was not set correctly on the kubernetes plugin binary %s: expected %q got %q", pluginBinaryPath, meta.Version, gotVersion)) |
| 189 | + } |
168 | 190 | } |
169 | 191 |
|
170 | 192 | // Run local integration tests against the test cluster. |
|
0 commit comments