Skip to content

Commit

Permalink
Review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
bartelink committed Apr 8, 2022
1 parent e50078a commit c0b0d73
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 16 deletions.
7 changes: 2 additions & 5 deletions src/FSharp.AWS.DynamoDB/TableContext.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1133,11 +1133,8 @@ module Scripting =
/// <param name="client">DynamoDB client instance.</param>
/// <param name="tableName">Table name to target.</param>
/// <param name="throughput">Optional throughput to configure if the Table does not yet exist.</param>
/// <param name="metricsCollector">Function to receive request metrics.</param>
static member Initialize<'TRecord>
( client : IAmazonDynamoDB, tableName : string, ?throughput,
?metricsCollector : RequestMetrics -> unit) : TableContext<'TRecord> =
let context = TableContext<'TRecord>(client, tableName, ?metricsCollector = metricsCollector)
static member Initialize<'TRecord>(client : IAmazonDynamoDB, tableName : string, ?throughput) : TableContext<'TRecord> =
let context = TableContext<'TRecord>(client, tableName)
match throughput with
| None -> context.VerifyTableAsync() |> Async.RunSynchronously
| Some t -> context.VerifyOrCreateTableAsync(t) |> Async.RunSynchronously
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ type ``Conditional Expression Tests`` (fixture : TableFixture) =
Serialized = rand(), guid()
}

let table = fixture.CreateContextAndTableIfNotExists<CondExprRecord>()
let table = fixture.CreateEmpty<CondExprRecord>()

let [<Fact>] ``Item exists precondition`` () =
let item = mkItem()
Expand Down
8 changes: 4 additions & 4 deletions tests/FSharp.AWS.DynamoDB.Tests/MetricsCollectorTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ let (|TotalCu|) : ConsumedCapacity list -> float = Seq.sumBy (fun c -> c.Capacit
/// Tests without common setup
type Tests(fixture : TableFixture) =

let rawTable = fixture.CreateContextAndTableIfNotExists<MetricsRecord>()
let rawTable = fixture.CreateEmpty<MetricsRecord>()

let (|ExpectedTableName|_|) name = if name = fixture.TableName then Some () else None

Expand Down Expand Up @@ -84,7 +84,7 @@ type Tests(fixture : TableFixture) =
/// Tests that look up a specific item. Each test run gets a fresh individual item
type ItemTests(fixture : TableFixture) =

let rawTable = fixture.CreateContextAndTableIfNotExists<MetricsRecord>()
let rawTable = fixture.CreateEmpty<MetricsRecord>()
let (|ExpectedTableName|_|) name = if name = fixture.TableName then Some () else None

let item = mkItem (guid()) (guid()) 0
Expand Down Expand Up @@ -131,7 +131,7 @@ type ItemTests(fixture : TableFixture) =
/// Heavy tests reliant on establishing (and mutating) multiple items. Separate Test Class so Xunit will run them in parallel with others
type BulkMutationTests(fixture : TableFixture) =

let rawTable = fixture.CreateContextAndTableIfNotExists<MetricsRecord>()
let rawTable = fixture.CreateEmpty<MetricsRecord>()
let (|ExpectedTableName|_|) name = if name = fixture.TableName then Some () else None

// NOTE we mutate the items so they need to be established each time
Expand Down Expand Up @@ -169,7 +169,7 @@ type ManyReadOnlyItemsFixture() =
inherit TableFixture()

// TOCONSIDER shift this into IAsyncLifetime.InitializeAsync
let table = base.CreateContextAndTableIfNotExists<MetricsRecord>()
let table = base.CreateEmpty<MetricsRecord>()

let hk = guid ()
do let gsk = guid ()
Expand Down
2 changes: 1 addition & 1 deletion tests/FSharp.AWS.DynamoDB.Tests/PaginationTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type ``Pagination Tests`` (fixture : TableFixture) =
LocalAttribute = int (rand () % 2L)
}

let table = fixture.CreateContextAndTableIfNotExists<PaginationRecord>()
let table = fixture.CreateEmpty<PaginationRecord>()

let [<Fact>] ``Paginated Query on Primary Key`` () =
let hk = guid()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ type ``Projection Expression Tests`` (fixture : TableFixture) =
Serialized = rand(), guid() ; Serialized2 = { NV = guid() ; NE = enum<Enum> (int (rand()) % 3) } ;
}

let table = fixture.CreateContextAndTableIfNotExists<ProjectionExprRecord>()
let table = fixture.CreateEmpty<ProjectionExprRecord>()

let [<Fact>] ``Should fail on invalid projections`` () =
let testProj (p : Expr<R -> 'T>) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type ``Simple Table Operation Tests`` (fixture : TableFixture) =
Unions = [Choice1Of3 (guid()) ; Choice2Of3(rand()) ; Choice3Of3(Guid.NewGuid().ToByteArray())]
}

let table = fixture.CreateContextAndTableIfNotExists<SimpleRecord>()
let table = fixture.CreateEmpty<SimpleRecord>()

let [<Fact>] ``Convert to compatible table`` () =
let table' = table.WithRecordType<CompatibleRecord> ()
Expand Down
2 changes: 1 addition & 1 deletion tests/FSharp.AWS.DynamoDB.Tests/SparseGSITests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type ``Sparse GSI Tests`` (fixture : TableFixture) =
SecondaryHashKey = if rand() % 2L = 0L then Some (guid()) else None ;
}

let table = fixture.CreateContextAndTableIfNotExists<GsiRecord>()
let table = fixture.CreateEmpty<GsiRecord>()

let [<Fact>] ``GSI Put Operation`` () =
let value = mkItem()
Expand Down
2 changes: 1 addition & 1 deletion tests/FSharp.AWS.DynamoDB.Tests/UpdateExpressionTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ type ``Update Expression Tests``(fixture : TableFixture) =
Serialized = rand(), guid() ; Serialized2 = { NV = guid() ; NE = enum<Enum> (int (rand()) % 3) } ;
}

let table = fixture.CreateContextAndTableIfNotExists<UpdateExprRecord>()
let table = fixture.CreateEmpty<UpdateExprRecord>()

let [<Fact>] ``Attempt to update HashKey`` () =
let item = mkItem()
Expand Down
2 changes: 1 addition & 1 deletion tests/FSharp.AWS.DynamoDB.Tests/Utils.fs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ module Utils =
member _.Client = client
member _.TableName = tableName

member _.CreateContextAndTableIfNotExists<'TRecord>() =
member _.CreateEmpty<'TRecord>() =
let throughput = ProvisionedThroughput(readCapacityUnits = 10L, writeCapacityUnits = 10L)
Scripting.TableContext.Initialize<'TRecord>(client, tableName, Throughput.Provisioned throughput)

Expand Down

0 comments on commit c0b0d73

Please sign in to comment.