Skip to content

Commit 11daf8d

Browse files
authored
feat: add more domain paths for the config dirs and files (#308)
This change adds more paths for the domain config dirs and files so they can be called on the domain struct. This aims to provide a way to access the expected paths for the domain config dirs and files.
1 parent 54bfa2f commit 11daf8d

File tree

5 files changed

+164
-68
lines changed

5 files changed

+164
-68
lines changed

.changeset/crazy-moose-warn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"chainlink-deployments-framework": minor
3+
---
4+
5+
Adds additional config related file path getter methods to Domains

engine/cld/domain/domain.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,28 @@ func (d Domain) InternalDirPath() string {
110110
func (d Domain) CmdDirPath() string {
111111
return filepath.Join(d.DirPath(), CmdDirName)
112112
}
113+
114+
// ConfigDirPath returns the path to the domain config directory within the domain.
115+
func (d Domain) ConfigDirPath() string {
116+
return filepath.Join(d.DirPath(), DomainConfigDirName)
117+
}
118+
119+
// ConfigLocalDirPath returns the path where local execution config files are stored.
120+
func (d Domain) ConfigLocalDirPath() string {
121+
return filepath.Join(d.ConfigDirPath(), DomainConfigLocalDirName)
122+
}
123+
124+
// ConfigLocalFileName returns the path to a domain environment's local execution config file.
125+
func (d Domain) ConfigLocalFileName(env string) string {
126+
return filepath.Join(d.ConfigLocalDirPath(), "config."+env+".yaml")
127+
}
128+
129+
// ConfigNetworksFilePath returns the path where the domain's networks config files are stored.
130+
func (d Domain) ConfigNetworksFilePath() string {
131+
return filepath.Join(d.ConfigDirPath(), DomainConfigNetworksDirName)
132+
}
133+
134+
// ConfigCIDirPath returns the path where the domain's CI .env files are stored.
135+
func (d Domain) ConfigCIDirPath() string {
136+
return filepath.Join(d.ConfigDirPath(), DomainConfigCIDirName)
137+
}

engine/cld/domain/domain_test.go

Lines changed: 30 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,36 @@ func Test_Domain_CmdDirPath(t *testing.T) {
205205
assert.Equal(t, "domains/ccip/cmd", d.CmdDirPath())
206206
}
207207

208+
func Test_Domain_ConfigDirPath(t *testing.T) {
209+
t.Parallel()
210+
d := NewDomain("domains", "ccip")
211+
assert.Equal(t, "domains/ccip/.config", d.ConfigDirPath())
212+
}
213+
214+
func Test_Domain_ConfigLocalDirPath(t *testing.T) {
215+
t.Parallel()
216+
d := NewDomain("domains", "ccip")
217+
assert.Equal(t, "domains/ccip/.config/local", d.ConfigLocalDirPath())
218+
}
219+
220+
func Test_Domain_ConfigLocalFileName(t *testing.T) {
221+
t.Parallel()
222+
d := NewDomain("domains", "ccip")
223+
assert.Equal(t, "domains/ccip/.config/local/config.staging.yaml", d.ConfigLocalFileName("staging"))
224+
}
225+
226+
func Test_Domain_ConfigNetworksFilePath(t *testing.T) {
227+
t.Parallel()
228+
d := NewDomain("domains", "ccip")
229+
assert.Equal(t, "domains/ccip/.config/networks", d.ConfigNetworksFilePath())
230+
}
231+
232+
func Test_Domain_ConfigCIDirPath(t *testing.T) {
233+
t.Parallel()
234+
d := NewDomain("domains", "ccip")
235+
assert.Equal(t, "domains/ccip/.config/ci", d.ConfigCIDirPath())
236+
}
237+
208238
// todo: uncomment after moving migration registry over to cldf
209239
// func Test_EnvDir_LatestExecutedMigration(t *testing.T) {
210240
// t.Parallel()
@@ -237,49 +267,3 @@ func Test_Domain_CmdDirPath(t *testing.T) {
237267
// require.NoError(t, err)
238268
// require.Equal(t, "0002_second", got)
239269
// }
240-
241-
// todo: uncomment after moving view state over to cldf
242-
// func Test_EnvDir_SaveViewState(t *testing.T) {
243-
// t.Parallel()
244-
//
245-
// tests := []struct {
246-
// name string
247-
// giveState json.Marshaler
248-
// want string
249-
// wantErr string
250-
// }{
251-
// {
252-
// name: "success",
253-
// giveState: &testMarshaler{
254-
// Name: "test",
255-
// },
256-
// want: `{"Name":"test"}`,
257-
// },
258-
// {
259-
// name: "save error",
260-
// giveState: &failedMarshaler{},
261-
// wantErr: "unable to marshal state",
262-
// },
263-
// }
264-
//
265-
// for _, tt := range tests {
266-
// t.Run(tt.name, func(t *testing.T) {
267-
// t.Parallel()
268-
//
269-
// fixture := setupTestDomainsFS(t)
270-
//
271-
// err := fixture.envDir.SaveViewState(tt.giveState)
272-
//
273-
// if tt.wantErr != "" {
274-
// require.Error(t, err)
275-
// assert.ErrorContains(t, err, tt.wantErr)
276-
// } else {
277-
// require.NoError(t, err)
278-
// b, err := os.ReadFile(fixture.envDir.ViewStateFilePath())
279-
// require.NoError(t, err)
280-
//
281-
// assert.JSONEq(t, tt.want, string(b))
282-
// }
283-
// })
284-
// }
285-
// }

engine/cld/domain/envdir_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package domain
22

33
import (
4+
"encoding/json"
45
"fmt"
56
"os"
67
"path/filepath"
@@ -1327,3 +1328,48 @@ func Test_EnvDir_SaveFile(t *testing.T) {
13271328
})
13281329
}
13291330
}
1331+
1332+
func Test_EnvDir_SaveViewState(t *testing.T) {
1333+
t.Parallel()
1334+
1335+
tests := []struct {
1336+
name string
1337+
giveState json.Marshaler
1338+
want string
1339+
wantErr string
1340+
}{
1341+
{
1342+
name: "success",
1343+
giveState: &testMarshaler{
1344+
Name: "test",
1345+
},
1346+
want: `{"Name":"test"}`,
1347+
},
1348+
{
1349+
name: "save error",
1350+
giveState: &failedMarshaler{},
1351+
wantErr: "unable to marshal state",
1352+
},
1353+
}
1354+
1355+
for _, tt := range tests {
1356+
t.Run(tt.name, func(t *testing.T) {
1357+
t.Parallel()
1358+
1359+
fixture := setupTestDomainsFS(t)
1360+
1361+
err := fixture.envDir.SaveViewState(tt.giveState)
1362+
1363+
if tt.wantErr != "" {
1364+
require.Error(t, err)
1365+
assert.ErrorContains(t, err, tt.wantErr)
1366+
} else {
1367+
require.NoError(t, err)
1368+
b, err := os.ReadFile(fixture.envDir.ViewStateFilePath())
1369+
require.NoError(t, err)
1370+
1371+
assert.JSONEq(t, tt.want, string(b))
1372+
}
1373+
})
1374+
}
1375+
}

engine/cld/domain/paths.go

Lines changed: 58 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,90 @@
11
package domain
22

33
const (
4-
// LibDirName is the standard name of the directory containing the domain's lib directory.
4+
// LibDirName is the name of the directory containing the domain's lib directory.
55
LibDirName = "lib"
6-
// InternalDirName is the standard name of the directory containing the domain's internal directory.
6+
7+
// InternalDirName is the name of the directory containing the domain's internal directory.
78
InternalDirName = "internal"
8-
// CmdDirName is the standard name of the directory containing the domain's cmd directory.
9+
10+
// CmdDirName is the name of the directory containing the domain's cmd directory.
911
CmdDirName = "cmd"
10-
// AddressBookFileName is the standard name of the file containing the address book.
12+
13+
// AddressBookFileName is the name of the file containing the address book.
1114
AddressBookFileName = "addresses.json"
12-
// ArchivedProposalsDirName is the standard name of the directory containing archived proposals.
15+
16+
// ArchivedProposalsDirName is the name of the directory containing archived proposals.
1317
ArchivedProposalsDirName = "archived_proposals"
14-
// ArtifactsDirName is the standard name of the directory containing migration artifacts.
18+
19+
// ArtifactsDirName is the name of the directory containing migration artifacts.
1520
ArtifactsDirName = "artifacts"
16-
// DarastoreDirName is the standard name of the directory containing the datastore files.
21+
22+
// DarastoreDirName is the name of the directory containing the datastore files.
1723
DatastoreDirName = "datastore"
18-
// DataStoreFileName is the standard name of the file containing the datastore.
24+
25+
// DataStoreFileName is the name of the file containing the datastore.
1926
DataStoreFileName = "datastore.json"
20-
// AddressRefsFileName is the standard name of the file containing the address refs.
27+
28+
// AddressRefsFileName is the name of the file containing the address refs.
2129
AddressRefsFileName = "address_refs.json"
22-
// ChainMetadataFileName is the standard name of the file containing the chain metadata.
30+
31+
// ChainMetadataFileName is the name of the file containing the chain metadata.
2332
ChainMetadataFileName = "chain_metadata.json"
24-
// ContractMetadataFileName is the standard name of the file containing the contract metadata.
33+
34+
// ContractMetadataFileName is the name of the file containing the contract metadata.
2535
ContractMetadataFileName = "contract_metadata.json"
26-
// EnvMetadataFileName is the standard name of the file containing the environment metadata.
36+
37+
// DomainConfigDirName is the name of the directory containing the domain's config directory.
38+
DomainConfigDirName = ".config"
39+
40+
// DomainConfigLocalDirName is the name of the directory containing the local domain config.
41+
DomainConfigLocalDirName = "local"
42+
43+
// DomainConfigLocalFileName is the name of the file containing the local domain config.
44+
DomainConfigLocalFileName = "config.yml"
45+
46+
// DomainConfigNetworksDirName is the name of the directory containing the domain networks config.
47+
DomainConfigNetworksDirName = "networks"
48+
49+
// DomainConfigCIDirName is the name of the directory containing the domain CI config.
50+
DomainConfigCIDirName = "ci"
51+
52+
// EnvMetadataFileName is the name of the file containing the environment metadata.
2753
EnvMetadataFileName = "env_metadata.json"
28-
// NodesFileName is the standard name of the file containing node information in the
54+
55+
// NodesFileName is the name of the file containing node information in the
2956
// environment directory.
3057
NodesFileName = "nodes.json"
31-
// ProposalsDirName is the standard name of the directory containing proposals.
58+
59+
// ProposalsDirName is the name of the directory containing proposals.
3260
ProposalsDirName = "proposals"
33-
// DecodedProposalsDirName is the standard name of the directory containing decoded proposals.
61+
62+
// DecodedProposalsDirName is the name of the directory containing decoded proposals.
3463
DecodedProposalsDirName = "decoded_proposals"
35-
// DurablePipelinesFileName is the standard name of the file containing the durable pipelines for
64+
65+
// DurablePipelinesFileName is the name of the file containing the durable pipelines for
3666
// the environment.
3767
DurablePipelinesFileName = "durable_pipelines.go"
38-
// OperationsReportsDirName is the standard name of the directory containing operations reports.[
68+
69+
// OperationsReportsDirName is the name of the directory containing operations reports.[
3970
OperationsReportsDirName = "operations_reports"
40-
// ViewStateFileName is the standard name of the file containing the view state of the
71+
72+
// ViewStateFileName is the name of the file containing the view state of the
4173
// environment.
4274
ViewStateFileName = "state.json"
43-
// MigrationsFileName is the standard name of the file containing the migrations for the
75+
76+
// MigrationsFileName is the name of the file containing the migrations for the
4477
// environment.
4578
MigrationsFileName = "migrations.go"
46-
// MigrationsArchiveFileName is the standard name of the file containing the archived
79+
80+
// MigrationsArchiveFileName is the name of the file containing the archived
4781
// migrations for the environment.
4882
MigrationsArchiveFileName = "migrations_archive.go"
49-
// DurablePipelineDirName is the standard name of the directory containing durable pipelines.
83+
84+
// DurablePipelineDirName is the name of the directory containing durable pipelines.
5085
DurablePipelineDirName = "durable_pipelines"
51-
// DurablePipelineInputsDirName is the standard name of the directory containing the inputs
86+
87+
// DurablePipelineInputsDirName is the name of the directory containing the inputs
5288
// for the durable pipelines.
5389
DurablePipelineInputsDirName = "inputs"
5490
)

0 commit comments

Comments
 (0)