mirror of https://github.com/dapr/dapr.git
Enabled linter for test files as well (#696)
* Enabled linter for test files as well * Fixed unittest failure * Fixed unit test
This commit is contained in:
parent
eaa1e29f8e
commit
b49e75e5e6
|
|
@ -10,7 +10,7 @@ run:
|
||||||
issues-exit-code: 1
|
issues-exit-code: 1
|
||||||
|
|
||||||
# include test files or not, default is true
|
# include test files or not, default is true
|
||||||
tests: false
|
tests: true
|
||||||
|
|
||||||
# list of build tags, all linters use it. Default is empty list.
|
# list of build tags, all linters use it. Default is empty list.
|
||||||
#build-tags:
|
#build-tags:
|
||||||
|
|
@ -116,7 +116,7 @@ linters-settings:
|
||||||
# minimal length of string constant, 3 by default
|
# minimal length of string constant, 3 by default
|
||||||
min-len: 3
|
min-len: 3
|
||||||
# minimal occurrences count to trigger, 3 by default
|
# minimal occurrences count to trigger, 3 by default
|
||||||
min-occurrences: 3
|
min-occurrences: 5
|
||||||
depguard:
|
depguard:
|
||||||
list-type: blacklist
|
list-type: blacklist
|
||||||
include-go-root: false
|
include-go-root: false
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ import (
|
||||||
|
|
||||||
const (
|
const (
|
||||||
TestDaprID = "fakeDaprID"
|
TestDaprID = "fakeDaprID"
|
||||||
|
TestKeyName = "key0"
|
||||||
)
|
)
|
||||||
|
|
||||||
type fakeStateStore struct {
|
type fakeStateStore struct {
|
||||||
|
|
@ -396,11 +397,10 @@ func TestReminderFiresOnceWitnEmptyPeriod(t *testing.T) {
|
||||||
func TestConstructActorStateKey(t *testing.T) {
|
func TestConstructActorStateKey(t *testing.T) {
|
||||||
testActorsRuntime := newTestActorsRuntime()
|
testActorsRuntime := newTestActorsRuntime()
|
||||||
actorType, actorID := getTestActorTypeAndID()
|
actorType, actorID := getTestActorTypeAndID()
|
||||||
keyName := "key0"
|
expected := fmt.Sprintf("%s-%s-%s-%s", TestDaprID, actorType, actorID, TestKeyName)
|
||||||
expected := fmt.Sprintf("%s-%s-%s-%s", TestDaprID, actorType, actorID, keyName)
|
|
||||||
|
|
||||||
// act
|
// act
|
||||||
stateKey := testActorsRuntime.constructActorStateKey(actorType, actorID, keyName)
|
stateKey := testActorsRuntime.constructActorStateKey(actorType, actorID, TestKeyName)
|
||||||
|
|
||||||
// assert
|
// assert
|
||||||
assert.Equal(t, expected, stateKey)
|
assert.Equal(t, expected, stateKey)
|
||||||
|
|
@ -409,7 +409,6 @@ func TestConstructActorStateKey(t *testing.T) {
|
||||||
func TestSaveState(t *testing.T) {
|
func TestSaveState(t *testing.T) {
|
||||||
testActorRuntime := newTestActorsRuntime()
|
testActorRuntime := newTestActorsRuntime()
|
||||||
actorType, actorID := getTestActorTypeAndID()
|
actorType, actorID := getTestActorTypeAndID()
|
||||||
keyName := "key0"
|
|
||||||
fakeData := strconv.Quote("fakeData")
|
fakeData := strconv.Quote("fakeData")
|
||||||
|
|
||||||
var val interface{}
|
var val interface{}
|
||||||
|
|
@ -422,7 +421,7 @@ func TestSaveState(t *testing.T) {
|
||||||
err := testActorRuntime.SaveState(&SaveStateRequest{
|
err := testActorRuntime.SaveState(&SaveStateRequest{
|
||||||
ActorID: actorID,
|
ActorID: actorID,
|
||||||
ActorType: actorType,
|
ActorType: actorType,
|
||||||
Key: keyName,
|
Key: TestKeyName,
|
||||||
Value: val,
|
Value: val,
|
||||||
})
|
})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
@ -431,7 +430,7 @@ func TestSaveState(t *testing.T) {
|
||||||
response, err := testActorRuntime.GetState(&GetStateRequest{
|
response, err := testActorRuntime.GetState(&GetStateRequest{
|
||||||
ActorID: actorID,
|
ActorID: actorID,
|
||||||
ActorType: actorType,
|
ActorType: actorType,
|
||||||
Key: keyName,
|
Key: TestKeyName,
|
||||||
})
|
})
|
||||||
|
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
@ -441,7 +440,6 @@ func TestSaveState(t *testing.T) {
|
||||||
func TestGetState(t *testing.T) {
|
func TestGetState(t *testing.T) {
|
||||||
testActorRuntime := newTestActorsRuntime()
|
testActorRuntime := newTestActorsRuntime()
|
||||||
actorType, actorID := getTestActorTypeAndID()
|
actorType, actorID := getTestActorTypeAndID()
|
||||||
keyName := "key0"
|
|
||||||
fakeData := strconv.Quote("fakeData")
|
fakeData := strconv.Quote("fakeData")
|
||||||
|
|
||||||
var val interface{}
|
var val interface{}
|
||||||
|
|
@ -453,7 +451,7 @@ func TestGetState(t *testing.T) {
|
||||||
testActorRuntime.SaveState(&SaveStateRequest{
|
testActorRuntime.SaveState(&SaveStateRequest{
|
||||||
ActorID: actorID,
|
ActorID: actorID,
|
||||||
ActorType: actorType,
|
ActorType: actorType,
|
||||||
Key: keyName,
|
Key: TestKeyName,
|
||||||
Value: val,
|
Value: val,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -461,7 +459,7 @@ func TestGetState(t *testing.T) {
|
||||||
response, err := testActorRuntime.GetState(&GetStateRequest{
|
response, err := testActorRuntime.GetState(&GetStateRequest{
|
||||||
ActorID: actorID,
|
ActorID: actorID,
|
||||||
ActorType: actorType,
|
ActorType: actorType,
|
||||||
Key: keyName,
|
Key: TestKeyName,
|
||||||
})
|
})
|
||||||
|
|
||||||
// assert
|
// assert
|
||||||
|
|
@ -472,7 +470,6 @@ func TestGetState(t *testing.T) {
|
||||||
func TestDeleteState(t *testing.T) {
|
func TestDeleteState(t *testing.T) {
|
||||||
testActorRuntime := newTestActorsRuntime()
|
testActorRuntime := newTestActorsRuntime()
|
||||||
actorType, actorID := getTestActorTypeAndID()
|
actorType, actorID := getTestActorTypeAndID()
|
||||||
keyName := "key0"
|
|
||||||
fakeData := strconv.Quote("fakeData")
|
fakeData := strconv.Quote("fakeData")
|
||||||
|
|
||||||
var val interface{}
|
var val interface{}
|
||||||
|
|
@ -485,7 +482,7 @@ func TestDeleteState(t *testing.T) {
|
||||||
testActorRuntime.SaveState(&SaveStateRequest{
|
testActorRuntime.SaveState(&SaveStateRequest{
|
||||||
ActorID: actorID,
|
ActorID: actorID,
|
||||||
ActorType: actorType,
|
ActorType: actorType,
|
||||||
Key: keyName,
|
Key: TestKeyName,
|
||||||
Value: val,
|
Value: val,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -493,7 +490,7 @@ func TestDeleteState(t *testing.T) {
|
||||||
response, err := testActorRuntime.GetState(&GetStateRequest{
|
response, err := testActorRuntime.GetState(&GetStateRequest{
|
||||||
ActorID: actorID,
|
ActorID: actorID,
|
||||||
ActorType: actorType,
|
ActorType: actorType,
|
||||||
Key: keyName,
|
Key: TestKeyName,
|
||||||
})
|
})
|
||||||
|
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
@ -503,7 +500,7 @@ func TestDeleteState(t *testing.T) {
|
||||||
err = testActorRuntime.DeleteState(&DeleteStateRequest{
|
err = testActorRuntime.DeleteState(&DeleteStateRequest{
|
||||||
ActorID: actorID,
|
ActorID: actorID,
|
||||||
ActorType: actorType,
|
ActorType: actorType,
|
||||||
Key: keyName,
|
Key: TestKeyName,
|
||||||
})
|
})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
|
@ -511,7 +508,7 @@ func TestDeleteState(t *testing.T) {
|
||||||
response, err = testActorRuntime.GetState(&GetStateRequest{
|
response, err = testActorRuntime.GetState(&GetStateRequest{
|
||||||
ActorID: actorID,
|
ActorID: actorID,
|
||||||
ActorType: actorType,
|
ActorType: actorType,
|
||||||
Key: keyName,
|
Key: TestKeyName,
|
||||||
})
|
})
|
||||||
|
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
@ -530,7 +527,7 @@ func TestTransactionalState(t *testing.T) {
|
||||||
ActorType: actorType,
|
ActorType: actorType,
|
||||||
ActorID: actorID,
|
ActorID: actorID,
|
||||||
Operations: []TransactionalOperation{
|
Operations: []TransactionalOperation{
|
||||||
TransactionalOperation{
|
{
|
||||||
Operation: Upsert,
|
Operation: Upsert,
|
||||||
Request: TransactionalUpsert{
|
Request: TransactionalUpsert{
|
||||||
Key: "key1",
|
Key: "key1",
|
||||||
|
|
@ -553,14 +550,14 @@ func TestTransactionalState(t *testing.T) {
|
||||||
ActorType: actorType,
|
ActorType: actorType,
|
||||||
ActorID: actorID,
|
ActorID: actorID,
|
||||||
Operations: []TransactionalOperation{
|
Operations: []TransactionalOperation{
|
||||||
TransactionalOperation{
|
{
|
||||||
Operation: Upsert,
|
Operation: Upsert,
|
||||||
Request: TransactionalUpsert{
|
Request: TransactionalUpsert{
|
||||||
Key: "key1",
|
Key: "key1",
|
||||||
Value: "fakeData",
|
Value: "fakeData",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
TransactionalOperation{
|
{
|
||||||
Operation: Delete,
|
Operation: Delete,
|
||||||
Request: TransactionalDelete{
|
Request: TransactionalDelete{
|
||||||
Key: "key1",
|
Key: "key1",
|
||||||
|
|
@ -582,7 +579,7 @@ func TestTransactionalState(t *testing.T) {
|
||||||
ActorType: actorType,
|
ActorType: actorType,
|
||||||
ActorID: actorID,
|
ActorID: actorID,
|
||||||
Operations: []TransactionalOperation{
|
Operations: []TransactionalOperation{
|
||||||
TransactionalOperation{
|
{
|
||||||
Operation: Upsert,
|
Operation: Upsert,
|
||||||
Request: "wrongBody",
|
Request: "wrongBody",
|
||||||
},
|
},
|
||||||
|
|
@ -602,7 +599,7 @@ func TestTransactionalState(t *testing.T) {
|
||||||
ActorType: actorType,
|
ActorType: actorType,
|
||||||
ActorID: actorID,
|
ActorID: actorID,
|
||||||
Operations: []TransactionalOperation{
|
Operations: []TransactionalOperation{
|
||||||
TransactionalOperation{
|
{
|
||||||
Operation: "Wrong",
|
Operation: "Wrong",
|
||||||
Request: "wrongBody",
|
Request: "wrongBody",
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@ package grpc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
|
@ -42,7 +44,7 @@ func (m *mockServer) OnTopicEvent(ctx context.Context, in *pb.CloudEventEnvelope
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInvokeMethod(t *testing.T) {
|
func TestInvokeMethod(t *testing.T) {
|
||||||
lis, err := net.Listen("tcp", ":9998")
|
lis, err := net.Listen("tcp", "127.0.0.1:9998")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
grpcServer := grpc.NewServer()
|
grpcServer := grpc.NewServer()
|
||||||
|
|
@ -54,7 +56,7 @@ func TestInvokeMethod(t *testing.T) {
|
||||||
var opts []grpc.DialOption
|
var opts []grpc.DialOption
|
||||||
opts = append(opts, grpc.WithInsecure())
|
opts = append(opts, grpc.WithInsecure())
|
||||||
conn, err := grpc.Dial("localhost:9998", opts...)
|
conn, err := grpc.Dial("localhost:9998", opts...)
|
||||||
defer conn.Close()
|
defer close(t, conn)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
c := Channel{baseAddress: "localhost:9998", client: conn}
|
c := Channel{baseAddress: "localhost:9998", client: conn}
|
||||||
|
|
@ -65,6 +67,13 @@ func TestInvokeMethod(t *testing.T) {
|
||||||
grpcServer.Stop()
|
grpcServer.Stop()
|
||||||
|
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.True(t, "param1=val1¶m2=val2&" == string(response.Data) ||
|
assert.True(t, string(response.Data) == "param1=val1¶m2=val2&" ||
|
||||||
"param2=val2¶m1=val1&" == string(response.Data))
|
string(response.Data) == "param2=val2¶m1=val1&")
|
||||||
|
}
|
||||||
|
|
||||||
|
func close(t *testing.T, c io.Closer) {
|
||||||
|
err := c.Close()
|
||||||
|
if err != nil {
|
||||||
|
assert.Fail(t, fmt.Sprintf("unable to close %s", err))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,5 +26,4 @@ func TestLoad(t *testing.T) {
|
||||||
assert.NotNil(t, p)
|
assert.NotNil(t, p)
|
||||||
assert.Nil(t, e)
|
assert.Nil(t, e)
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ package grpc
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
@ -101,7 +102,7 @@ func TestCallActorWithTracing(t *testing.T) {
|
||||||
var opts []grpc_go.DialOption
|
var opts []grpc_go.DialOption
|
||||||
opts = append(opts, grpc_go.WithInsecure())
|
opts = append(opts, grpc_go.WithInsecure())
|
||||||
conn, err := grpc_go.Dial(fmt.Sprintf("localhost:%d", port), opts...)
|
conn, err := grpc_go.Dial(fmt.Sprintf("localhost:%d", port), opts...)
|
||||||
defer conn.Close()
|
defer close(t, conn)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
client := daprinternal_pb.NewDaprInternalClient(conn)
|
client := daprinternal_pb.NewDaprInternalClient(conn)
|
||||||
|
|
@ -148,7 +149,7 @@ func TestCallRemoteAppWithTracing(t *testing.T) {
|
||||||
var opts []grpc_go.DialOption
|
var opts []grpc_go.DialOption
|
||||||
opts = append(opts, grpc_go.WithInsecure())
|
opts = append(opts, grpc_go.WithInsecure())
|
||||||
conn, err := grpc_go.Dial(fmt.Sprintf("localhost:%d", port), opts...)
|
conn, err := grpc_go.Dial(fmt.Sprintf("localhost:%d", port), opts...)
|
||||||
defer conn.Close()
|
defer close(t, conn)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
client := daprinternal_pb.NewDaprInternalClient(conn)
|
client := daprinternal_pb.NewDaprInternalClient(conn)
|
||||||
|
|
@ -178,13 +179,13 @@ func TestSaveState(t *testing.T) {
|
||||||
var opts []grpc_go.DialOption
|
var opts []grpc_go.DialOption
|
||||||
opts = append(opts, grpc_go.WithInsecure())
|
opts = append(opts, grpc_go.WithInsecure())
|
||||||
conn, err := grpc_go.Dial(fmt.Sprintf("localhost:%d", port), opts...)
|
conn, err := grpc_go.Dial(fmt.Sprintf("localhost:%d", port), opts...)
|
||||||
defer conn.Close()
|
defer close(t, conn)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
client := dapr_pb.NewDaprClient(conn)
|
client := dapr_pb.NewDaprClient(conn)
|
||||||
request := &dapr_pb.SaveStateEnvelope{
|
request := &dapr_pb.SaveStateEnvelope{
|
||||||
Requests: []*dapr_pb.StateRequest{
|
Requests: []*dapr_pb.StateRequest{
|
||||||
&dapr_pb.StateRequest{
|
{
|
||||||
Key: "1",
|
Key: "1",
|
||||||
Value: &any.Any{Value: []byte("2")},
|
Value: &any.Any{Value: []byte("2")},
|
||||||
},
|
},
|
||||||
|
|
@ -212,7 +213,7 @@ func TestGetState(t *testing.T) {
|
||||||
var opts []grpc_go.DialOption
|
var opts []grpc_go.DialOption
|
||||||
opts = append(opts, grpc_go.WithInsecure())
|
opts = append(opts, grpc_go.WithInsecure())
|
||||||
conn, err := grpc_go.Dial(fmt.Sprintf("localhost:%d", port), opts...)
|
conn, err := grpc_go.Dial(fmt.Sprintf("localhost:%d", port), opts...)
|
||||||
defer conn.Close()
|
defer close(t, conn)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
client := dapr_pb.NewDaprClient(conn)
|
client := dapr_pb.NewDaprClient(conn)
|
||||||
|
|
@ -237,7 +238,7 @@ func TestDeleteState(t *testing.T) {
|
||||||
var opts []grpc_go.DialOption
|
var opts []grpc_go.DialOption
|
||||||
opts = append(opts, grpc_go.WithInsecure())
|
opts = append(opts, grpc_go.WithInsecure())
|
||||||
conn, err := grpc_go.Dial(fmt.Sprintf("localhost:%d", port), opts...)
|
conn, err := grpc_go.Dial(fmt.Sprintf("localhost:%d", port), opts...)
|
||||||
defer conn.Close()
|
defer close(t, conn)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
client := dapr_pb.NewDaprClient(conn)
|
client := dapr_pb.NewDaprClient(conn)
|
||||||
|
|
@ -262,7 +263,7 @@ func TestPublishTopic(t *testing.T) {
|
||||||
var opts []grpc_go.DialOption
|
var opts []grpc_go.DialOption
|
||||||
opts = append(opts, grpc_go.WithInsecure())
|
opts = append(opts, grpc_go.WithInsecure())
|
||||||
conn, err := grpc_go.Dial(fmt.Sprintf("localhost:%d", port), opts...)
|
conn, err := grpc_go.Dial(fmt.Sprintf("localhost:%d", port), opts...)
|
||||||
defer conn.Close()
|
defer close(t, conn)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
client := dapr_pb.NewDaprClient(conn)
|
client := dapr_pb.NewDaprClient(conn)
|
||||||
|
|
@ -287,7 +288,7 @@ func TestInvokeBinding(t *testing.T) {
|
||||||
var opts []grpc_go.DialOption
|
var opts []grpc_go.DialOption
|
||||||
opts = append(opts, grpc_go.WithInsecure())
|
opts = append(opts, grpc_go.WithInsecure())
|
||||||
conn, err := grpc_go.Dial(fmt.Sprintf("localhost:%d", port), opts...)
|
conn, err := grpc_go.Dial(fmt.Sprintf("localhost:%d", port), opts...)
|
||||||
defer conn.Close()
|
defer close(t, conn)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
client := dapr_pb.NewDaprClient(conn)
|
client := dapr_pb.NewDaprClient(conn)
|
||||||
|
|
@ -295,3 +296,10 @@ func TestInvokeBinding(t *testing.T) {
|
||||||
server.Stop()
|
server.Stop()
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func close(t *testing.T, c io.Closer) {
|
||||||
|
err := c.Close()
|
||||||
|
if err != nil {
|
||||||
|
assert.Fail(t, fmt.Sprintf("unable to close %s", err))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
// Licensed under the MIT License.
|
// Licensed under the MIT License.
|
||||||
// ------------------------------------------------------------
|
// ------------------------------------------------------------
|
||||||
|
|
||||||
|
//nolint:goconst
|
||||||
package http
|
package http
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
@ -40,8 +41,7 @@ var retryCounter = 0
|
||||||
func TestSetHeaders(t *testing.T) {
|
func TestSetHeaders(t *testing.T) {
|
||||||
testAPI := &api{}
|
testAPI := &api{}
|
||||||
c := &routing.Context{}
|
c := &routing.Context{}
|
||||||
request := fasthttp.Request{}
|
c.RequestCtx = &fasthttp.RequestCtx{Request: fasthttp.Request{}}
|
||||||
c.RequestCtx = &fasthttp.RequestCtx{Request: request}
|
|
||||||
c.Request.Header.Set("H1", "v1")
|
c.Request.Header.Set("H1", "v1")
|
||||||
c.Request.Header.Set("H2", "v2")
|
c.Request.Header.Set("H2", "v2")
|
||||||
m := map[string]string{}
|
m := map[string]string{}
|
||||||
|
|
@ -320,7 +320,6 @@ func TestV1DirectMessagingEndpointsWithTracer(t *testing.T) {
|
||||||
mockDirectMessaging.AssertNumberOfCalls(t, "Invoke", 1)
|
mockDirectMessaging.AssertNumberOfCalls(t, "Invoke", 1)
|
||||||
assert.Equal(t, 200, resp.StatusCode)
|
assert.Equal(t, 200, resp.StatusCode)
|
||||||
assert.Equal(t, "0", buffer, "failed to generate proper traces with invoke")
|
assert.Equal(t, "0", buffer, "failed to generate proper traces with invoke")
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
fakeServer.Shutdown()
|
fakeServer.Shutdown()
|
||||||
|
|
@ -428,12 +427,12 @@ func TestV1ActorEndpoints(t *testing.T) {
|
||||||
|
|
||||||
fakeBodyArray := []byte{0x01, 0x02, 0x03, 0x06, 0x10}
|
fakeBodyArray := []byte{0x01, 0x02, 0x03, 0x06, 0x10}
|
||||||
|
|
||||||
fakeBodyObject := map[string]interface{}{
|
fakeResp := map[string]interface{}{
|
||||||
"data": "fakeData",
|
"data": "fakeData",
|
||||||
"data2": fakeBodyArray,
|
"data2": fakeBodyArray,
|
||||||
}
|
}
|
||||||
|
|
||||||
serializedByteArray, _ := json.Marshal(fakeBodyObject)
|
serializedByteArray, _ := json.Marshal(fakeResp)
|
||||||
|
|
||||||
encodedLen := base64.StdEncoding.EncodedLen(len(fakeBodyArray))
|
encodedLen := base64.StdEncoding.EncodedLen(len(fakeBodyArray))
|
||||||
base64Encoded := make([]byte, encodedLen)
|
base64Encoded := make([]byte, encodedLen)
|
||||||
|
|
@ -554,14 +553,14 @@ func TestV1ActorEndpoints(t *testing.T) {
|
||||||
apiPath := "v1.0/actors/fakeActorType/fakeActorID/state"
|
apiPath := "v1.0/actors/fakeActorType/fakeActorID/state"
|
||||||
|
|
||||||
testTransactionalOperations := []actors.TransactionalOperation{
|
testTransactionalOperations := []actors.TransactionalOperation{
|
||||||
actors.TransactionalOperation{
|
{
|
||||||
Operation: actors.Upsert,
|
Operation: actors.Upsert,
|
||||||
Request: map[string]interface{}{
|
Request: map[string]interface{}{
|
||||||
"key": "fakeKey1",
|
"key": "fakeKey1",
|
||||||
"value": fakeBodyObject,
|
"value": fakeBodyObject,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
actors.TransactionalOperation{
|
{
|
||||||
Operation: actors.Delete,
|
Operation: actors.Delete,
|
||||||
Request: map[string]interface{}{
|
Request: map[string]interface{}{
|
||||||
"key": "fakeKey1",
|
"key": "fakeKey1",
|
||||||
|
|
@ -722,12 +721,12 @@ func TestV1ActorEndpointsWithTracer(t *testing.T) {
|
||||||
|
|
||||||
fakeBodyArray := []byte{0x01, 0x02, 0x03, 0x06, 0x10}
|
fakeBodyArray := []byte{0x01, 0x02, 0x03, 0x06, 0x10}
|
||||||
|
|
||||||
fakeBodyObject := map[string]interface{}{
|
fakeObj := map[string]interface{}{
|
||||||
"data": "fakeData",
|
"data": "fakeData",
|
||||||
"data2": fakeBodyArray,
|
"data2": fakeBodyArray,
|
||||||
}
|
}
|
||||||
|
|
||||||
serializedByteArray, _ := json.Marshal(fakeBodyObject)
|
serializedByteArray, _ := json.Marshal(fakeObj)
|
||||||
|
|
||||||
encodedLen := base64.StdEncoding.EncodedLen(len(fakeBodyArray))
|
encodedLen := base64.StdEncoding.EncodedLen(len(fakeBodyArray))
|
||||||
base64Encoded := make([]byte, encodedLen)
|
base64Encoded := make([]byte, encodedLen)
|
||||||
|
|
@ -857,14 +856,14 @@ func TestV1ActorEndpointsWithTracer(t *testing.T) {
|
||||||
apiPath := "v1.0/actors/fakeActorType/fakeActorID/state"
|
apiPath := "v1.0/actors/fakeActorType/fakeActorID/state"
|
||||||
|
|
||||||
testTransactionalOperations := []actors.TransactionalOperation{
|
testTransactionalOperations := []actors.TransactionalOperation{
|
||||||
actors.TransactionalOperation{
|
{
|
||||||
Operation: actors.Upsert,
|
Operation: actors.Upsert,
|
||||||
Request: map[string]interface{}{
|
Request: map[string]interface{}{
|
||||||
"key": "fakeKey1",
|
"key": "fakeKey1",
|
||||||
"value": fakeBodyObject,
|
"value": fakeBodyObject,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
actors.TransactionalOperation{
|
{
|
||||||
Operation: actors.Delete,
|
Operation: actors.Delete,
|
||||||
Request: map[string]interface{}{
|
Request: map[string]interface{}{
|
||||||
"key": "fakeKey1",
|
"key": "fakeKey1",
|
||||||
|
|
@ -993,6 +992,7 @@ func (f *fakeHTTPServer) DoRequest(method, path string, body []byte, params map[
|
||||||
}
|
}
|
||||||
|
|
||||||
bodyBytes, _ := ioutil.ReadAll(res.Body)
|
bodyBytes, _ := ioutil.ReadAll(res.Body)
|
||||||
|
defer res.Body.Close()
|
||||||
response := fakeHTTPResponse{
|
response := fakeHTTPResponse{
|
||||||
StatusCode: res.StatusCode,
|
StatusCode: res.StatusCode,
|
||||||
ContentType: res.Header.Get("Content-Type"),
|
ContentType: res.Header.Get("Content-Type"),
|
||||||
|
|
@ -1037,7 +1037,7 @@ func TestV1StateEndpoints(t *testing.T) {
|
||||||
})
|
})
|
||||||
t.Run("Update state - No ETag", func(t *testing.T) {
|
t.Run("Update state - No ETag", func(t *testing.T) {
|
||||||
apiPath := "v1.0/state"
|
apiPath := "v1.0/state"
|
||||||
request := []state.SetRequest{state.SetRequest{
|
request := []state.SetRequest{{
|
||||||
Key: "good-key",
|
Key: "good-key",
|
||||||
ETag: "",
|
ETag: "",
|
||||||
}}
|
}}
|
||||||
|
|
@ -1049,7 +1049,7 @@ func TestV1StateEndpoints(t *testing.T) {
|
||||||
})
|
})
|
||||||
t.Run("Update state - Matching ETag", func(t *testing.T) {
|
t.Run("Update state - Matching ETag", func(t *testing.T) {
|
||||||
apiPath := "v1.0/state"
|
apiPath := "v1.0/state"
|
||||||
request := []state.SetRequest{state.SetRequest{
|
request := []state.SetRequest{{
|
||||||
Key: "good-key",
|
Key: "good-key",
|
||||||
ETag: etag,
|
ETag: etag,
|
||||||
}}
|
}}
|
||||||
|
|
@ -1061,7 +1061,7 @@ func TestV1StateEndpoints(t *testing.T) {
|
||||||
})
|
})
|
||||||
t.Run("Update state - Wrong ETag", func(t *testing.T) {
|
t.Run("Update state - Wrong ETag", func(t *testing.T) {
|
||||||
apiPath := "v1.0/state"
|
apiPath := "v1.0/state"
|
||||||
request := []state.SetRequest{state.SetRequest{
|
request := []state.SetRequest{{
|
||||||
Key: "good-key",
|
Key: "good-key",
|
||||||
ETag: "BAD ETAG",
|
ETag: "BAD ETAG",
|
||||||
}}
|
}}
|
||||||
|
|
@ -1107,7 +1107,7 @@ func TestV1StateEndpoints(t *testing.T) {
|
||||||
t.Run("Set state - With Retries", func(t *testing.T) {
|
t.Run("Set state - With Retries", func(t *testing.T) {
|
||||||
apiPath := "v1.0/state"
|
apiPath := "v1.0/state"
|
||||||
retryCounter = 0
|
retryCounter = 0
|
||||||
request := []state.SetRequest{state.SetRequest{
|
request := []state.SetRequest{{
|
||||||
Key: "failed-key",
|
Key: "failed-key",
|
||||||
ETag: "BAD ETAG",
|
ETag: "BAD ETAG",
|
||||||
Options: state.SetStateOption{
|
Options: state.SetStateOption{
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,6 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGetDaprID(t *testing.T) {
|
func TestGetDaprID(t *testing.T) {
|
||||||
|
|
||||||
t.Run("WithValidId", func(t *testing.T) {
|
t.Run("WithValidId", func(t *testing.T) {
|
||||||
// Arrange
|
// Arrange
|
||||||
expected := "test_id"
|
expected := "test_id"
|
||||||
|
|
@ -41,7 +40,6 @@ func TestGetDaprID(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIsAnnotatedForDapr(t *testing.T) {
|
func TestIsAnnotatedForDapr(t *testing.T) {
|
||||||
|
|
||||||
t.Run("Enabled", func(t *testing.T) {
|
t.Run("Enabled", func(t *testing.T) {
|
||||||
// Arrange
|
// Arrange
|
||||||
expected := "true"
|
expected := "true"
|
||||||
|
|
@ -66,7 +64,6 @@ func TestIsAnnotatedForDapr(t *testing.T) {
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
assert.False(t, got)
|
assert.False(t, got)
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Invalid", func(t *testing.T) {
|
t.Run("Invalid", func(t *testing.T) {
|
||||||
|
|
@ -83,14 +80,13 @@ func TestIsAnnotatedForDapr(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func getDeployment(daprId string, daprEnabled string) *appsv1.Deployment {
|
func getDeployment(daprID string, daprEnabled string) *appsv1.Deployment {
|
||||||
|
|
||||||
// Arrange
|
// Arrange
|
||||||
metadata := meta_v1.ObjectMeta{
|
metadata := meta_v1.ObjectMeta{
|
||||||
Name: "app",
|
Name: "app",
|
||||||
Labels: map[string]string{"app": "test_app"},
|
Labels: map[string]string{"app": "test_app"},
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
daprIDAnnotationKey: daprId,
|
daprIDAnnotationKey: daprID,
|
||||||
daprEnabledAnnotationKey: daprEnabled,
|
daprEnabledAnnotationKey: daprEnabled,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,7 @@ func TestInitPubSub(t *testing.T) {
|
||||||
rt.appChannel = mockAppChannel
|
rt.appChannel = mockAppChannel
|
||||||
|
|
||||||
// User App subscribes 2 topics via http app channel
|
// User App subscribes 2 topics via http app channel
|
||||||
fakeHttpResponse := &channel.InvokeResponse{
|
fakeHTTPResponse := &channel.InvokeResponse{
|
||||||
Metadata: map[string]string{http_channel.HTTPStatusCode: "200"},
|
Metadata: map[string]string{http_channel.HTTPStatusCode: "200"},
|
||||||
Data: []byte("[ \"topic0\", \"topic1\" ]"),
|
Data: []byte("[ \"topic0\", \"topic1\" ]"),
|
||||||
}
|
}
|
||||||
|
|
@ -102,7 +102,7 @@ func TestInitPubSub(t *testing.T) {
|
||||||
&channel.InvokeRequest{
|
&channel.InvokeRequest{
|
||||||
Method: "dapr/subscribe",
|
Method: "dapr/subscribe",
|
||||||
Metadata: map[string]string{http_channel.HTTPVerb: http_channel.Get},
|
Metadata: map[string]string{http_channel.HTTPVerb: http_channel.Get},
|
||||||
}).Return(fakeHttpResponse, nil)
|
}).Return(fakeHTTPResponse, nil)
|
||||||
|
|
||||||
// act
|
// act
|
||||||
err := rt.initPubSub()
|
err := rt.initPubSub()
|
||||||
|
|
@ -120,7 +120,7 @@ func TestInitPubSub(t *testing.T) {
|
||||||
mockAppChannel := new(channelt.MockAppChannel)
|
mockAppChannel := new(channelt.MockAppChannel)
|
||||||
rt.appChannel = mockAppChannel
|
rt.appChannel = mockAppChannel
|
||||||
|
|
||||||
fakeHttpResponse := &channel.InvokeResponse{
|
fakeHTTPResponse := &channel.InvokeResponse{
|
||||||
Metadata: map[string]string{http_channel.HTTPStatusCode: "404"},
|
Metadata: map[string]string{http_channel.HTTPStatusCode: "404"},
|
||||||
Data: nil,
|
Data: nil,
|
||||||
}
|
}
|
||||||
|
|
@ -130,7 +130,7 @@ func TestInitPubSub(t *testing.T) {
|
||||||
&channel.InvokeRequest{
|
&channel.InvokeRequest{
|
||||||
Method: "dapr/subscribe",
|
Method: "dapr/subscribe",
|
||||||
Metadata: map[string]string{http_channel.HTTPVerb: http_channel.Get},
|
Metadata: map[string]string{http_channel.HTTPVerb: http_channel.Get},
|
||||||
}).Return(fakeHttpResponse, nil)
|
}).Return(fakeHTTPResponse, nil)
|
||||||
|
|
||||||
// act
|
// act
|
||||||
err := rt.initPubSub()
|
err := rt.initPubSub()
|
||||||
|
|
@ -215,7 +215,7 @@ func TestInitSecretStores(t *testing.T) {
|
||||||
func TestMetadataItemsToPropertiesConversion(t *testing.T) {
|
func TestMetadataItemsToPropertiesConversion(t *testing.T) {
|
||||||
rt := NewTestDaprRuntime(modes.StandaloneMode)
|
rt := NewTestDaprRuntime(modes.StandaloneMode)
|
||||||
items := []components_v1alpha1.MetadataItem{
|
items := []components_v1alpha1.MetadataItem{
|
||||||
components_v1alpha1.MetadataItem{
|
{
|
||||||
Name: "a",
|
Name: "a",
|
||||||
Value: "b",
|
Value: "b",
|
||||||
},
|
},
|
||||||
|
|
@ -233,14 +233,14 @@ func TestProcessComponentSecrets(t *testing.T) {
|
||||||
Spec: components_v1alpha1.ComponentSpec{
|
Spec: components_v1alpha1.ComponentSpec{
|
||||||
Type: "bindings.mock",
|
Type: "bindings.mock",
|
||||||
Metadata: []components_v1alpha1.MetadataItem{
|
Metadata: []components_v1alpha1.MetadataItem{
|
||||||
components_v1alpha1.MetadataItem{
|
{
|
||||||
Name: "a",
|
Name: "a",
|
||||||
SecretKeyRef: components_v1alpha1.SecretKeyRef{
|
SecretKeyRef: components_v1alpha1.SecretKeyRef{
|
||||||
Key: "key1",
|
Key: "key1",
|
||||||
Name: "name1",
|
Name: "name1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
components_v1alpha1.MetadataItem{
|
{
|
||||||
Name: "b",
|
Name: "b",
|
||||||
Value: "value2",
|
Value: "value2",
|
||||||
},
|
},
|
||||||
|
|
@ -331,14 +331,14 @@ func TestInitSecretStoresInKubernetesMode(t *testing.T) {
|
||||||
Spec: components_v1alpha1.ComponentSpec{
|
Spec: components_v1alpha1.ComponentSpec{
|
||||||
Type: "secretstores.fake.secretstore",
|
Type: "secretstores.fake.secretstore",
|
||||||
Metadata: []components_v1alpha1.MetadataItem{
|
Metadata: []components_v1alpha1.MetadataItem{
|
||||||
components_v1alpha1.MetadataItem{
|
{
|
||||||
Name: "a",
|
Name: "a",
|
||||||
SecretKeyRef: components_v1alpha1.SecretKeyRef{
|
SecretKeyRef: components_v1alpha1.SecretKeyRef{
|
||||||
Key: "key1",
|
Key: "key1",
|
||||||
Name: "name1",
|
Name: "name1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
components_v1alpha1.MetadataItem{
|
{
|
||||||
Name: "b",
|
Name: "b",
|
||||||
Value: "value2",
|
Value: "value2",
|
||||||
},
|
},
|
||||||
|
|
@ -380,12 +380,12 @@ func TestOnNewPublishedMessage(t *testing.T) {
|
||||||
mockAppChannel := new(channelt.MockAppChannel)
|
mockAppChannel := new(channelt.MockAppChannel)
|
||||||
rt.appChannel = mockAppChannel
|
rt.appChannel = mockAppChannel
|
||||||
|
|
||||||
fakeHttpResponse := &channel.InvokeResponse{
|
fakeHTTPResponse := &channel.InvokeResponse{
|
||||||
Metadata: map[string]string{http_channel.HTTPStatusCode: "200"},
|
Metadata: map[string]string{http_channel.HTTPStatusCode: "200"},
|
||||||
Data: []byte("OK"),
|
Data: []byte("OK"),
|
||||||
}
|
}
|
||||||
|
|
||||||
mockAppChannel.On("InvokeMethod", expectedRequest).Return(fakeHttpResponse, nil)
|
mockAppChannel.On("InvokeMethod", expectedRequest).Return(fakeHTTPResponse, nil)
|
||||||
|
|
||||||
// act
|
// act
|
||||||
err := rt.publishMessageHTTP(testPubSubMessage)
|
err := rt.publishMessageHTTP(testPubSubMessage)
|
||||||
|
|
@ -401,14 +401,14 @@ func TestOnNewPublishedMessage(t *testing.T) {
|
||||||
|
|
||||||
clientError := errors.New("Internal Error")
|
clientError := errors.New("Internal Error")
|
||||||
|
|
||||||
fakeHttpResponse := &channel.InvokeResponse{
|
fakeHTPResponse := &channel.InvokeResponse{
|
||||||
Metadata: map[string]string{http_channel.HTTPStatusCode: "500"},
|
Metadata: map[string]string{http_channel.HTTPStatusCode: "500"},
|
||||||
Data: []byte(clientError.Error()),
|
Data: []byte(clientError.Error()),
|
||||||
}
|
}
|
||||||
|
|
||||||
expectedClientError := fmt.Errorf("error from app consumer: Internal Error")
|
expectedClientError := fmt.Errorf("error from app consumer: Internal Error")
|
||||||
|
|
||||||
mockAppChannel.On("InvokeMethod", expectedRequest).Return(fakeHttpResponse, clientError)
|
mockAppChannel.On("InvokeMethod", expectedRequest).Return(fakeHTPResponse, clientError)
|
||||||
|
|
||||||
// act
|
// act
|
||||||
err := rt.publishMessageHTTP(testPubSubMessage)
|
err := rt.publishMessageHTTP(testPubSubMessage)
|
||||||
|
|
@ -429,15 +429,15 @@ func getFakeProperties() map[string]string {
|
||||||
|
|
||||||
func getFakeMetadataItems() []components_v1alpha1.MetadataItem {
|
func getFakeMetadataItems() []components_v1alpha1.MetadataItem {
|
||||||
return []components_v1alpha1.MetadataItem{
|
return []components_v1alpha1.MetadataItem{
|
||||||
components_v1alpha1.MetadataItem{
|
{
|
||||||
Name: "host",
|
Name: "host",
|
||||||
Value: "localhost",
|
Value: "localhost",
|
||||||
},
|
},
|
||||||
components_v1alpha1.MetadataItem{
|
{
|
||||||
Name: "password",
|
Name: "password",
|
||||||
Value: "fakePassword",
|
Value: "fakePassword",
|
||||||
},
|
},
|
||||||
components_v1alpha1.MetadataItem{
|
{
|
||||||
Name: "consumerID",
|
Name: "consumerID",
|
||||||
Value: TestRuntimeConfigID,
|
Value: TestRuntimeConfigID,
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue