зеркало из https://github.com/microsoft/abstrakt.git
Updated tests to use asserts.
This commit is contained in:
Родитель
a5b3cea457
Коммит
ae85792efe
|
@ -2,6 +2,7 @@ package cmd
|
|||
|
||||
import (
|
||||
"github.com/microsoft/abstrakt/internal/tools/helpers"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
@ -12,10 +13,7 @@ func TestComposeCommandReturnsErrorIfTemplateTypeIsInvalid(t *testing.T) {
|
|||
defer helpers.CleanTempTestFiles(t, tdir)
|
||||
|
||||
output, err := helpers.ExecuteCommand(newComposeCmd().cmd, "test-compose-cmd-returns-error-if-template-type-is-invalid", "-f", constellationPath, "-m", mapsPath, "-t", templateType, "-o", tdir)
|
||||
|
||||
if err == nil {
|
||||
t.Errorf("Did not received expected error. \nGot:\n %v", output)
|
||||
}
|
||||
assert.Errorf(t, err, "Did not received expected error. \nGot:\n %v", output)
|
||||
}
|
||||
|
||||
func TestComposeCommandDoesNotErrorIfTemplateTypeIsEmptyOrHelm(t *testing.T) {
|
||||
|
@ -25,33 +23,24 @@ func TestComposeCommandDoesNotErrorIfTemplateTypeIsEmptyOrHelm(t *testing.T) {
|
|||
defer helpers.CleanTempTestFiles(t, tdir)
|
||||
|
||||
output, err := helpers.ExecuteCommand(newComposeCmd().cmd, "test-compose-cmd-does-not-error-if-template-type-is-empty-or-helm", "-f", constellationPath, "-m", mapsPath, "-t", templateType, "-o", tdir)
|
||||
assert.NoErrorf(t, err, "Did not expect error:\n %v\n output: %v", err, output)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("Did not expect error:\n %v\n output: %v", err, output)
|
||||
}
|
||||
templateType = "helm"
|
||||
output, err = helpers.ExecuteCommand(newComposeCmd().cmd, "test-compose-cmd-does-not-error-if-template-type-is-empty-or-helm", "-f", constellationPath, "-m", mapsPath, "-t", templateType, "-o", tdir)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("Did not expect error:\n %v\n output: %v", err, output)
|
||||
}
|
||||
output, err = helpers.ExecuteCommand(newComposeCmd().cmd, "test-compose-cmd-does-not-error-if-template-type-is-empty-or-helm", "-f", constellationPath, "-m", mapsPath, "-t", templateType, "-o", tdir)
|
||||
assert.NoErrorf(t, err, "Did not expect error:\n %v\n output: %v", err, output)
|
||||
}
|
||||
|
||||
func TestComposeCommandReturnsErrorWithInvalidFilePaths(t *testing.T) {
|
||||
output, err := helpers.ExecuteCommand(newComposeCmd().cmd, "test-compose-cmd-returns-error-with-invalid-files", "-f", "invalid", "-m", "invalid", "-o", "invalid")
|
||||
|
||||
if err == nil {
|
||||
t.Errorf("Did not received expected error. \nGot:\n %v", output)
|
||||
}
|
||||
assert.Errorf(t, err, "Did not received expected error. \nGot:\n %v", output)
|
||||
}
|
||||
|
||||
// TODO bug #43: figure out how to make this test work reliably.
|
||||
// Something weird is making this test fail when run along with other tests in the package.
|
||||
// It passes whenever it runs on it's own.
|
||||
func TestComposeCmdVerifyRequiredFlags(t *testing.T) {
|
||||
expected := "required flag(s) \"constellationFilePath\", \"mapsFilePath\", \"outputPath\" not set"
|
||||
|
||||
output, err := helpers.ExecuteCommand(newComposeCmd().cmd, "")
|
||||
|
||||
if err != nil {
|
||||
helpers.CheckStringContains(t, err.Error(), expected)
|
||||
} else {
|
||||
|
@ -65,9 +54,7 @@ func TestComposeCmdWithValidFlags(t *testing.T) {
|
|||
defer helpers.CleanTempTestFiles(t, tdir)
|
||||
|
||||
output, err := helpers.ExecuteCommand(newComposeCmd().cmd, "test-compose-cmd-with-flags", "-f", constellationPath, "-m", mapsPath, "-o", tdir)
|
||||
if err != nil {
|
||||
t.Errorf("error: \n %v\noutput:\n %v\n", err, output)
|
||||
}
|
||||
assert.NoErrorf(t, err, "error: \n %v\noutput:\n %v\n", err, output)
|
||||
}
|
||||
|
||||
func TestComposeWithRealFiles(t *testing.T) {
|
||||
|
@ -76,8 +63,5 @@ func TestComposeWithRealFiles(t *testing.T) {
|
|||
defer helpers.CleanTempTestFiles(t, tdir)
|
||||
|
||||
output, err := helpers.ExecuteCommand(newComposeCmd().cmd, "test-compose-cmd-with-real-files", "-f", constellationPath, "-m", mapsPath, "-o", tdir)
|
||||
if err != nil {
|
||||
t.Errorf("error: \n %v\noutput:\n %v\n", err, output)
|
||||
}
|
||||
|
||||
assert.NoErrorf(t, err, "error: \n %v\noutput:\n %v\n", err, output)
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
set "github.com/deckarep/golang-set"
|
||||
"github.com/microsoft/abstrakt/internal/platform/constellation"
|
||||
"github.com/microsoft/abstrakt/internal/tools/helpers"
|
||||
"github.com/sirupsen/logrus/hooks/test"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
|
@ -20,15 +20,10 @@ func TestDiffCmdWithAllRequirementsNoError(t *testing.T) {
|
|||
hook := test.NewGlobal()
|
||||
_, err := helpers.ExecuteCommand(newDiffCmd().cmd, "-o", constellationPathOrg, "-n", constellationPathNew)
|
||||
|
||||
// fmt.Println(hook.LastEntry().Message)
|
||||
// fmt.Println(testDiffComparisonOutputString)
|
||||
|
||||
if err != nil {
|
||||
t.Error("Did not receive output")
|
||||
} else {
|
||||
if !helpers.CompareGraphOutputAsSets(testDiffComparisonOutputString, hook.LastEntry().Message) {
|
||||
t.Errorf("Expcted output and produced output do not match : expected %s produced %s", testDiffComparisonOutputString, hook.LastEntry().Message)
|
||||
}
|
||||
assert.Truef(t, helpers.CompareGraphOutputAsSets(testDiffComparisonOutputString, hook.LastEntry().Message), "Expcted output and produced output do not match : expected %s produced %s", testDiffComparisonOutputString, hook.LastEntry().Message)
|
||||
// Did use this initially but wont work with the strongs output from the graphviz library as the sequence of entries in the output can change
|
||||
// while the sequence may change the result is still valid and the same so am usinga local comparison function to get around this problem
|
||||
// checkStringContains(t, hook.LastEntry().Message, testDiffComparisonOutputString)
|
||||
|
@ -54,8 +49,6 @@ func localPrepareRealFilesForTest(t *testing.T) (string, string, string, string)
|
|||
t.Fatal(err2)
|
||||
}
|
||||
|
||||
fmt.Print(cwd)
|
||||
|
||||
constellationPathOrg := path.Join(cwd, "../sample/constellation/sample_constellation.yaml")
|
||||
constellationPathNew := path.Join(cwd, "../sample/constellation/sample_constellation_changed.yaml")
|
||||
mapsPath := path.Join(cwd, "../sample/constellation/sample_constellation_maps.yaml")
|
||||
|
@ -116,15 +109,11 @@ func TestGetComparisonSets(t *testing.T) {
|
|||
|
||||
dsGraphOrg := new(constellation.Config)
|
||||
err := dsGraphOrg.LoadString(testOrgDagStr)
|
||||
if err != nil {
|
||||
t.Errorf("dagConfigService failed to load dag from test string %s", err)
|
||||
}
|
||||
assert.NoErrorf(t, err, "dagConfigService failed to load dag from test string %s", err)
|
||||
|
||||
dsGraphNew := new(constellation.Config)
|
||||
err = dsGraphNew.LoadString(testNewDagStr)
|
||||
if err != nil {
|
||||
t.Errorf("dagConfigService failed to load file %s", err)
|
||||
}
|
||||
assert.NoErrorf(t, err, "dagConfigService failed to load file %s", err)
|
||||
|
||||
//construct sets struct for loaded constellation
|
||||
loadedSets := &setsForComparison{}
|
||||
|
@ -136,30 +125,12 @@ func TestGetComparisonSets(t *testing.T) {
|
|||
// function being tested
|
||||
fillComparisonSets(dsGraphOrg, dsGraphNew, loadedSets)
|
||||
|
||||
if !knownSets.setCommonSvcs.Equal(loadedSets.setCommonSvcs) {
|
||||
t.Errorf("Common services - did not match between expected result and input yaml")
|
||||
}
|
||||
|
||||
if !knownSets.setCommonRels.Equal(loadedSets.setCommonRels) {
|
||||
t.Errorf("Common relationships - did not match between expected result and input yaml")
|
||||
}
|
||||
|
||||
if !knownSets.setAddedSvcs.Equal(loadedSets.setAddedSvcs) {
|
||||
t.Errorf("Added services - did not match between expected result and input yaml")
|
||||
}
|
||||
|
||||
if !knownSets.setAddedRels.Equal(loadedSets.setAddedRels) {
|
||||
t.Errorf("Added relationships - did not match between expected result and input yaml")
|
||||
}
|
||||
|
||||
if !knownSets.setDelSvcs.Equal(loadedSets.setDelSvcs) {
|
||||
t.Errorf("Deleted services - did not match between expected result and input yaml")
|
||||
}
|
||||
|
||||
if !knownSets.setDelRels.Equal(loadedSets.setDelRels) {
|
||||
t.Errorf("Deleted relationships - did not match between expected result and input yaml")
|
||||
}
|
||||
|
||||
assert.True(t, knownSets.setCommonSvcs.Equal(loadedSets.setCommonSvcs), "Common services - did not match between expected result and input yaml")
|
||||
assert.True(t, knownSets.setCommonRels.Equal(loadedSets.setCommonRels), "Common relationships - did not match between expected result and input yaml")
|
||||
assert.True(t, knownSets.setAddedSvcs.Equal(loadedSets.setAddedSvcs), "Added services - did not match between expected result and input yaml")
|
||||
assert.True(t, knownSets.setAddedRels.Equal(loadedSets.setAddedRels), "Added relationships - did not match between expected result and input yaml")
|
||||
assert.True(t, knownSets.setDelSvcs.Equal(loadedSets.setDelSvcs), "Deleted services - did not match between expected result and input yaml")
|
||||
assert.True(t, knownSets.setDelRels.Equal(loadedSets.setDelRels), "Deleted relationships - did not match between expected result and input yaml")
|
||||
}
|
||||
|
||||
// testGraphWithChanges - test diff comparison function
|
||||
|
@ -173,9 +144,7 @@ func TestGraphWithChanges(t *testing.T) {
|
|||
|
||||
dsGraphNew := new(constellation.Config)
|
||||
err = dsGraphNew.LoadString(testNewDagStr)
|
||||
if err != nil {
|
||||
t.Errorf("dagConfigService failed to load file %s", err)
|
||||
}
|
||||
assert.NoErrorf(t, err, "dagConfigService failed to load file %s", err)
|
||||
|
||||
//construct sets struct for loaded constellation
|
||||
loadedSets := &setsForComparison{}
|
||||
|
@ -185,9 +154,7 @@ func TestGraphWithChanges(t *testing.T) {
|
|||
|
||||
resString := createGraphWithChanges(dsGraphNew, loadedSets)
|
||||
|
||||
if !helpers.CompareGraphOutputAsSets(testDiffComparisonOutputString, resString) {
|
||||
t.Errorf("Resulting output does not match the reference comparison input \n RESULT \n%s EXPECTED \n%s", resString, testDiffComparisonOutputString)
|
||||
}
|
||||
assert.Truef(t, helpers.CompareGraphOutputAsSets(testDiffComparisonOutputString, resString), "Resulting output does not match the reference comparison input \n RESULT \n%s EXPECTED \n%s", resString, testDiffComparisonOutputString)
|
||||
}
|
||||
|
||||
// Utility to populate comparison sets with expected/known result
|
||||
|
@ -215,7 +182,6 @@ func populateComparisonSets(target *setsForComparison) {
|
|||
target.setDelRels = set.NewSet()
|
||||
target.setDelRels.Add("9e1bcb3d-ff58-41d4-8779-f71e7b8800f8" + "|" + "3aa1e546-1ed5-4d67-a59c-be0d5905b490")
|
||||
target.setDelRels.Add("3aa1e546-1ed5-4d67-a59c-be0d5905b490" + "|" + "a268fae5-2a82-4a3e-ada7-a52eeb7019ac")
|
||||
|
||||
}
|
||||
|
||||
// Sample DAG file data - original file
|
||||
|
|
|
@ -2,6 +2,7 @@ package cmd
|
|||
|
||||
import (
|
||||
"github.com/microsoft/abstrakt/internal/tools/helpers"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
@ -14,9 +15,7 @@ func TestValidateCommand(t *testing.T) {
|
|||
|
||||
output, err := helpers.ExecuteCommand(newValidateCmd().cmd, "-f", constellationPath)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("Did not received expected error. \nGot:\n %v", output)
|
||||
}
|
||||
assert.NoErrorf(t, err, "Did not received expected error. \nGot:\n %v", output)
|
||||
|
||||
_, err = helpers.ExecuteCommand(newValidateCmd().cmd, "-f", "does-not-exist")
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package cmd
|
|||
import (
|
||||
"github.com/microsoft/abstrakt/internal/tools/helpers"
|
||||
"github.com/sirupsen/logrus/hooks/test"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
@ -16,10 +17,7 @@ func TestMain(m *testing.M) {
|
|||
func TestVersion(t *testing.T) {
|
||||
expected := "0.0.1"
|
||||
version := Version()
|
||||
|
||||
if version != expected {
|
||||
t.Errorf("Did not find correct abstrakt version. Expected %v, got %v", expected, version)
|
||||
}
|
||||
assert.Equal(t, expected, version)
|
||||
}
|
||||
|
||||
func TestVersionCmd(t *testing.T) {
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/microsoft/abstrakt/internal/platform/constellation"
|
||||
"github.com/microsoft/abstrakt/internal/tools/helpers"
|
||||
"github.com/sirupsen/logrus/hooks/test"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
@ -22,9 +22,7 @@ func TestVisualiseCmdWithAllRequirementsNoError(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Error("Did not receive output")
|
||||
} else {
|
||||
if !helpers.CompareGraphOutputAsSets(validGraphString, hook.LastEntry().Message) {
|
||||
t.Errorf("Expcted output and produced output do not match : expected %s produced %s", validGraphString, hook.LastEntry().Message)
|
||||
}
|
||||
assert.Truef(t, helpers.CompareGraphOutputAsSets(validGraphString, hook.LastEntry().Message), "Expcted output and produced output do not match : expected %s produced %s", validGraphString, hook.LastEntry().Message)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -65,22 +63,15 @@ func TestFileExists(t *testing.T) {
|
|||
|
||||
//Create a file to test against
|
||||
err := ioutil.WriteFile(testValidFilename, testData, 0644)
|
||||
if err != nil {
|
||||
fmt.Println("Could not create output testing file, cannot proceed")
|
||||
t.Error(err)
|
||||
}
|
||||
assert.NoError(t, err, "Could not create output testing file, cannot proceed")
|
||||
|
||||
//Test that a valid file (created above) can be seen
|
||||
var result bool = helpers.FileExists(testValidFilename) //Expecting true - file does exists
|
||||
if result == false {
|
||||
t.Errorf("Test file does exist but testFile returns that it does not")
|
||||
}
|
||||
assert.True(t, result, "Test file does exist but testFile returns that it does not")
|
||||
|
||||
//Test that an invalid file (does not exist) is not seen
|
||||
result = helpers.FileExists(testInvalidFilename) //Expecting false - file does not exist
|
||||
if result != false {
|
||||
t.Errorf("Test file does not exist but testFile says it does")
|
||||
}
|
||||
assert.False(t, result, "Test file does not exist but testFile says it does")
|
||||
|
||||
err = os.Remove(testValidFilename)
|
||||
if err != nil {
|
||||
|
@ -88,10 +79,7 @@ func TestFileExists(t *testing.T) {
|
|||
}
|
||||
|
||||
result = helpers.FileExists(testValidFilename) //Expecting false - file has been removed
|
||||
if result == true {
|
||||
t.Errorf("Test file has been removed but fileExists is finding it")
|
||||
}
|
||||
|
||||
assert.False(t, result, "Test file has been removed but fileExists is finding it")
|
||||
}
|
||||
|
||||
func TestParseYaml(t *testing.T) {
|
||||
|
@ -108,7 +96,6 @@ func TestParseYaml(t *testing.T) {
|
|||
len(retConfig.Relationships) != 1 {
|
||||
t.Errorf("YAML did not parse correctly and it should have")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Sample DAG file data
|
||||
|
|
1
go.mod
1
go.mod
|
@ -19,6 +19,7 @@ require (
|
|||
github.com/spf13/cobra v0.0.5
|
||||
github.com/spf13/jwalterweatherman v1.1.0 // indirect
|
||||
github.com/spf13/viper v1.4.0
|
||||
github.com/stretchr/testify v1.4.0
|
||||
golang.org/x/crypto v0.0.0-20191028145041-f83a4685e152
|
||||
golang.org/x/sys v0.0.0-20191112214154-59a1497f0cea // indirect
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
|
||||
|
|
|
@ -3,7 +3,7 @@ package compose
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/microsoft/abstrakt/internal/chart"
|
||||
"github.com/microsoft/abstrakt/internal/platform/chart"
|
||||
"github.com/microsoft/abstrakt/internal/platform/constellation"
|
||||
"github.com/microsoft/abstrakt/internal/platform/mapper"
|
||||
helm "helm.sh/helm/v3/pkg/chart"
|
||||
|
|
|
@ -3,6 +3,7 @@ package compose_test
|
|||
import (
|
||||
"fmt"
|
||||
"github.com/microsoft/abstrakt/internal/compose"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"helm.sh/helm/v3/pkg/chart"
|
||||
"helm.sh/helm/v3/pkg/chart/loader"
|
||||
"helm.sh/helm/v3/pkg/chartutil"
|
||||
|
@ -28,17 +29,13 @@ func TestComposeService(t *testing.T) {
|
|||
comp := new(compose.Composer)
|
||||
_, err = comp.Build("test", tdir)
|
||||
|
||||
if err == nil {
|
||||
t.Errorf("Compose should fail if not yet loaded")
|
||||
}
|
||||
assert.NoError(t, err, "Compose should fail if not yet loaded")
|
||||
|
||||
_ = comp.LoadString(test01DagStr, configMapTest01String)
|
||||
|
||||
h, err := comp.Build("test", tdir)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("Compose should have loaded")
|
||||
}
|
||||
assert.NoError(t, err, "Compose should have loaded")
|
||||
|
||||
_ = chartutil.SaveDir(h, tdir)
|
||||
h, _ = loader.LoadDir(tdir)
|
||||
|
@ -74,9 +71,7 @@ func TestHelmLibCompose(t *testing.T) {
|
|||
t.Fatalf("Failed to load newly created chart %q: %s", c, err)
|
||||
}
|
||||
|
||||
if mychart.Name() != "foo" {
|
||||
t.Errorf("Expected name to be 'foo', got %q", mychart.Name())
|
||||
}
|
||||
assert.Equalf(t, "foo", mychart.Name(), "Expected name to be 'foo', got %q", mychart.Name())
|
||||
|
||||
for _, f := range []string{
|
||||
chartutil.ChartfileName,
|
||||
|
@ -113,21 +108,15 @@ func TestHelmLibCompose(t *testing.T) {
|
|||
|
||||
func TestLoadFromString(t *testing.T) {
|
||||
comp := new(compose.Composer)
|
||||
err := comp.LoadString(test01DagStr, configMapTest01String)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("Error: %v", err)
|
||||
}
|
||||
err := comp.LoadString(test01DagStr, configMapTest01String)
|
||||
assert.NoErrorf(t, err, "Error: %v", err)
|
||||
|
||||
err = comp.LoadString("sfdsd", configMapTest01String)
|
||||
if err == nil {
|
||||
t.Errorf("Didn't get error when should")
|
||||
}
|
||||
assert.Error(t, err, "Didn't get error when should")
|
||||
|
||||
err = comp.LoadString(test01DagStr, "sdfsdf")
|
||||
if err == nil {
|
||||
t.Errorf("Didn't get error when should")
|
||||
}
|
||||
assert.Error(t, err, "Didn't get error when should")
|
||||
}
|
||||
|
||||
const test01DagStr = `Name: "Azure Event Hubs Sample"
|
||||
|
|
|
@ -3,6 +3,7 @@ package constellation_test
|
|||
import (
|
||||
"github.com/microsoft/abstrakt/internal/platform/constellation"
|
||||
"github.com/microsoft/abstrakt/internal/tools/guid"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"io/ioutil"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
@ -37,9 +38,7 @@ func TestNewDagConfigFromString(t *testing.T) {
|
|||
t.Errorf("LoadDagConfigFromString() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
if !reflect.DeepEqual(dag, tt.wantRet) {
|
||||
t.Errorf("LoadDagConfigFromString() =\n%#v,\nWant:\n%#v\n", dag, tt.wantRet)
|
||||
}
|
||||
assert.Truef(t, reflect.DeepEqual(dag, tt.wantRet), "LoadDagConfigFromString() =\n%#v,\nWant:\n%#v\n", dag, tt.wantRet)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package constellation_test
|
|||
|
||||
import (
|
||||
"github.com/microsoft/abstrakt/internal/platform/constellation"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
@ -11,9 +12,7 @@ func TestRelationshipFinding(t *testing.T) {
|
|||
rel1 := dag.FindRelationshipByFromName("Event Generator")
|
||||
rel2 := dag.FindRelationshipByToName("Azure Event Hub")
|
||||
|
||||
if rel1[0].From != rel2[0].From || rel1[0].To != rel2[0].To {
|
||||
t.Error("Relationships were not correctly resolved")
|
||||
}
|
||||
assert.Condition(t, func() bool { return !(rel1[0].From != rel2[0].From || rel1[0].To != rel2[0].To) }, "Relationships were not correctly resolved")
|
||||
}
|
||||
|
||||
func TestMultipleInstanceInRelationships(t *testing.T) {
|
||||
|
@ -32,11 +31,6 @@ func TestMultipleInstanceInRelationships(t *testing.T) {
|
|||
from := dag.FindRelationshipByFromName("Event Generator")
|
||||
to := dag.FindRelationshipByToName("Event Logger")
|
||||
|
||||
if len(from) != 2 {
|
||||
t.Error("Event Generator did not have the correct number of `From` relationships")
|
||||
}
|
||||
|
||||
if len(to) != 2 {
|
||||
t.Error("Event Logger did not have the correct number of `To` relationships")
|
||||
}
|
||||
assert.EqualValues(t, 2, len(from), "Event Generator did not have the correct number of `From` relationships")
|
||||
assert.EqualValues(t, 2, len(to), "Event Logger did not have the correct number of `To` relationships")
|
||||
}
|
||||
|
|
|
@ -3,8 +3,8 @@ package constellation
|
|||
import (
|
||||
"fmt"
|
||||
"github.com/awalterschulze/gographviz"
|
||||
"strings"
|
||||
"io"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// GenerateGraph - function to take a dagconfigService structure and create a graph object that contains the
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"bytes"
|
||||
"github.com/microsoft/abstrakt/internal/platform/constellation"
|
||||
"github.com/microsoft/abstrakt/internal/tools/helpers"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
@ -11,6 +12,9 @@ func TestGenerateGraph(t *testing.T) {
|
|||
|
||||
retConfig := new(constellation.Config)
|
||||
err := retConfig.LoadFile("testdata/valid.yaml")
|
||||
|
||||
assert.NoError(t, err)
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -20,14 +24,8 @@ func TestGenerateGraph(t *testing.T) {
|
|||
cmpString := test02ConstGraphString
|
||||
retString, err := retConfig.GenerateGraph(out)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("Should not recieve error: %v", err)
|
||||
}
|
||||
|
||||
if !helpers.CompareGraphOutputAsSets(cmpString, retString) {
|
||||
t.Errorf("Input graph did not generate expected output graphviz representation")
|
||||
t.Errorf("Expected:\n%v \nGot:\n%v", cmpString, retString)
|
||||
}
|
||||
assert.NoErrorf(t, err, "Should not recieve error: %v", err)
|
||||
assert.True(t, helpers.CompareGraphOutputAsSets(cmpString, retString), "Input graph did not generate expected output graphviz representation\nExpected:\n%v \nGot:\n%v", cmpString, retString)
|
||||
}
|
||||
|
||||
const test02ConstGraphString = `digraph Azure_Event_Hubs_Sample {
|
||||
|
|
|
@ -2,6 +2,7 @@ package constellation_test
|
|||
|
||||
import (
|
||||
"github.com/microsoft/abstrakt/internal/platform/constellation"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
@ -11,9 +12,7 @@ func TestForDuplicatIDsInServices(t *testing.T) {
|
|||
|
||||
duplicates := testData.CheckDuplicates()
|
||||
|
||||
if duplicates != nil {
|
||||
t.Error("No duplicates should be found.")
|
||||
}
|
||||
assert.Nil(t, duplicates, "No duplicates should be found.")
|
||||
}
|
||||
|
||||
func TestServicesExists(t *testing.T) {
|
||||
|
@ -22,9 +21,7 @@ func TestServicesExists(t *testing.T) {
|
|||
|
||||
missing := testData.CheckServiceExists()
|
||||
|
||||
if len(missing) != 0 {
|
||||
t.Error("No missing services should be found.")
|
||||
}
|
||||
assert.Empty(t, missing, "No missing services should be found.")
|
||||
}
|
||||
|
||||
func TestSchemaChecks(t *testing.T) {
|
||||
|
@ -33,9 +30,7 @@ func TestSchemaChecks(t *testing.T) {
|
|||
|
||||
err := testData.ValidateModel()
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("Model validation should not return errors: %v", err.Error())
|
||||
}
|
||||
assert.NoError(t, err, "Model validation should not return errors")
|
||||
}
|
||||
|
||||
func TestForDuplicatIDsInServicesFail(t *testing.T) {
|
||||
|
@ -44,9 +39,8 @@ func TestForDuplicatIDsInServicesFail(t *testing.T) {
|
|||
|
||||
duplicates := testData.CheckDuplicates()
|
||||
|
||||
if duplicates == nil {
|
||||
t.Errorf("There should be %v duplicate IDs found", len(testData.Services))
|
||||
}
|
||||
assert.NotNilf(t, duplicates, "There should be %v duplicate IDs found", 2)
|
||||
assert.Equal(t, 2, len(duplicates))
|
||||
}
|
||||
|
||||
func TestForDuplicatIDsInRelationshipsFail(t *testing.T) {
|
||||
|
@ -55,9 +49,8 @@ func TestForDuplicatIDsInRelationshipsFail(t *testing.T) {
|
|||
|
||||
duplicates := testData.CheckDuplicates()
|
||||
|
||||
if duplicates == nil {
|
||||
t.Errorf("There should be %v duplicate IDs found", len(testData.Relationships))
|
||||
}
|
||||
assert.NotNilf(t, duplicates, "There should be %v duplicate IDs found", 1)
|
||||
assert.Equal(t, 1, len(duplicates))
|
||||
}
|
||||
|
||||
func TestForDuplicatIDsFail(t *testing.T) {
|
||||
|
@ -66,9 +59,8 @@ func TestForDuplicatIDsFail(t *testing.T) {
|
|||
|
||||
duplicates := testData.CheckDuplicates()
|
||||
|
||||
if duplicates == nil {
|
||||
t.Error("There should be 2 duplicate IDs found")
|
||||
}
|
||||
assert.NotNilf(t, duplicates, "There should be %v duplicate IDs found", 1)
|
||||
assert.Equal(t, 1, len(duplicates))
|
||||
}
|
||||
|
||||
func TestServicesExistsFail(t *testing.T) {
|
||||
|
@ -80,11 +72,8 @@ func TestServicesExistsFail(t *testing.T) {
|
|||
|
||||
foundID := missing["Event Hubs to Event Logger Link"][0]
|
||||
|
||||
if len(missing) != 1 {
|
||||
t.Error("There should be only 1 missing services found")
|
||||
} else if foundID != expected {
|
||||
t.Errorf("Incorrect reference found. Expected: %v \nGot: %v", expected, foundID)
|
||||
}
|
||||
assert.Equal(t, 1, len(missing), "There should be only 1 missing services found")
|
||||
assert.Equalf(t, expected, foundID, "Incorrect reference found\nExpected: %v \nGot: %v", expected, foundID)
|
||||
}
|
||||
|
||||
func TestSchemaMissingDagName(t *testing.T) {
|
||||
|
@ -93,9 +82,7 @@ func TestSchemaMissingDagName(t *testing.T) {
|
|||
|
||||
err := testData.ValidateModel()
|
||||
|
||||
if err == nil {
|
||||
t.Error("Model validation should be invalid")
|
||||
}
|
||||
assert.Error(t, err, "Model validation should be invalid")
|
||||
}
|
||||
|
||||
func TestSchemaMissingDagID(t *testing.T) {
|
||||
|
@ -104,9 +91,7 @@ func TestSchemaMissingDagID(t *testing.T) {
|
|||
|
||||
err := testData.ValidateModel()
|
||||
|
||||
if err == nil {
|
||||
t.Error("Model validation should be invalid")
|
||||
}
|
||||
assert.Error(t, err, "Model validation should be invalid")
|
||||
}
|
||||
|
||||
func TestSchemaMissingService(t *testing.T) {
|
||||
|
@ -115,9 +100,7 @@ func TestSchemaMissingService(t *testing.T) {
|
|||
|
||||
err := testData.ValidateModel()
|
||||
|
||||
if err == nil {
|
||||
t.Error("Model validation should be invalid")
|
||||
}
|
||||
assert.Error(t, err, "Model validation should be invalid")
|
||||
}
|
||||
|
||||
func TestSchemaMissingServiceID(t *testing.T) {
|
||||
|
@ -126,9 +109,7 @@ func TestSchemaMissingServiceID(t *testing.T) {
|
|||
|
||||
err := testData.ValidateModel()
|
||||
|
||||
if err == nil {
|
||||
t.Error("Model validation should be invalid")
|
||||
}
|
||||
assert.Error(t, err, "Model validation should be invalid")
|
||||
}
|
||||
|
||||
func TestSchemaMissingRelationshipID(t *testing.T) {
|
||||
|
@ -137,7 +118,5 @@ func TestSchemaMissingRelationshipID(t *testing.T) {
|
|||
|
||||
err := testData.ValidateModel()
|
||||
|
||||
if err == nil {
|
||||
t.Error("Model validation should be invalid")
|
||||
}
|
||||
assert.Error(t, err, "Model validation should be invalid")
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package mapper_test
|
|||
import (
|
||||
"github.com/microsoft/abstrakt/internal/platform/mapper"
|
||||
"github.com/microsoft/abstrakt/internal/tools/guid"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
@ -32,9 +33,7 @@ func TestMapFromString(t *testing.T) {
|
|||
t.Errorf("LoadMapFromString() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
if !reflect.DeepEqual(mapper, tt.wantRet) {
|
||||
t.Errorf("LoadMapFromString() = %v, want %v", mapper, tt.wantRet)
|
||||
}
|
||||
assert.Truef(t, reflect.DeepEqual(mapper, tt.wantRet), "LoadMapFromString() = %v, want %v", mapper, tt.wantRet)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче