MCPcopy Index your code
hub / github.com/commitdev/zero / TestCreateProjectConfigFile

Function TestCreateProjectConfigFile

internal/config/projectconfig/init_test.go:15–55  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

13)
14
15func TestCreateProjectConfigFile(t *testing.T) {
16 const testDir = "../../test-sandbox"
17 projectName := "test-project"
18
19 projectconfig.SetRootDir(testDir)
20 defer os.RemoveAll(testDir)
21
22 testDirPath := path.Join(projectconfig.RootDir, projectName)
23
24 // create sandbox dir
25 err := os.MkdirAll(testDirPath, os.ModePerm)
26 if err != nil {
27 t.Fatal(err)
28 }
29
30 expectedConfig := &projectconfig.ZeroProjectConfig{
31 Name: projectName,
32 ShouldPushRepositories: false,
33 Modules: eksGoReactSampleModules(),
34 }
35 assert.NoError(t, projectconfig.CreateProjectConfigFile(projectconfig.RootDir, projectName, expectedConfig))
36
37 // make sure the file exists
38 if _, err := os.Stat(path.Join(testDirPath, constants.ZeroProjectYml)); err != nil {
39 t.Fatal(err)
40 }
41
42 t.Run("Should return a valid project config", func(t *testing.T) {
43 resultConfig := projectconfig.LoadConfig(path.Join(testDirPath, constants.ZeroProjectYml))
44
45 if !cmp.Equal(expectedConfig, resultConfig, cmpopts.EquateEmpty()) {
46 t.Errorf("projectconfig.ZeroProjectConfig.Unmarshal mismatch (-expected +result):\n%s", cmp.Diff(expectedConfig, resultConfig))
47 }
48 })
49
50 t.Run("Should fail if modules are missing from project config", func(t *testing.T) {
51 expectedConfig.Modules = nil
52 assert.Error(t, projectconfig.CreateProjectConfigFile(projectconfig.RootDir, projectName, expectedConfig))
53 })
54
55}

Callers

nothing calls this directly

Calls 5

SetRootDirFunction · 0.92
CreateProjectConfigFileFunction · 0.92
LoadConfigFunction · 0.92
eksGoReactSampleModulesFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected