| 1 | package host |
| 2 | |
| 3 | import ( |
| 4 | "github.com/carlosframework/platform/internal/moves" |
| 5 | "testing" |
| 6 | ) |
| 7 | |
| 8 | func TestPlan14FloorReconstruction(t *testing.T) { |
| 9 | a := moves.Floor{Min: 1, MinRelease: "v1.0.0"} |
| 10 | b := moves.Floor{Min: 2, MinRelease: "v2.0.0"} |
| 11 | c := moves.Floor{Min: 3, MinRelease: "v3.0.0"} |
| 12 | for _, tc := range []struct { |
| 13 | name string |
| 14 | history, remote *moves.Floor |
| 15 | legacy []*moves.Floor |
| 16 | want *moves.Floor |
| 17 | bad bool |
| 18 | }{ |
| 19 | {"remote deleted", &b, nil, nil, &b, false}, |
| 20 | {"remote regressed", &b, &a, nil, &b, true}, |
| 21 | {"legacy stricter", &a, &a, []*moves.Floor{&b}, &b, true}, |
| 22 | {"legacy cannot grant", nil, &b, []*moves.Floor{&b}, nil, true}, |
| 23 | {"both legacy files missing", nil, &a, nil, nil, true}, |
| 24 | {"remote and legacy missing", nil, nil, nil, nil, true}, |
| 25 | {"corrupt legacy", &a, &c, []*moves.Floor{{Min: 2, MinRelease: "broken"}}, nil, true}, |
| 26 | {"root history survives legacy deletion", &b, &c, nil, &c, false}, |
| 27 | {"independent minima", &a, nil, []*moves.Floor{{Min: 3, MinRelease: "v1.0.0"}, &b}, &moves.Floor{Min: 3, MinRelease: "v2.0.0"}, true}, |
| 28 | } { |
| 29 | t.Run(tc.name, func(t *testing.T) { |
| 30 | got, err := reconstructRootFloor(tc.history, tc.remote, tc.legacy) |
| 31 | if (err != nil) != tc.bad { |
| 32 | t.Fatalf("error = %v", err) |
| 33 | } |
| 34 | if (got == nil) != (tc.want == nil) || (got != nil && *got != *tc.want) { |
| 35 | t.Fatalf("floor=%+v, want %+v", got, tc.want) |
| 36 | } |
| 37 | }) |
| 38 | } |
| 39 | } |
| 40 | |