Skip to content

Commit 33d9aa8

Browse files
committed
fix ut
1 parent 66a2b7f commit 33d9aa8

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

components/hello/helloworld/helloworld_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import (
2020
"context"
2121
"testing"
2222

23+
"github.com/stretchr/testify/assert"
24+
2325
"mosn.io/layotto/components/pkg/common"
2426

2527
"mosn.io/layotto/components/hello"
@@ -59,4 +61,10 @@ func TestHelloWorld(t *testing.T) {
5961
if resp.HelloString != "Bye, Layotto" {
6062
t.Fatalf("hello output failed")
6163
}
64+
65+
component := hs.(common.InjectComponent)
66+
err = component.InjectConfigComponent(nil)
67+
assert.Nil(t, err)
68+
err = component.InjectSecretComponent(nil)
69+
assert.Nil(t, err)
6270
}

pkg/runtime/ref/injector_test.go

+21-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func TestInject(t *testing.T) {
3535
cf := &mock.MockStore{}
3636
container.ConfigRef["mock_config_store"] = cf
3737

38-
injector := DefaultInjector{Container: *container}
38+
injector := NewDefaultInjector(container.SecretRef, container.ConfigRef)
3939
meta := make(map[string]string)
4040

4141
var items []*ref.SecretRefConfig
@@ -59,5 +59,25 @@ func TestInject(t *testing.T) {
5959
injector.InjectSecretRef(items, meta)
6060
assert.Equal(t, meta["ref-key"], "life is good")
6161
assert.Equal(t, meta["good-key"], "life is good")
62+
secretStoreRef, err := injector.InjectSecretStoreRef(&ref.ComponentRefConfig{
63+
SecretStore: "fake_secret_store",
64+
})
65+
assert.Nil(t, err)
66+
assert.Equal(t, secretStoreRef, ss)
67+
68+
_, err = injector.InjectSecretStoreRef(&ref.ComponentRefConfig{
69+
SecretStore: "null",
70+
})
71+
assert.NotNil(t, err)
6272

73+
configStoreRef, err := injector.InjectConfigStoreRef(&ref.ComponentRefConfig{
74+
ConfigStore: "mock_config_store",
75+
})
76+
assert.Nil(t, err)
77+
assert.Equal(t, configStoreRef, cf)
78+
79+
_, err = injector.InjectConfigStoreRef(&ref.ComponentRefConfig{
80+
ConfigStore: "null",
81+
})
82+
assert.NotNil(t, err)
6383
}

0 commit comments

Comments
 (0)