forked from ipdxco/github-as-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync.test.ts
More file actions
87 lines (71 loc) · 2.27 KB
/
sync.test.ts
File metadata and controls
87 lines (71 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import 'reflect-metadata'
import * as YAML from 'yaml'
import {Config} from '../src/yaml/config.js'
import {State} from '../src/terraform/state.js'
import {sync} from '../src/sync.js'
import {Resource} from '../src/resources/resource.js'
import {RepositoryFile} from '../src/resources/repository-file.js'
import {StateSchema} from '../src/terraform/schema.js'
import {toggleArchivedRepos} from '../src/actions/shared/toggle-archived-repos.js'
import {before, describe, it, mock} from 'node:test'
import assert from 'node:assert'
import {mockGitHub} from './github.js'
describe('sync', () => {
before(() => {
mockGitHub()
})
it('sync', async () => {
const yamlConfig = new Config('{}')
const tfConfig = await State.New()
const expectedYamlConfig = Config.FromPath()
await sync(tfConfig, yamlConfig)
await toggleArchivedRepos(tfConfig, yamlConfig)
yamlConfig.format()
assert.equal(yamlConfig.toString(), expectedYamlConfig.toString())
})
it('sync new repository file', async () => {
const yamlSource = {
repositories: {
blog: {
files: {
'README.md': {
content: 'Hello, world!'
}
}
}
}
}
const tfSource: StateSchema = {
values: {
root_module: {
resources: []
}
}
}
const yamlConfig = new Config(YAML.stringify(yamlSource))
const tfConfig = new State(JSON.stringify(tfSource))
mock.module('../src/terraform/state.js', {
namedExports: {
loadState: async () => JSON.stringify(tfSource)
}
})
tfConfig.addResource = async (id: string, resource: Resource) => {
tfSource?.values?.root_module?.resources?.push({
mode: 'managed',
index: id,
address: resource.getStateAddress(),
type: RepositoryFile.StateType,
values: {
repository: (resource as RepositoryFile).repository,
file: (resource as RepositoryFile).file,
content: (resource as RepositoryFile).content ?? '',
...resource
}
})
}
const expectedYamlConfig = new Config(YAML.stringify(yamlSource))
await sync(tfConfig, yamlConfig)
yamlConfig.format()
assert.equal(yamlConfig.toString(), expectedYamlConfig.toString())
})
})