Skip to content

Different amount of Documents in ytbx.InputFile depending on how InputFile is created #220

@oscr

Description

@oscr

Hi 👋

Depending on how an InputFile is created the amount of Documents differ for the same file/data. I would have expected no diff.

I ran the example program below with an empty file called example.txt in the same folder. I got the following output:

failed to compare input: comparing YAMLs with a different number of documents is currently not supported
expected len: 1
actual len: 0
expected file value: ''
package main

import (
	"fmt"
	"github.com/gonvenience/ytbx"
	"github.com/homeport/dyff/pkg/dyff"
	"os"
)

func main() {
	filename := "empty.txt"

	expectedFile, err := ytbx.LoadFile(filename)
	if err != nil {
		fmt.Errorf("failed to load expected: %v", err)
		os.Exit(1)
	}

	data, err := os.ReadFile(filename)
	docs, err := ytbx.LoadYAMLDocuments(data)
	if err != nil {
		fmt.Printf("failed to load actual: %v", err)
		os.Exit(1)
	}

	actualFile := ytbx.InputFile{
		Documents: docs,
	}

	_, err = dyff.CompareInputFiles(expectedFile, actualFile, dyff.KubernetesEntityDetection(true))
	if err != nil {
		fmt.Printf("failed to compare input: %v\n", err)
		fmt.Printf("expected len: %d\n", len(expectedFile.Documents))
		fmt.Printf("actual len: %d\n", len(actualFile.Documents))
		fmt.Printf("expected file value: '%s'\n", expectedFile.Documents[0].Value)
		os.Exit(1)
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions