Skip to content

Commit

Permalink
test(i): Restructure mutation integration test dir (sourcenetwork#1848)
Browse files Browse the repository at this point in the history
## Relevant issue(s)

Resolves sourcenetwork#1847

## Description

Restructures mutation integration test dir.

The previous structure did not offer adequate levels of test
discoverability, and as we really need to add more tests here, it needed
sorting out.

Also, all tests (I think) in the `mutation` directory have been migrated
to the newer test framework. A handful have been deleted, as the
restructuring highlight a few duplicates. Some schemas have also been
simplified.
  • Loading branch information
AndrewSisley authored Sep 6, 2023
1 parent 6bd4ee5 commit 8b10d0b
Show file tree
Hide file tree
Showing 58 changed files with 3,525 additions and 2,864 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
testUtils "github.com/sourcenetwork/defradb/tests/integration"
)

func ExecuteTestCase(t *testing.T, test testUtils.TestCase) {
func executeTestCase(t *testing.T, test testUtils.TestCase) {
testUtils.ExecuteTestCase(
t,
testUtils.TestCase{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

package create
package one_to_many

import (
"fmt"
"testing"

testUtils "github.com/sourcenetwork/defradb/tests/integration"
fixture "github.com/sourcenetwork/defradb/tests/integration/mutation/one_to_many"
)

func TestMutationCreateOneToMany_AliasedRelationNameWithInvalidField_Error(t *testing.T) {
Expand All @@ -32,7 +31,7 @@ func TestMutationCreateOneToMany_AliasedRelationNameWithInvalidField_Error(t *te
},
},
}
fixture.ExecuteTestCase(t, test)
executeTestCase(t, test)
}

func TestMutationCreateOneToMany_AliasedRelationNameNonExistingRelationSingleSide_NoIDFieldError(t *testing.T) {
Expand All @@ -49,7 +48,7 @@ func TestMutationCreateOneToMany_AliasedRelationNameNonExistingRelationSingleSid
},
},
}
fixture.ExecuteTestCase(t, test)
executeTestCase(t, test)
}

// Note: This test should probably not pass, as it contains a
Expand All @@ -72,7 +71,7 @@ func TestMutationCreateOneToMany_AliasedRelationNameNonExistingRelationManySide_
},
},
}
fixture.ExecuteTestCase(t, test)
executeTestCase(t, test)
}

func TestMutationCreateOneToMany_AliasedRelationNamToLinkFromSingleSide_NoIDFieldError(t *testing.T) {
Expand Down Expand Up @@ -107,7 +106,7 @@ func TestMutationCreateOneToMany_AliasedRelationNamToLinkFromSingleSide_NoIDFiel
},
}

fixture.ExecuteTestCase(t, test)
executeTestCase(t, test)
}

func TestMutationCreateOneToMany_AliasedRelationNameToLinkFromManySide(t *testing.T) {
Expand Down Expand Up @@ -184,7 +183,7 @@ func TestMutationCreateOneToMany_AliasedRelationNameToLinkFromManySide(t *testin
},
}

fixture.ExecuteTestCase(t, test)
executeTestCase(t, test)
}

func TestMutationUpdateOneToMany_AliasRelationNameAndInternalIDBothProduceSameDocID(t *testing.T) {
Expand Down Expand Up @@ -226,7 +225,7 @@ func TestMutationUpdateOneToMany_AliasRelationNameAndInternalIDBothProduceSameDo
},
},
}
fixture.ExecuteTestCase(t, nonAliasedTest)
executeTestCase(t, nonAliasedTest)

// Check that `bookKey` is same in both above and the alised version below.
// Note: Everything should be same, only diff should be the use of alias.
Expand Down Expand Up @@ -265,5 +264,5 @@ func TestMutationUpdateOneToMany_AliasRelationNameAndInternalIDBothProduceSameDo
},
},
}
fixture.ExecuteTestCase(t, aliasedTest)
executeTestCase(t, aliasedTest)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

package create
package one_to_many

import (
"fmt"
"testing"

testUtils "github.com/sourcenetwork/defradb/tests/integration"
fixture "github.com/sourcenetwork/defradb/tests/integration/mutation/one_to_many"
)

func TestMutationCreateOneToMany_WithInvalidField_Error(t *testing.T) {
Expand All @@ -32,7 +31,7 @@ func TestMutationCreateOneToMany_WithInvalidField_Error(t *testing.T) {
},
},
}
fixture.ExecuteTestCase(t, test)
executeTestCase(t, test)
}

func TestMutationCreateOneToMany_NonExistingRelationSingleSide_NoIDFieldError(t *testing.T) {
Expand All @@ -49,7 +48,7 @@ func TestMutationCreateOneToMany_NonExistingRelationSingleSide_NoIDFieldError(t
},
},
}
fixture.ExecuteTestCase(t, test)
executeTestCase(t, test)
}

// Note: This test should probably not pass, as it contains a
Expand All @@ -72,7 +71,7 @@ func TestMutationCreateOneToMany_NonExistingRelationManySide_CreatedDoc(t *testi
},
},
}
fixture.ExecuteTestCase(t, test)
executeTestCase(t, test)
}

func TestMutationCreateOneToMany_RelationIDToLinkFromSingleSide_NoIDFieldError(t *testing.T) {
Expand Down Expand Up @@ -107,7 +106,7 @@ func TestMutationCreateOneToMany_RelationIDToLinkFromSingleSide_NoIDFieldError(t
},
}

fixture.ExecuteTestCase(t, test)
executeTestCase(t, test)
}

func TestMutationCreateOneToMany_RelationIDToLinkFromManySide(t *testing.T) {
Expand Down Expand Up @@ -184,5 +183,5 @@ func TestMutationCreateOneToMany_RelationIDToLinkFromManySide(t *testing.T) {
},
}

fixture.ExecuteTestCase(t, test)
executeTestCase(t, test)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
testUtils "github.com/sourcenetwork/defradb/tests/integration"
)

func ExecuteTestCase(t *testing.T, test testUtils.TestCase) {
func executeTestCase(t *testing.T, test testUtils.TestCase) {
testUtils.ExecuteTestCase(
t,
testUtils.TestCase{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

package create
package one_to_one

import (
"fmt"
"testing"

testUtils "github.com/sourcenetwork/defradb/tests/integration"
simpleTests "github.com/sourcenetwork/defradb/tests/integration/mutation/one_to_one"
)

func TestMutationCreateOneToOne_UseAliasWithInvalidField_Error(t *testing.T) {
Expand All @@ -32,7 +31,7 @@ func TestMutationCreateOneToOne_UseAliasWithInvalidField_Error(t *testing.T) {
},
},
}
simpleTests.ExecuteTestCase(t, test)
executeTestCase(t, test)
}

// Note: This test should probably not pass, as it contains a
Expand All @@ -55,7 +54,7 @@ func TestMutationCreateOneToOne_UseAliasWithNonExistingRelationPrimarySide_Creat
},
},
}
simpleTests.ExecuteTestCase(t, test)
executeTestCase(t, test)
}

func TestMutationCreateOneToOne_UseAliasWithNonExistingRelationSecondarySide_Error(t *testing.T) {
Expand All @@ -72,7 +71,7 @@ func TestMutationCreateOneToOne_UseAliasWithNonExistingRelationSecondarySide_Err
},
},
}
simpleTests.ExecuteTestCase(t, test)
executeTestCase(t, test)
}

func TestMutationCreateOneToOne_UseAliasedRelationNameToLink_QueryFromPrimarySide(t *testing.T) {
Expand Down Expand Up @@ -147,7 +146,7 @@ func TestMutationCreateOneToOne_UseAliasedRelationNameToLink_QueryFromPrimarySid
},
}

simpleTests.ExecuteTestCase(t, test)
executeTestCase(t, test)
}

func TestMutationCreateOneToOne_UseAliasedRelationNameToLink_QueryFromSecondarySide(t *testing.T) {
Expand Down Expand Up @@ -222,5 +221,5 @@ func TestMutationCreateOneToOne_UseAliasedRelationNameToLink_QueryFromSecondaryS
},
}

simpleTests.ExecuteTestCase(t, test)
executeTestCase(t, test)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

package create
package one_to_one

import (
"fmt"
"testing"

testUtils "github.com/sourcenetwork/defradb/tests/integration"
simpleTests "github.com/sourcenetwork/defradb/tests/integration/mutation/one_to_one"
)

func TestMutationCreateOneToOne_WithInvalidField_Error(t *testing.T) {
Expand All @@ -32,7 +31,7 @@ func TestMutationCreateOneToOne_WithInvalidField_Error(t *testing.T) {
},
},
}
simpleTests.ExecuteTestCase(t, test)
executeTestCase(t, test)
}

// Note: This test should probably not pass, as it contains a
Expand All @@ -55,7 +54,7 @@ func TestMutationCreateOneToOneNoChild(t *testing.T) {
},
},
}
simpleTests.ExecuteTestCase(t, test)
executeTestCase(t, test)
}

func TestMutationCreateOneToOne_NonExistingRelationSecondarySide_Error(t *testing.T) {
Expand All @@ -72,7 +71,7 @@ func TestMutationCreateOneToOne_NonExistingRelationSecondarySide_Error(t *testin
},
},
}
simpleTests.ExecuteTestCase(t, test)
executeTestCase(t, test)
}

func TestMutationCreateOneToOne(t *testing.T) {
Expand Down Expand Up @@ -149,7 +148,7 @@ func TestMutationCreateOneToOne(t *testing.T) {
},
}

simpleTests.ExecuteTestCase(t, test)
executeTestCase(t, test)
}

func TestMutationCreateOneToOneSecondarySide(t *testing.T) {
Expand Down Expand Up @@ -226,7 +225,7 @@ func TestMutationCreateOneToOneSecondarySide(t *testing.T) {
},
}

simpleTests.ExecuteTestCase(t, test)
executeTestCase(t, test)
}

func TestMutationCreateOneToOne_ErrorsGivenRelationAlreadyEstablishedViaPrimary(t *testing.T) {
Expand Down Expand Up @@ -264,7 +263,7 @@ func TestMutationCreateOneToOne_ErrorsGivenRelationAlreadyEstablishedViaPrimary(
},
}

simpleTests.ExecuteTestCase(t, test)
executeTestCase(t, test)
}

func TestMutationCreateOneToOne_ErrorsGivenRelationAlreadyEstablishedViaSecondary(t *testing.T) {
Expand Down Expand Up @@ -302,5 +301,5 @@ func TestMutationCreateOneToOne_ErrorsGivenRelationAlreadyEstablishedViaSecondar
},
}

simpleTests.ExecuteTestCase(t, test)
executeTestCase(t, test)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright 2023 Democratized Data Foundation
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

package one_to_one_to_one

import (
"testing"

testUtils "github.com/sourcenetwork/defradb/tests/integration"
)

func execute(t *testing.T, test testUtils.TestCase) {
testUtils.ExecuteTestCase(
t,
testUtils.TestCase{
Description: test.Description,
Actions: append(
[]any{
testUtils.SchemaUpdate{
Schema: `
type Book {
name: String
rating: Float
author: Author
publisher: Publisher
}
type Author {
name: String
age: Int
verified: Boolean
wrote: Book @primary
}
type Publisher {
name: String
address: String
published: Book
}
`,
},
},
test.Actions...,
),
},
)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022 Democratized Data Foundation
// Copyright 2023 Democratized Data Foundation
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
Expand All @@ -8,15 +8,14 @@
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

package relation_create
package one_to_one_to_one

import (
"testing"

"github.com/sourcenetwork/immutable"

testUtils "github.com/sourcenetwork/defradb/tests/integration"
relationTests "github.com/sourcenetwork/defradb/tests/integration/mutation/relation"
)

func TestTransactionalCreationAndLinkingOfRelationalDocumentsForward(t *testing.T) {
Expand Down Expand Up @@ -168,7 +167,7 @@ func TestTransactionalCreationAndLinkingOfRelationalDocumentsForward(t *testing.
},
}

relationTests.Execute(t, test)
execute(t, test)
}

func TestTransactionalCreationAndLinkingOfRelationalDocumentsBackward(t *testing.T) {
Expand Down Expand Up @@ -308,5 +307,5 @@ func TestTransactionalCreationAndLinkingOfRelationalDocumentsBackward(t *testing
},
}

relationTests.Execute(t, test)
execute(t, test)
}
Loading

0 comments on commit 8b10d0b

Please sign in to comment.