Skip to content

Commit

Permalink
Fixes state cert tests (#3596)
Browse files Browse the repository at this point in the history
Signed-off-by: Elena Kolevska <elena@kolevska.com>
  • Loading branch information
elena-kolevska authored Dec 2, 2024
1 parent 1e095ed commit 2e4fc0b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/infrastructure/docker-compose-sqlserver.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '2'
version: '3'
services:
sqlserver:
image: mcr.microsoft.com/mssql/server:2019-latest
Expand Down
12 changes: 4 additions & 8 deletions tests/certification/state/azure/cosmosdb/cosmosdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,13 @@ func TestAzureCosmosDBStorage(t *testing.T) {
"partitionKey": "mypartition",
}

test := func(setMeta, getMeta map[string]string, expectedValue string, expectedErr bool) {
test := func(setMeta, getMeta map[string]string, expectedValue string) {
// save state, default options: strong, last-write
err = client.SaveState(ctx, statestore, stateKey, []byte(stateValue), setMeta)
require.NoError(t, err)

// get state
item, err := client.GetState(ctx, statestore, stateKey, getMeta)
if expectedErr {
require.Error(t, err)
return
}
require.NoError(t, err)
assert.Equal(t, expectedValue, string(item.Value))

Expand All @@ -153,13 +149,13 @@ func TestAzureCosmosDBStorage(t *testing.T) {
}

// Test with no partition key
test(nil, meta1, stateValue, false)
test(nil, meta1, stateValue)

// Test with specific partition key
test(meta2, meta2, stateValue, false)
test(meta2, meta2, stateValue)

// Test with incorrect partition key
test(meta2, meta1, "", true)
test(meta2, meta1, "")

return nil
}
Expand Down
7 changes: 4 additions & 3 deletions tests/certification/state/memcached/memcached_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import (
"github.com/dapr/components-contrib/state"
"github.com/dapr/go-sdk/client"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

state_memcached "github.com/dapr/components-contrib/state/memcached"
"github.com/dapr/components-contrib/tests/certification/embedded"
"github.com/dapr/components-contrib/tests/certification/flow"
Expand All @@ -31,8 +34,6 @@ import (
state_loader "github.com/dapr/dapr/pkg/components/state"
dapr_testing "github.com/dapr/dapr/pkg/testing"
"github.com/dapr/kit/logger"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

const (
Expand Down Expand Up @@ -168,7 +169,7 @@ func TestMemcached(t *testing.T) {
key := certificationTestPrefix + "_expiresInOneSecondKey"
value := "This key will self-destroy in 1 second"

ttlExpirationTime := 1 * time.Second
ttlExpirationTime := 3 * time.Second
ttlInSeconds := int(ttlExpirationTime.Seconds())
mapOptionsExpiringKey := map[string]string{
"ttlInSeconds": strconv.Itoa(ttlInSeconds),
Expand Down
14 changes: 14 additions & 0 deletions tests/certification/state/sqlserver/sqlserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,20 @@ const (
)

func TestSqlServer(t *testing.T) {
// The default certificate created by the docker container sometimes contains a negative serial number.
// A TLS certificate with a negative serial number is invalid, although it was tolerated until 1.22
// Since Go 1.23 the default behavior has changed and the certificate is rejected.
// This environment variable is used to revert to the old behavior.
// Ref: https://github.com/microsoft/mssql-docker/issues/895
oldDebugValue := os.Getenv("GODEBUG")
err := os.Setenv("GODEBUG", "x509negativeserial=1")
if err != nil {
t.Fatalf("Failed to set GODEBUG environment variable: %v", err)
}
defer func() {
os.Setenv("GODEBUG", oldDebugValue)
}()

ports, err := dapr_testing.GetFreePorts(2)
require.NoError(t, err)

Expand Down

0 comments on commit 2e4fc0b

Please sign in to comment.