refactored util_test.go to test on real files
Signed-off-by: Christian Goll <cgoll@suse.com>
This commit is contained in:
committed by
Jonathon Anderson
parent
242276bba9
commit
767be4fd8c
@@ -125,6 +125,9 @@ func OverlayInit(overlayName string) error {
|
||||
Build the given overlays for a node and create a Image for them
|
||||
*/
|
||||
func BuildOverlay(nodeInfo node.NodeInfo, context string, overlayNames []string) error {
|
||||
if len(overlayNames) == 0 {
|
||||
return nil
|
||||
}
|
||||
// create the dir where the overlay images will reside
|
||||
name := fmt.Sprintf("overlay %s/%v", nodeInfo.Id.Get(), overlayNames)
|
||||
overlayImage := OverlayImage(nodeInfo.Id.Get(), context, overlayNames)
|
||||
@@ -171,7 +174,7 @@ exists it will be created.
|
||||
*/
|
||||
func BuildOverlayIndir(nodeInfo node.NodeInfo, overlayNames []string, outputDir string) error {
|
||||
if len(overlayNames) == 0 {
|
||||
return errors.New("At least one valid overlay is needed to build for a node")
|
||||
return nil
|
||||
}
|
||||
if !util.IsDir(outputDir) {
|
||||
return errors.Errorf("output must a be a directory: %s", outputDir)
|
||||
@@ -188,10 +191,10 @@ func BuildOverlayIndir(nodeInfo node.NodeInfo, overlayNames []string, outputDir
|
||||
for _, overlayName := range overlayNames {
|
||||
wwlog.Verbose("Building overlay %s for node %s in %s", overlayName, nodeInfo.Id.Get(), outputDir)
|
||||
overlaySourceDir := OverlaySourceDir(overlayName)
|
||||
wwlog.Debug("Starting to build overlay %s\nChanging directory to OverlayDir: %s", overlayName, overlaySourceDir)
|
||||
wwlog.Debug("Changing directory to OverlayDir: %s", overlaySourceDir)
|
||||
err := os.Chdir(overlaySourceDir)
|
||||
if err != nil {
|
||||
return errors.Wrapf(ErrDoesNotExist, " name: %s", overlayName)
|
||||
return errors.Wrapf(ErrDoesNotExist, "directory: %s name: %s", overlaySourceDir, overlayName)
|
||||
}
|
||||
|
||||
wwlog.Verbose("Walking the overlay structure: %s", overlaySourceDir)
|
||||
|
||||
@@ -20,19 +20,20 @@ var buildOverlayTests = []struct {
|
||||
overlays []string
|
||||
image string
|
||||
contents []string
|
||||
hasFiles bool
|
||||
}{
|
||||
{"empty", "", "", nil, "", nil},
|
||||
{"empty node", "node1", "", nil, "", nil},
|
||||
{"empty context", "", "system", nil, "", nil},
|
||||
{"empty overlay", "", "", []string{"o1"}, "o1.img", []string{"o1.txt"}},
|
||||
{"single overlay", "node1", "", []string{"o1"}, "node1/o1.img", []string{"o1.txt"}},
|
||||
{"multiple overlays", "node1", "", []string{"o1", "o2"}, "node1/o1-o2.img", []string{"o1.txt", "o2.txt"}},
|
||||
{"empty system overlay", "node1", "system", nil, "", nil},
|
||||
{"empty runtime overlay", "node1", "runtime", nil, "", nil},
|
||||
{"single system overlay", "node1", "system", []string{"o1"}, "node1/__SYSTEM__.img", []string{"o1.txt"}},
|
||||
{"single runtime overlay", "node1", "runtime", []string{"o1"}, "node1/__RUNTIME__.img", []string{"o1.txt"}},
|
||||
{"two system overlays", "node1", "system", []string{"o1", "o2"}, "node1/__SYSTEM__.img", []string{"o1.txt", "o2.txt"}},
|
||||
{"two runtime overlays", "node1", "runtime", []string{"o1", "o2"}, "node1/__RUNTIME__.img", []string{"o1.txt", "o2.txt"}},
|
||||
{"empty", "", "", nil, "", nil, false},
|
||||
{"empty node", "node1", "", nil, "", nil, false},
|
||||
{"empty context", "", "system", nil, "", nil, false},
|
||||
{"empty overlay", "", "", []string{"o1"}, "o1.img", []string{"o1.txt"}, true},
|
||||
{"single overlay", "node1", "", []string{"o1"}, "node1/o1.img", []string{"o1.txt"}, true},
|
||||
{"multiple overlays", "node1", "", []string{"o1", "o2"}, "node1/o1-o2.img", []string{"o1.txt", "o2.txt"}, true},
|
||||
{"empty system overlay", "node1", "system", nil, "", nil, false},
|
||||
{"empty runtime overlay", "node1", "runtime", nil, "", nil, false},
|
||||
{"single system overlay", "node1", "system", []string{"o1"}, "node1/__SYSTEM__.img", []string{"o1.txt"}, true},
|
||||
{"single runtime overlay", "node1", "runtime", []string{"o1"}, "node1/__RUNTIME__.img", []string{"o1.txt"}, true},
|
||||
{"two system overlays", "node1", "system", []string{"o1", "o2"}, "node1/__SYSTEM__.img", []string{"o1.txt", "o2.txt"}, true},
|
||||
{"two runtime overlays", "node1", "runtime", []string{"o1", "o2"}, "node1/__RUNTIME__.img", []string{"o1.txt", "o2.txt"}, true},
|
||||
}
|
||||
|
||||
func Test_BuildOverlay(t *testing.T) {
|
||||
@@ -65,7 +66,7 @@ func Test_BuildOverlay(t *testing.T) {
|
||||
conf.Paths.WWProvisiondir = provisionDir
|
||||
|
||||
err := BuildOverlay(nodeInfo, tt.context, tt.overlays)
|
||||
if len(tt.image) > 0 {
|
||||
if tt.hasFiles {
|
||||
image := path.Join(provisionDir, "overlays", tt.image)
|
||||
assert.FileExists(t, image)
|
||||
assert.NoError(t, err)
|
||||
@@ -75,7 +76,6 @@ func Test_BuildOverlay(t *testing.T) {
|
||||
sort.Strings(files)
|
||||
assert.Equal(t, tt.contents, files)
|
||||
} else {
|
||||
assert.Error(t, err)
|
||||
dirName := path.Join(provisionDir, "overlays", tt.nodeName)
|
||||
isEmpty := dirIsEmpty(t, dirName)
|
||||
assert.True(t, isEmpty, "%v should be empty, but isn't", dirName)
|
||||
@@ -90,22 +90,23 @@ var buildAllOverlaysTests = []struct {
|
||||
systemOverlays []string
|
||||
runtimeOverlays []string
|
||||
succeed bool
|
||||
createdOverlays []string
|
||||
}{
|
||||
{"no nodes", nil, nil, nil, true},
|
||||
{"single empty node", []string{"node1"}, nil, nil, false},
|
||||
{"two empty node", []string{"node1", "node2"}, nil, nil, false},
|
||||
{"no nodes", nil, nil, nil, true, nil},
|
||||
{"single empty node", []string{"node1"}, nil, nil, true, nil},
|
||||
{"two empty node", []string{"node1", "node2"}, nil, nil, true, nil},
|
||||
{"single node with system overlay", []string{"node1"},
|
||||
[]string{"o1"}, nil, false},
|
||||
[]string{"o1"}, nil, true, []string{"__SYSTEM__.img.gz"}},
|
||||
{"two nodes with system overlays", []string{"node1", "node2"},
|
||||
[]string{"o1", "o1,o2"}, nil, false},
|
||||
[]string{"o1", "o1,o2"}, nil, true, []string{"__SYSTEM__.img.gz"}},
|
||||
{"single node with runtime overlay", []string{"node1"},
|
||||
nil, []string{"o1"}, false},
|
||||
nil, []string{"o1"}, true, []string{"__RUNTIME__.img.gz"}},
|
||||
{"two nodes with runtime overlays", []string{"node1", "node2"},
|
||||
nil, []string{"o1", "o1,o2"}, false},
|
||||
{"stingle node with full overlays", []string{"node1"},
|
||||
[]string{"o1"}, []string{"o2"}, true},
|
||||
nil, []string{"o1", "o1,o2"}, true, []string{"__RUNTIME__.img.gz"}},
|
||||
{"single node with full overlays", []string{"node1"},
|
||||
[]string{"o1"}, []string{"o2"}, true, []string{"__RUNTIME__.img.gz", "__SYSTEM__.img.gz"}},
|
||||
{"two nodes with full overlays", []string{"node1", "node2"},
|
||||
[]string{"o1", "o1,o2"}, []string{"o2", "o2"}, true},
|
||||
[]string{"o1", "o1,o2"}, []string{"o2", "o2"}, true, []string{"__RUNTIME__.img.gz", "__SYSTEM__.img.gz"}},
|
||||
}
|
||||
|
||||
func Test_BuildAllOverlays(t *testing.T) {
|
||||
@@ -142,8 +143,9 @@ func Test_BuildAllOverlays(t *testing.T) {
|
||||
} else {
|
||||
assert.NoError(t, err)
|
||||
for _, nodeName := range tt.nodes {
|
||||
assert.FileExists(t, path.Join(provisionDir, "overlays", nodeName, "__SYSTEM__.img"))
|
||||
assert.FileExists(t, path.Join(provisionDir, "overlays", nodeName, "__RUNTIME__.img"))
|
||||
for _, file := range tt.createdOverlays {
|
||||
assert.FileExists(t, path.Join(provisionDir, "overlays", nodeName, file))
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user