2020-04-09 02:00:16 -05:00
|
|
|
package plugins
|
|
|
|
|
|
|
|
import (
|
2020-04-14 08:02:39 -05:00
|
|
|
"strings"
|
2020-04-09 02:00:16 -05:00
|
|
|
"testing"
|
|
|
|
|
2020-04-14 08:02:39 -05:00
|
|
|
"github.com/stretchr/testify/assert"
|
2020-04-09 02:00:16 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestManifestParsing(t *testing.T) {
|
2020-04-14 08:02:39 -05:00
|
|
|
txt := `-----BEGIN PGP SIGNED MESSAGE-----
|
2020-04-09 02:00:16 -05:00
|
|
|
Hash: SHA512
|
|
|
|
|
|
|
|
{
|
2020-04-14 08:02:39 -05:00
|
|
|
"plugin": "grafana-googlesheets-datasource",
|
|
|
|
"version": "1.0.0-dev",
|
2020-04-09 02:00:16 -05:00
|
|
|
"files": {
|
|
|
|
"LICENSE": "7df059597099bb7dcf25d2a9aedfaf4465f72d8d",
|
2020-04-14 08:02:39 -05:00
|
|
|
"README.md": "08ec6d704b6115bef57710f6d7e866c050cb50ee",
|
|
|
|
"gfx_sheets_darwin_amd64": "1b8ae92c6e80e502bb0bf2d0ae9d7223805993ab",
|
|
|
|
"gfx_sheets_linux_amd64": "f39e0cc7344d3186b1052e6d356eecaf54d75b49",
|
|
|
|
"gfx_sheets_windows_amd64.exe": "c8825dfec512c1c235244f7998ee95182f9968de",
|
|
|
|
"module.js": "aaec6f51a995b7b843b843cd14041925274d960d",
|
|
|
|
"module.js.LICENSE.txt": "7f822fe9341af8f82ad1b0c69aba957822a377cf",
|
|
|
|
"module.js.map": "c5a524f5c4237f6ed6a016d43cd46938efeadb45",
|
|
|
|
"plugin.json": "55556b845e91935cc48fae3aa67baf0f22694c3f"
|
2020-04-09 02:00:16 -05:00
|
|
|
},
|
2020-04-14 08:02:39 -05:00
|
|
|
"time": 1586817677115,
|
|
|
|
"keyId": "7e4d0c6a708866e7"
|
2020-04-09 02:00:16 -05:00
|
|
|
}
|
|
|
|
-----BEGIN PGP SIGNATURE-----
|
|
|
|
Version: OpenPGP.js v4.10.1
|
|
|
|
Comment: https://openpgpjs.org
|
|
|
|
|
2020-04-14 08:02:39 -05:00
|
|
|
wqEEARMKAAYFAl6U6o0ACgkQfk0ManCIZuevWAIHSvcxOy1SvvL5gC+HpYyG
|
|
|
|
VbSsUvF2FsCoXUCTQflK6VdJfSPNzm8YdCdx7gNrBdly6HEs06ZaRp44F/ve
|
|
|
|
NR7DnB0CCQHO+4FlSPtXFTzNepoc+CytQyDAeOLMLmf2Tqhk2YShk+G/YlVX
|
|
|
|
74uuP5UXZxwK2YKJovdSknDIU7MhfuvvQIP/og==
|
|
|
|
=hBea
|
|
|
|
-----END PGP SIGNATURE-----`
|
2020-04-09 02:00:16 -05:00
|
|
|
|
2020-04-14 08:02:39 -05:00
|
|
|
t.Run("valid manifest", func(t *testing.T) {
|
2020-04-09 02:00:16 -05:00
|
|
|
manifest, err := readPluginManifest([]byte(txt))
|
|
|
|
|
2020-04-14 08:02:39 -05:00
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.NotNil(t, manifest)
|
|
|
|
assert.Equal(t, manifest.Plugin, "grafana-googlesheets-datasource")
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("invalid manifest", func(t *testing.T) {
|
|
|
|
modified := strings.ReplaceAll(txt, "README.md", "xxxxxxxxxx")
|
|
|
|
manifest, err := readPluginManifest([]byte(modified))
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
assert.Nil(t, manifest)
|
2020-04-09 02:00:16 -05:00
|
|
|
})
|
|
|
|
}
|