|
|
@ -3,6 +3,7 @@ package themis
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"context"
|
|
|
|
_ "embed"
|
|
|
|
_ "embed"
|
|
|
|
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
|
|
_ "github.com/mattn/go-sqlite3"
|
|
|
|
_ "github.com/mattn/go-sqlite3"
|
|
|
@ -18,6 +19,7 @@ func TestStore_Claim(t *testing.T) {
|
|
|
|
type args struct {
|
|
|
|
type args struct {
|
|
|
|
player string
|
|
|
|
player string
|
|
|
|
province string
|
|
|
|
province string
|
|
|
|
|
|
|
|
userId string
|
|
|
|
claimType ClaimType
|
|
|
|
claimType ClaimType
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
tests := []struct {
|
|
|
@ -31,6 +33,7 @@ func TestStore_Claim(t *testing.T) {
|
|
|
|
player: "foo",
|
|
|
|
player: "foo",
|
|
|
|
province: "Italy",
|
|
|
|
province: "Italy",
|
|
|
|
claimType: CLAIM_TYPE_REGION,
|
|
|
|
claimType: CLAIM_TYPE_REGION,
|
|
|
|
|
|
|
|
userId: "000000000000000001",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wantErr: false,
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
@ -40,6 +43,7 @@ func TestStore_Claim(t *testing.T) {
|
|
|
|
player: "foo",
|
|
|
|
player: "foo",
|
|
|
|
province: "Italy",
|
|
|
|
province: "Italy",
|
|
|
|
claimType: CLAIM_TYPE_TRADE, // Italy is a Region you silly goose
|
|
|
|
claimType: CLAIM_TYPE_TRADE, // Italy is a Region you silly goose
|
|
|
|
|
|
|
|
userId: "000000000000000001",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
@ -49,6 +53,7 @@ func TestStore_Claim(t *testing.T) {
|
|
|
|
player: "bar",
|
|
|
|
player: "bar",
|
|
|
|
province: "Genoa",
|
|
|
|
province: "Genoa",
|
|
|
|
claimType: CLAIM_TYPE_TRADE,
|
|
|
|
claimType: CLAIM_TYPE_TRADE,
|
|
|
|
|
|
|
|
userId: "000000000000000002",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
@ -58,13 +63,14 @@ func TestStore_Claim(t *testing.T) {
|
|
|
|
player: "foo", // 'foo' has a claim on Italy, which has overlapping provinces
|
|
|
|
player: "foo", // 'foo' has a claim on Italy, which has overlapping provinces
|
|
|
|
province: "Genoa",
|
|
|
|
province: "Genoa",
|
|
|
|
claimType: CLAIM_TYPE_TRADE,
|
|
|
|
claimType: CLAIM_TYPE_TRADE,
|
|
|
|
|
|
|
|
userId: "000000000000000001",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wantErr: false,
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
if err := store.Claim(context.TODO(), tt.args.player, tt.args.province, tt.args.claimType); (err != nil) != tt.wantErr {
|
|
|
|
if _, err := store.Claim(context.TODO(), tt.args.userId, tt.args.player, tt.args.province, tt.args.claimType); (err != nil) != tt.wantErr {
|
|
|
|
t.Errorf("Store.Claim() error = %v, wantErr %v", err, tt.wantErr)
|
|
|
|
t.Errorf("Store.Claim() error = %v, wantErr %v", err, tt.wantErr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
@ -75,9 +81,9 @@ func TestAvailability(t *testing.T) {
|
|
|
|
store, err := NewStore(TEST_CONN_STRING)
|
|
|
|
store, err := NewStore(TEST_CONN_STRING)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
store.Claim(context.TODO(), "foo", "Genoa", CLAIM_TYPE_TRADE)
|
|
|
|
store.Claim(context.TODO(), "000000000000000001", "foo", "Genoa", CLAIM_TYPE_TRADE)
|
|
|
|
store.Claim(context.TODO(), "foo", "Venice", CLAIM_TYPE_TRADE)
|
|
|
|
store.Claim(context.TODO(), "000000000000000001", "foo", "Venice", CLAIM_TYPE_TRADE)
|
|
|
|
store.Claim(context.TODO(), "foo", "English Channel", CLAIM_TYPE_TRADE)
|
|
|
|
store.Claim(context.TODO(), "000000000000000001", "foo", "English Channel", CLAIM_TYPE_TRADE)
|
|
|
|
|
|
|
|
|
|
|
|
// There's a total of 80 distinct trade nodes, there should be 77 available
|
|
|
|
// There's a total of 80 distinct trade nodes, there should be 77 available
|
|
|
|
// after the three claims above
|
|
|
|
// after the three claims above
|
|
|
@ -85,8 +91,8 @@ func TestAvailability(t *testing.T) {
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, 77, len(availability))
|
|
|
|
assert.Equal(t, 77, len(availability))
|
|
|
|
|
|
|
|
|
|
|
|
store.Claim(context.TODO(), "foo", "France", CLAIM_TYPE_REGION)
|
|
|
|
store.Claim(context.TODO(), "000000000000000001", "foo", "France", CLAIM_TYPE_REGION)
|
|
|
|
store.Claim(context.TODO(), "foo", "Italy", CLAIM_TYPE_REGION)
|
|
|
|
store.Claim(context.TODO(), "000000000000000001", "foo", "Italy", CLAIM_TYPE_REGION)
|
|
|
|
|
|
|
|
|
|
|
|
// There's a total of 73 distinct regions, there should be 71 available
|
|
|
|
// There's a total of 73 distinct regions, there should be 71 available
|
|
|
|
// after the two claims above
|
|
|
|
// after the two claims above
|
|
|
@ -94,10 +100,10 @@ func TestAvailability(t *testing.T) {
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, 71, len(availability))
|
|
|
|
assert.Equal(t, 71, len(availability))
|
|
|
|
|
|
|
|
|
|
|
|
store.Claim(context.TODO(), "foo", "Normandy", CLAIM_TYPE_AREA)
|
|
|
|
store.Claim(context.TODO(), "000000000000000001", "foo", "Normandy", CLAIM_TYPE_AREA)
|
|
|
|
store.Claim(context.TODO(), "foo", "Champagne", CLAIM_TYPE_AREA)
|
|
|
|
store.Claim(context.TODO(), "000000000000000001", "foo", "Champagne", CLAIM_TYPE_AREA)
|
|
|
|
store.Claim(context.TODO(), "foo", "Lorraine", CLAIM_TYPE_AREA)
|
|
|
|
store.Claim(context.TODO(), "000000000000000001", "foo", "Lorraine", CLAIM_TYPE_AREA)
|
|
|
|
store.Claim(context.TODO(), "foo", "Provence", CLAIM_TYPE_AREA)
|
|
|
|
store.Claim(context.TODO(), "000000000000000001", "foo", "Provence", CLAIM_TYPE_AREA)
|
|
|
|
|
|
|
|
|
|
|
|
// There's a total of 823 distinct regions, there should be 819 available
|
|
|
|
// There's a total of 823 distinct regions, there should be 819 available
|
|
|
|
// after the four claims above
|
|
|
|
// after the four claims above
|
|
|
@ -108,7 +114,7 @@ func TestAvailability(t *testing.T) {
|
|
|
|
// There is both a Trade Node and an Area called 'Valencia', while the trade
|
|
|
|
// There is both a Trade Node and an Area called 'Valencia', while the trade
|
|
|
|
// node is claimed, the area should show up in the availability list (even
|
|
|
|
// node is claimed, the area should show up in the availability list (even
|
|
|
|
// though there are conflicting provinces)
|
|
|
|
// though there are conflicting provinces)
|
|
|
|
store.Claim(context.TODO(), "foo", "Valencia", CLAIM_TYPE_TRADE)
|
|
|
|
store.Claim(context.TODO(), "000000000000000001", "foo", "Valencia", CLAIM_TYPE_TRADE)
|
|
|
|
availability, err = store.ListAvailability(context.TODO(), CLAIM_TYPE_AREA)
|
|
|
|
availability, err = store.ListAvailability(context.TODO(), CLAIM_TYPE_AREA)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, 819, len(availability)) // availability for areas should be the same as before
|
|
|
|
assert.Equal(t, 819, len(availability)) // availability for areas should be the same as before
|
|
|
@ -122,14 +128,23 @@ func TestDeleteClaim(t *testing.T) {
|
|
|
|
store, err := NewStore(TEST_CONN_STRING)
|
|
|
|
store, err := NewStore(TEST_CONN_STRING)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
store.Claim(context.TODO(), "foo", "Genoa", CLAIM_TYPE_TRADE)
|
|
|
|
// make sure all claims are gone, this is due to how the in-memory database
|
|
|
|
store.Claim(context.TODO(), "bar", "Balkans", CLAIM_TYPE_REGION)
|
|
|
|
// with a shared cache interacts with other tests running in parallel
|
|
|
|
store.Claim(context.TODO(), "baz", "English Channel", CLAIM_TYPE_TRADE)
|
|
|
|
_, err = store.db.ExecContext(context.TODO(), "DELETE FROM claims")
|
|
|
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fooId, _ := store.Claim(context.TODO(), "000000000000000001", "foo", "Genoa", CLAIM_TYPE_TRADE)
|
|
|
|
|
|
|
|
barId, _ := store.Claim(context.TODO(), "000000000000000002", "bar", "Balkans", CLAIM_TYPE_REGION)
|
|
|
|
|
|
|
|
store.Claim(context.TODO(), "000000000000000003", "baz", "English Channel", CLAIM_TYPE_TRADE)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
claims, err := store.ListClaims(context.TODO())
|
|
|
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
fmt.Print(claims)
|
|
|
|
|
|
|
|
|
|
|
|
err = store.DeleteClaim(context.TODO(), 1, "foo")
|
|
|
|
err = store.DeleteClaim(context.TODO(), fooId, "000000000000000001")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
err = store.DeleteClaim(context.TODO(), 2, "foo")
|
|
|
|
err = store.DeleteClaim(context.TODO(), barId, "000000000000000001")
|
|
|
|
assert.Error(t, err)
|
|
|
|
assert.Error(t, err)
|
|
|
|
assert.ErrorIs(t, err, ErrNoSuchClaim)
|
|
|
|
assert.ErrorIs(t, err, ErrNoSuchClaim)
|
|
|
|
}
|
|
|
|
}
|
|
|
|