func TestExportControl(t *testing.T) {
	for _, example := range exportControlTests {
		dir, err := ioutil.TempDir("", "example")
		if err != nil {
			log.Fatal(err)
		}
		defer os.RemoveAll(dir)
		openControlData, errs := lib.LoadData(example.opencontrolDir, example.certificationPath)
		if len(errs) > 0 {
			log.Fatal("Should have loaded the opencontrol data.")
		}
		openControl := OpenControlGitBook{
			openControlData,
			"",
			dir,
			fs.OSUtil{},
		}
		standard, _ := openControl.GetStandard(example.standardKey)
		control := standard.GetControl(example.controlKey)
		actualPath, actualText := openControl.exportControl(&ControlGitbook{control, dir, example.standardKey, example.controlKey})
		expectedPath := filepath.Join(dir, example.expectedPath)
		// Verify the expected export path is the same as the actual export path
		if expectedPath != actualPath {
			t.Errorf("Expected %s, Actual: %s", example.expectedPath, actualPath)
		}
		// Verify the expected text is the same as the actual text
		if example.expectedText != strings.Replace(actualText, "\\", "/", -1) {
			t.Errorf("Expected %s, Actual: %s", example.expectedText, actualText)
		}

	}
// ComputeGapAnalysis will compute the gap analysis and return the inventory of the controls for the
// opencontrol workspace if successful. Otherwise, it will return a list of error messages.
// TODO: fix the error return to return of type error. This was used because existing code returned that type
// TODO: e.g. GetCertification
func ComputeGapAnalysis(config Config) (Inventory, []error) {
	// Initialize inventory with certification
	certificationPath, errs := certifications.GetCertification(config.OpencontrolDir, config.Certification)
	if certificationPath == "" {
		return Inventory{}, errs
	}
	workspace, _ := lib.LoadData(config.OpencontrolDir, certificationPath)
	i := Inventory{
		Workspace:               workspace,
		masterControlList:       make(map[string]common.Control),
		actualSatisfiedControls: make(map[string]common.Satisfies),
		MissingControlList:      make(map[string]common.Control),
	}
	if i.GetCertification() == nil || i.GetAllComponents() == nil {
		return Inventory{}, []error{fmt.Errorf("Unable to load data in %s for certification %s", config.OpencontrolDir, config.Certification)}
	}

	// Gather list of all controls for certification
	i.retrieveMasterControlsList()
	// Find the documented controls.
	i.findDocumentedControls()
	// Calculate the Missing controls / Non documented
	i.calculateNonDocumentedControls()

	return i, nil
}
func TestBuildComponentsSummaries(t *testing.T) {
	for _, example := range buildComponentsSummariesTests {
		openControlData, _ := lib.LoadData(example.opencontrolDir, example.certificationPath)
		openControl := OpenControlGitBook{
			openControlData,
			"",
			example.exportPath,
			fs.OSUtil{},
		}
		actualSummary := openControl.buildComponentsSummaries()
		data, err := ioutil.ReadFile(example.expectedSummary)
		if err != nil {
			log.Fatal(err)
		}
		expectedSummary := string(data)
		// Check that the actual and expected summaries are similar
		if strings.Replace(actualSummary, "\\", "/", -1) != expectedSummary {
			t.Errorf("Expected: `%s`, Actual: `%s`", expectedSummary, actualSummary)
		}
	}
// BuildGitbook entry point for creating gitbook
func (config Config) BuildGitbook() []error {
	var errs []error
	openControlData, err := lib.LoadData(config.OpencontrolDir, config.Certification)
	if err != nil && len(err) > 0 {
		return append(errs, err...)
	}
	openControl := OpenControlGitBook{
		openControlData,
		config.MarkdownPath,
		config.ExportPath,
		fs.OSUtil{},
	}
	openControl.FSUtil.Mkdirs(config.ExportPath)
	openControl.FSUtil.Mkdirs(filepath.Join(config.ExportPath, "components"))
	openControl.FSUtil.Mkdirs(filepath.Join(config.ExportPath, "standards"))
	if err := openControl.buildSummaries(); err != nil {
		return append(errs, err)
	}
	openControl.exportComponents()
	openControl.exportStandards()
	return nil
}
func run(workspacePath, certPath string, writer io.Writer) {
	workspace, _ := lib.LoadData(workspacePath, certPath)
	sampleData := simpleDataExtract(plugin{workspace})
	fmt.Fprint(writer, sampleData)
}