Add projects
This commit is contained in:
parent
2d3a9ad623
commit
8b607dd700
1802 changed files with 503346 additions and 2 deletions
159
backend/sdk/pluginstore/pluginstore_test.go
Normal file
159
backend/sdk/pluginstore/pluginstore_test.go
Normal file
|
|
@ -0,0 +1,159 @@
|
|||
package pluginstore
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestManifestValidateRequiresPinnedReleaseTag(t *testing.T) {
|
||||
manifest := validTestManifest()
|
||||
manifest.ReleaseTag = ""
|
||||
|
||||
errValidate := manifest.Validate()
|
||||
if errValidate == nil {
|
||||
t.Fatal("Validate() error = nil, want release-tag error")
|
||||
}
|
||||
if !strings.Contains(errValidate.Error(), "release-tag") {
|
||||
t.Fatalf("Validate() error = %v, want release-tag", errValidate)
|
||||
}
|
||||
}
|
||||
|
||||
func TestManifestValidateRejectsReleaseTagVersionMismatch(t *testing.T) {
|
||||
manifest := validTestManifest()
|
||||
manifest.ReleaseTag = "v0.3.0"
|
||||
|
||||
errValidate := manifest.Validate()
|
||||
if errValidate == nil {
|
||||
t.Fatal("Validate() error = nil, want version mismatch")
|
||||
}
|
||||
if !strings.Contains(errValidate.Error(), "resolves version") {
|
||||
t.Fatalf("Validate() error = %v, want version mismatch", errValidate)
|
||||
}
|
||||
}
|
||||
|
||||
func TestManifestFromReleaseBuildsPinnedManifest(t *testing.T) {
|
||||
manifest, errManifest := ManifestFromRelease(
|
||||
DefaultSource(),
|
||||
Plugin{
|
||||
ID: "sample-provider",
|
||||
Name: "Sample Provider",
|
||||
Description: "Adds sample provider support.",
|
||||
Author: "author-name",
|
||||
Repository: "https://github.com/author-name/sample-provider",
|
||||
},
|
||||
Release{TagName: "v0.2.0"},
|
||||
)
|
||||
if errManifest != nil {
|
||||
t.Fatalf("ManifestFromRelease() error = %v", errManifest)
|
||||
}
|
||||
if errValidate := manifest.Validate(); errValidate != nil {
|
||||
t.Fatalf("Validate() error = %v", errValidate)
|
||||
}
|
||||
if manifest.Version != "0.2.0" || manifest.ReleaseTag != "v0.2.0" {
|
||||
t.Fatalf("manifest version fields = %q/%q, want 0.2.0/v0.2.0", manifest.Version, manifest.ReleaseTag)
|
||||
}
|
||||
}
|
||||
|
||||
func TestManifestFromPluginBuildsDirectManifest(t *testing.T) {
|
||||
manifest, errManifest := ManifestFromPlugin(
|
||||
DefaultSource(),
|
||||
Plugin{
|
||||
ID: "sample-provider",
|
||||
Name: "Sample Provider",
|
||||
Description: "Adds sample provider support.",
|
||||
Author: "author-name",
|
||||
Version: "0.4.0",
|
||||
Install: InstallPlan{
|
||||
Type: InstallTypeDirect,
|
||||
Artifacts: []Artifact{{
|
||||
GOOS: "linux",
|
||||
GOARCH: "amd64",
|
||||
URL: "https://downloads.example/sample-provider.zip",
|
||||
SHA256: "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
|
||||
}},
|
||||
},
|
||||
},
|
||||
)
|
||||
if errManifest != nil {
|
||||
t.Fatalf("ManifestFromPlugin() error = %v", errManifest)
|
||||
}
|
||||
if errValidate := manifest.Validate(); errValidate != nil {
|
||||
t.Fatalf("Validate() error = %v", errValidate)
|
||||
}
|
||||
if manifest.SchemaVersion != SchemaVersionV2 || manifest.InstallType() != InstallTypeDirect || manifest.ReleaseTag != "" {
|
||||
t.Fatalf("manifest = %#v, want v2 direct without release tag", manifest)
|
||||
}
|
||||
if manifest.SourceURL != DefaultRegistryURL || len(manifest.Install.Artifacts) != 1 {
|
||||
t.Fatalf("manifest source/artifacts = %q/%d, want source URL and one pinned artifact", manifest.SourceURL, len(manifest.Install.Artifacts))
|
||||
}
|
||||
artifact := manifest.Install.Artifacts[0]
|
||||
if artifact.GOOS != "linux" || artifact.GOARCH != "amd64" || artifact.URL != "https://downloads.example/sample-provider.zip" {
|
||||
t.Fatalf("manifest artifact = %#v, want pinned linux/amd64 artifact", artifact)
|
||||
}
|
||||
}
|
||||
|
||||
func TestManifestFromPluginRejectsArtifactQuery(t *testing.T) {
|
||||
_, errManifest := ManifestFromPlugin(DefaultSource(), Plugin{
|
||||
ID: "sample-provider", Name: "Sample Provider", Description: "Sample", Author: "tester", Version: "1.0.0",
|
||||
Install: InstallPlan{Type: InstallTypeDirect, Artifacts: []Artifact{{
|
||||
GOOS: "linux", GOARCH: "amd64", URL: "https://downloads.example/sample.zip?X-Amz-Signature=secret",
|
||||
SHA256: "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
|
||||
}}},
|
||||
})
|
||||
if errManifest == nil {
|
||||
t.Fatal("ManifestFromPlugin() error = nil, want query rejection")
|
||||
}
|
||||
if strings.Contains(errManifest.Error(), "secret") {
|
||||
t.Fatalf("ManifestFromPlugin() error leaked query value: %v", errManifest)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPluginArtifactsIncludesVersionArtifacts(t *testing.T) {
|
||||
plugin := Plugin{
|
||||
ID: "sample-provider",
|
||||
Name: "Sample Provider",
|
||||
Description: "Adds sample provider support.",
|
||||
Author: "author-name",
|
||||
Version: "0.4.0",
|
||||
Install: InstallPlan{
|
||||
Type: InstallTypeDirect,
|
||||
Artifacts: []Artifact{{
|
||||
GOOS: "windows",
|
||||
GOARCH: "x64",
|
||||
URL: "https://downloads.example/sample-provider.zip",
|
||||
SHA256: "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
|
||||
}},
|
||||
},
|
||||
Versions: []Version{{
|
||||
Version: "0.3.0",
|
||||
Install: InstallPlan{
|
||||
Type: InstallTypeDirect,
|
||||
Artifacts: []Artifact{{
|
||||
GOOS: "linux",
|
||||
GOARCH: "aarch64",
|
||||
URL: "https://downloads.example/sample-provider-0.3.0.zip",
|
||||
SHA256: "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
|
||||
}},
|
||||
},
|
||||
}},
|
||||
}
|
||||
|
||||
artifacts := PluginArtifacts(plugin)
|
||||
if len(artifacts) != 2 ||
|
||||
artifacts[0].GOARCH != "amd64" ||
|
||||
artifacts[1].GOARCH != "arm64" {
|
||||
t.Fatalf("PluginArtifacts() = %#v, want normalized top-level and version artifacts", artifacts)
|
||||
}
|
||||
}
|
||||
|
||||
func validTestManifest() Manifest {
|
||||
return Manifest{
|
||||
ID: "sample-provider",
|
||||
Name: "Sample Provider",
|
||||
Description: "Adds sample provider support.",
|
||||
Author: "author-name",
|
||||
Version: "0.2.0",
|
||||
ReleaseTag: "v0.2.0",
|
||||
Repository: "https://github.com/author-name/sample-provider",
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue