// TestGraph tests creating a graph using different ways
// that a base kustomization file can be referenced (e.g.)
//
// - ./singledot
// - justfolder
// - ../updirectory
TestGraph tests creating a graph using different ways
that a base kustomization file can be referenced

- ./singledot
- justfolder
- ../updirectory
// TestGraph tests creating a graph using different ways // that a base kustomization file can be referenced ( e . g . ) // // - . / singledot // - justfolder // - .. / updirectory
func TestGraph(t *testing.T) {
	   /app
	   ├── middle
	   │   └── kustomization.yaml
	   ├── same
	   │   └── kustomization.yaml
	   ├── base
	   │   └── kustomization.yaml
	   └── kustomization.yaml
	fakeFileSystem := afero.NewMemMapFs()
	 Setup 'app' folder
	err := fakeFileSystem.Mkdir("app", 0755)
	appKustomizationFileContents := `
bases:
- same
- ./middle
`
	afero.WriteFile(fakeFileSystem, "app/kustomization.yaml", []byte(appKustomizationFileContents), 0644)
	 Setup 'same' folder
	fakeFileSystem.Mkdir("app/same", 0755)
	sameKustomizationFileContents := ""
	afero.WriteFile(fakeFileSystem, "app/same/kustomization.yaml", []byte(sameKustomizationFileContents), 0644)
	 Setup 'middle' folder
	fakeFileSystem.Mkdir("app/middle", 0755)
	middleKustomizationFileContents := `
bases:
- ../base
`
	afero.WriteFile(fakeFileSystem, "app/middle/kustomization.yaml", []byte(middleKustomizationFileContents), 0644)
	 Setup 'base' folder
	fakeFileSystem.Mkdir("app/base", 0755)
	baseKustomizationFileContents := ""
	afero.WriteFile(fakeFileSystem, "app/base/kustomization.yaml", []byte(baseKustomizationFileContents), 0644)
	graphContext := New("main")
	kustomizationFileContext := kustomizationfile.NewFromFileSystem(fakeFileSystem)
	err = graphContext.buildGraph(kustomizationFileContext, "app", "")
	if err != nil {
		t.Fatalf("Could not generate graph %v.", err)
	}
	 Verify all of the expected nodes are present in the graph
	expectedNodes := []string{
		wrapElement("app"),
		wrapElement("app/same"),
		wrapElement("app/middle"),
		wrapElement("app/base"),
	}
	for _, node := range expectedNodes {
		if !graphContext.IsNode(node) {
			t.Errorf("Expected node %v was not found", node)
		}
	}
	 Verify all of the expected edges are present and their directions are correct
	appFolderEdges := graphContext.Edges.SrcToDsts[wrapElement("app")]
	if _, exists := appFolderEdges[wrapElement("app/middle")]; !exists {
		t.Errorf("Expected edge [app -> app/middle] was not found")
	}
	if _, exists := appFolderEdges[wrapElement("app/same")]; !exists {
		t.Errorf("Expected edge [app -> app/same] was not found")
	}
	middleFolderEdges := graphContext.Edges.SrcToDsts[wrapElement("app/middle")]
	if _, exists := middleFolderEdges[wrapElement("app/base")]; !exists {
		t.Errorf("Expected edge [app/middle -> app/base] was not found")
	}
}
func TestGraph ( t * testing . T ) { fakeFileSystem := afero . NewMemMapFs ( ) err := fakeFileSystem . Mkdir ( " " , 0755 ) appKustomizationFileContents := `
bases:
- same
- ./middle
` afero . WriteFile ( fakeFileSystem , " " , [ ] byte ( appKustomizationFileContents ) , 0644 ) fakeFileSystem . Mkdir ( " " , 0755 ) sameKustomizationFileContents := " " afero . WriteFile ( fakeFileSystem , " " , [ ] byte ( sameKustomizationFileContents ) , 0644 ) fakeFileSystem . Mkdir ( " " , 0755 ) middleKustomizationFileContents := `
bases:
- ../base
` afero . WriteFile ( fakeFileSystem , " " , [ ] byte ( middleKustomizationFileContents ) , 0644 ) fakeFileSystem . Mkdir ( " " , 0755 ) baseKustomizationFileContents := " " afero . WriteFile ( fakeFileSystem , " " , [ ] byte ( baseKustomizationFileContents ) , 0644 ) graphContext := New ( " " ) kustomizationFileContext := kustomizationfile . NewFromFileSystem ( fakeFileSystem ) err = graphContext . buildGraph ( kustomizationFileContext , " " , " " ) if err != nil { t . Fatalf ( " " , err ) } expectedNodes := [ ] string { wrapElement ( " " ) , wrapElement ( " " ) , wrapElement ( " " ) , wrapElement ( " " ) , } for _ , node := range expectedNodes { if ! graphContext . IsNode ( node ) { t . Errorf ( " " , node ) } } appFolderEdges := graphContext . Edges . SrcToDsts [ wrapElement ( " " ) ] if _ , exists := appFolderEdges [ wrapElement ( " " ) ] ; ! exists { t . Errorf ( " " ) } if _ , exists := appFolderEdges [ wrapElement ( " " ) ] ; ! exists { t . Errorf ( " " ) } middleFolderEdges := graphContext . Edges . SrcToDsts [ wrapElement ( " " ) ] if _ , exists := middleFolderEdges [ wrapElement ( " " ) ] ; ! exists { t . Errorf ( " " ) } }
TestGraph tests creating a graph using different ways
that a base kustomization file can be referenced
TestGraph tests creating a graph using different ways that a base kustomization file can be referenced
// Folder structure for this test // //   /app //   ├── middle //   │   └── kustomization.yaml //   ├── same //   │   └── kustomization.yaml //   ├── base //   │   └── kustomization.yaml //   └── kustomization.yaml // // Setup 'app' folder // Setup 'same' folder // Setup 'middle' folder // Setup 'base' folder // Verify all of the expected nodes are present in the graph // Verify all of the expected edges are present and their directions are correct