2017-12-04 06:30:39 -05:00
|
|
|
package swarm
|
2017-06-20 14:00:01 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
|
2018-03-05 18:53:52 -05:00
|
|
|
"github.com/gotestyourself/gotestyourself/assert"
|
|
|
|
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
2017-06-20 14:00:01 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestLoadBundlefileErrors(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
namespace string
|
|
|
|
path string
|
2017-12-21 16:27:57 -05:00
|
|
|
expectedError string
|
2017-06-20 14:00:01 -04:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
namespace: "namespace_foo",
|
2017-12-21 16:27:57 -05:00
|
|
|
expectedError: "Bundle namespace_foo.dab not found",
|
2017-06-20 14:00:01 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
namespace: "namespace_foo",
|
|
|
|
path: "invalid_path",
|
2017-12-21 16:27:57 -05:00
|
|
|
expectedError: "Bundle invalid_path not found",
|
2017-06-20 14:00:01 -04:00
|
|
|
},
|
2017-12-21 16:27:57 -05:00
|
|
|
// FIXME: this test never working, testdata file is missing from repo
|
|
|
|
//{
|
|
|
|
// namespace: "namespace_foo",
|
|
|
|
// path: string(golden.Get(t, "bundlefile_with_invalid_syntax")),
|
|
|
|
// expectedError: "Error reading",
|
|
|
|
//},
|
2017-06-20 14:00:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
2017-12-04 06:30:39 -05:00
|
|
|
_, err := loadBundlefile(&bytes.Buffer{}, tc.namespace, tc.path)
|
2017-12-21 16:27:57 -05:00
|
|
|
assert.ErrorContains(t, err, tc.expectedError)
|
2017-06-20 14:00:01 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLoadBundlefile(t *testing.T) {
|
|
|
|
buf := new(bytes.Buffer)
|
|
|
|
|
|
|
|
namespace := ""
|
|
|
|
path := filepath.Join("testdata", "bundlefile_with_two_services.dab")
|
2017-12-04 06:30:39 -05:00
|
|
|
bundleFile, err := loadBundlefile(buf, namespace, path)
|
2017-06-20 14:00:01 -04:00
|
|
|
|
2018-03-06 14:44:13 -05:00
|
|
|
assert.NilError(t, err)
|
2018-03-05 18:53:52 -05:00
|
|
|
assert.Check(t, is.Equal(len(bundleFile.Services), 2))
|
2017-06-20 14:00:01 -04:00
|
|
|
}
|