
* fix: template apply uses better diff checking Previously, we did a DeepEqual of all the returned data about each changed entity, but due to our template overrides that is not actually all the information available for each entity. So we marked trivial things as 'conflicts' (e.g. telegraf config ID's 'changing' from the empty string to the real, current value) while not catching important conflicts like flux script changes in checks and tasks. Changes to make things more straightforward: * Change the --force behaviour to be more similar to `apt install`, where even in non-interactive mode `--force yes` is required to bypass the prompt to apply. * Before, there were two stages of diff checking - once to print diffs, and once after the 'Yes/No' prompt. If any conflicts were detected in the second check, the user got an inscrutable error message that did not highlight what the difference was or how to force it to apply. `--force conflict` was required to avoid this error. Instead, we now have simplified to `--force yes` to bypass the 'Yes/No' prompt, and we never do a second stage of diff checking. * Because we do not currently properly account for more complicated diffs (e.g. flux tasks), we now assume in the diff printing that every object has changes, except for Labels, Buckets, Variables, and Label Mappings. This could be improved in the future. * fix: when statestatus is 'remove', mark as removed
84 lines
2.7 KiB
Go
84 lines
2.7 KiB
Go
package template_test
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
|
|
"github.com/influxdata/influx-cli/v2/pkg/template"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestDiffPrinter_Empty(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
out := bytes.Buffer{}
|
|
printer := template.NewDiffPrinter(&out, false, true).
|
|
Title("Example").
|
|
SetHeaders("Wow", "Such", "A", "Fancy", "Printer")
|
|
|
|
printer.Render()
|
|
require.Empty(t, out.String())
|
|
}
|
|
|
|
func TestDiffPrinter(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
out := bytes.Buffer{}
|
|
printer := template.NewDiffPrinter(&out, false, true).
|
|
Title("Example").
|
|
SetHeaders("Wow", "Such", "A", "Fancy", "Printer")
|
|
|
|
// Add
|
|
printer.AppendDiff(nil, []string{"A", "B", "C", "D", "E"}, false)
|
|
|
|
// No change
|
|
simple := []string{"foo", "bar", "baz", "qux", "wat"}
|
|
printer.Append(simple)
|
|
|
|
// No change with two arguments
|
|
printer.AppendDiff(simple, simple, false)
|
|
|
|
// No change but force a diff
|
|
printer.AppendDiff(simple, simple, true)
|
|
|
|
// Replace
|
|
printer.AppendDiff(
|
|
[]string{"1", "200000000000000", "3", "4", "5"},
|
|
[]string{"9", "8", "7", "6", "5"},
|
|
false,
|
|
)
|
|
|
|
// Remove
|
|
printer.AppendDiff([]string{"x y", "z x", "x y z", "", "y z"}, nil, false)
|
|
|
|
printer.Render()
|
|
expected := `EXAMPLE +add | -remove | unchanged
|
|
+-----+-----+-----------------+-------+-------+---------+
|
|
| +/- | WOW | SUCH | A | FANCY | PRINTER |
|
|
+-----+-----+-----------------+-------+-------+---------+
|
|
| + | A | B | C | D | E |
|
|
+-----+-----+-----------------+-------+-------+---------+
|
|
| | foo | bar | baz | qux | wat |
|
|
+-----+-----+-----------------+-------+-------+---------+
|
|
+-----+-----+-----------------+-------+-------+---------+
|
|
| | foo | bar | baz | qux | wat |
|
|
+-----+-----+-----------------+-------+-------+---------+
|
|
+-----+-----+-----------------+-------+-------+---------+
|
|
| - | foo | bar | baz | qux | wat |
|
|
+-----+-----+-----------------+-------+-------+---------+
|
|
| + | foo | bar | baz | qux | wat |
|
|
+-----+-----+-----------------+-------+-------+---------+
|
|
+-----+-----+-----------------+-------+-------+---------+
|
|
| - | 1 | 200000000000000 | 3 | 4 | 5 |
|
|
+-----+-----+-----------------+-------+-------+---------+
|
|
| + | 9 | 8 | 7 | 6 | 5 |
|
|
+-----+-----+-----------------+-------+-------+---------+
|
|
+-----+-----+-----------------+-------+-------+---------+
|
|
| - | x y | z x | x y z | | y z |
|
|
+-----+-----+-----------------+-------+-------+---------+
|
|
| TOTAL | 5 |
|
|
+-----+-----+-----------------+-------+-------+---------+
|
|
`
|
|
require.Equal(t, expected, out.String())
|
|
}
|