tests/thirdparty: package metadata (#223)

Fetches third-party package metadata from Github.
This commit is contained in:
Michael McLoughlin
2021-11-07 16:13:33 -08:00
committed by GitHub
parent afe2d539b8
commit f355d27b13
9 changed files with 544 additions and 24 deletions

View File

@@ -1,6 +1,8 @@
package thirdparty
import (
"bytes"
"reflect"
"strings"
"testing"
)
@@ -24,35 +26,46 @@ func TestValidateErrors(t *testing.T) {
ErrorSubstring: "missing commands",
},
{
Name: "package_missing_version",
Name: "package_missing_default_branch",
Item: &Package{
Repository: GithubRepository{Owner: "octocat", Name: "hello-world"},
},
ErrorSubstring: "missing default branch",
},
{
Name: "package_missing_version",
Item: &Package{
Repository: GithubRepository{Owner: "octocat", Name: "hello-world"},
DefaultBranch: "main",
},
ErrorSubstring: "missing version",
},
{
Name: "package_missing_module",
Item: &Package{
Repository: GithubRepository{Owner: "octocat", Name: "hello-world"},
Version: "v1.0.1",
Repository: GithubRepository{Owner: "octocat", Name: "hello-world"},
DefaultBranch: "main",
Version: "v1.0.1",
},
ErrorSubstring: "missing module",
},
{
Name: "package_no_generate_commands",
Item: &Package{
Repository: GithubRepository{Owner: "octocat", Name: "hello-world"},
Version: "v1.0.1",
Module: "avo/go.mod",
Repository: GithubRepository{Owner: "octocat", Name: "hello-world"},
DefaultBranch: "main",
Version: "v1.0.1",
Module: "avo/go.mod",
},
ErrorSubstring: "no generate commands",
},
{
Name: "package_invalid_generate_commands",
Item: &Package{
Repository: GithubRepository{Owner: "octocat", Name: "hello-world"},
Version: "v1.0.1",
Module: "avo/go.mod",
Repository: GithubRepository{Owner: "octocat", Name: "hello-world"},
DefaultBranch: "main",
Version: "v1.0.1",
Module: "avo/go.mod",
Generate: []*Step{
{},
},
@@ -66,7 +79,7 @@ func TestValidateErrors(t *testing.T) {
Repository: GithubRepository{Owner: "octocat", Name: "hello-world"},
},
},
ErrorSubstring: "missing version",
ErrorSubstring: "missing default branch",
},
}
for _, c := range cases {
@@ -134,3 +147,26 @@ func TestPackagesFileStepsValid(t *testing.T) {
}
}
}
func TestPackagesFileRoundtrip(t *testing.T) {
pkgs, err := LoadPackagesFile("packages.json")
if err != nil {
t.Fatal(err)
}
// Write and read back.
buf := bytes.NewBuffer(nil)
if err := StorePackages(buf, pkgs); err != nil {
t.Fatal(err)
}
roundtrip, err := LoadPackages(buf)
if err != nil {
t.Fatal(err)
}
// Should be identical.
if !reflect.DeepEqual(pkgs, roundtrip) {
t.Fatal("roundtrip mismatch")
}
}