@@ -8,10 +8,9 @@ import (
88 "strings"
99 "testing"
1010
11+ "github.com/gogf/gf/v2/container/gvar"
1112 "github.com/gogf/gf/v2/frame/g"
1213 "github.com/gogf/gf/v2/os/gcfg"
13-
14- hostconfigsvc "lina-core/internal/service/config"
1514)
1615
1716// TestHostConfigReadsAnyNonRootHostConfigKey verifies source plugins can read
@@ -26,7 +25,7 @@ plugin:
2625 storagePath: "temp/dynamic"
2726` )
2827
29- svc := New (hostconfigsvc . New () )
28+ svc := New (testRawHostConfigReader {} )
3029 ctx := context .Background ()
3130
3231 link , err := svc .String (ctx , "database.default.link" , "" )
@@ -54,7 +53,7 @@ workspace:
5453 basePath: "/admin"
5554` )
5655
57- svc := New (hostconfigsvc . New () )
56+ svc := New (testRawHostConfigReader {} )
5857 found , err := svc .Exists (context .Background (), "database.default.link" )
5958 if err != nil {
6059 t .Fatalf ("check missing host config key: %v" , err )
@@ -72,7 +71,7 @@ workspace:
7271 basePath: "/admin"
7372` )
7473
75- svc := New (hostconfigsvc . New () )
74+ svc := New (testRawHostConfigReader {} )
7675 value , err := svc .Get (context .Background (), "." )
7776 if err != nil {
7877 t .Fatalf ("read host config root: %v" , err )
@@ -102,17 +101,6 @@ func TestHostConfigRequiresInjectedRawReader(t *testing.T) {
102101 }
103102}
104103
105- // TestHostConfigRejectsServiceWithoutRawReads verifies accidental stand-ins
106- // cannot bypass the injected host config service contract.
107- func TestHostConfigRejectsServiceWithoutRawReads (t * testing.T ) {
108- svc := New (hostConfigServiceWithoutRawReads {})
109-
110- if _ , err := svc .Get (context .Background (), "workspace.basePath" ); err == nil ||
111- ! strings .Contains (err .Error (), "does not support raw reads" ) {
112- t .Fatalf ("expected service without raw reads to fail explicitly, got %v" , err )
113- }
114- }
115-
116104// setTestHostConfigAdapter swaps the process config adapter for one test case
117105// and restores the original adapter afterward.
118106func setTestHostConfigAdapter (t * testing.T , content string ) {
@@ -130,13 +118,10 @@ func setTestHostConfigAdapter(t *testing.T, content string) {
130118 })
131119}
132120
133- // hostConfigServiceWithoutRawReads satisfies the broad host config service
134- // contract but intentionally omits GetRaw for dependency-boundary tests.
135- type hostConfigServiceWithoutRawReads struct {
136- hostconfigsvc.Service
137- }
121+ // testRawHostConfigReader reads from the test-scoped GoFrame config adapter.
122+ type testRawHostConfigReader struct {}
138123
139- // GetWorkspaceBasePath returns a deterministic workspace base path .
140- func (hostConfigServiceWithoutRawReads ) GetWorkspaceBasePath ( context.Context ) string {
141- return "/admin"
124+ // GetRaw returns one raw test config value through the active GoFrame adapter .
125+ func (testRawHostConfigReader ) GetRaw ( ctx context.Context , key string ) ( * gvar. Var , error ) {
126+ return g . Cfg (). Get ( ctx , key )
142127}
0 commit comments