2017-12-04 06:30:39 -05:00
|
|
|
package swarm
|
2017-06-20 14:00:01 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"fmt"
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestLoadBundlefileErrors(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
namespace string
|
|
|
|
path string
|
|
|
|
expectedError error
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
namespace: "namespace_foo",
|
|
|
|
expectedError: fmt.Errorf("Bundle %s.dab not found", "namespace_foo"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
namespace: "namespace_foo",
|
|
|
|
path: "invalid_path",
|
|
|
|
expectedError: fmt.Errorf("Bundle %s not found", "invalid_path"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
namespace: "namespace_foo",
|
|
|
|
path: filepath.Join("testdata", "bundlefile_with_invalid_syntax"),
|
|
|
|
expectedError: fmt.Errorf("Error reading"),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
2017-12-04 06:30:39 -05:00
|
|
|
_, err := loadBundlefile(&bytes.Buffer{}, tc.namespace, tc.path)
|
2017-06-20 14:00:01 -04:00
|
|
|
assert.Error(t, err, tc.expectedError)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, len(bundleFile.Services), 2)
|
|
|
|
}
|