From c7bc25ceada75780644f2da13a71f29517fbbf11 Mon Sep 17 00:00:00 2001 From: "Brian C. Lane" Date: Mon, 8 May 2023 10:14:37 -0700 Subject: [PATCH] tests: Add a test for freezing a blueprint with globs This is currently failing (fixed in the next commit). It tests to make sure that a blueprint with package name globs can be frozen. The resulting blueprint should replace the glob entries with the expanded list of packages. --- internal/client/blueprints_test.go | 40 ++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/internal/client/blueprints_test.go b/internal/client/blueprints_test.go index 135e52b9b..c1c89d36e 100644 --- a/internal/client/blueprints_test.go +++ b/internal/client/blueprints_test.go @@ -1101,6 +1101,46 @@ func TestBlueprintFreezeV0(t *testing.T) { require.NotEqual(t, "*", frozen.Blueprints[0].Blueprint.Modules[0].Version, "Wrong version in frozen blueprint module") } +func TestBlueprintFreezeGlobsV0(t *testing.T) { + // Test needs real packages, skip it for unit testing + if testState.unitTest { + t.Skip() + } + + bp := `{ + "name": "test-freeze-blueprint-glob-v0", + "description": "TestBlueprintFreezeGlobsV0", + "version": "0.0.1", + "packages": [{"name": "tmux", "version": "?.*"}, + {"name": "openssh-*", "version": "*"}] + }` + + // Push a blueprint + resp, err := PostJSONBlueprintV0(testState.socket, bp) + require.NoError(t, err, "POST blueprint failed with a client error") + require.True(t, resp.Status, "POST blueprint failed: %#v", resp) + + // Freeze the blueprint + frozen, api, err := FreezeBlueprintV0(testState.socket, "test-freeze-blueprint-glob-v0") + require.NoError(t, err, "Freeze blueprint failed with a client error") + require.Nil(t, api, "FreezeBlueprint failed: %#v", api) + require.Greater(t, len(frozen.Blueprints), 0, "No frozen blueprints returned") + require.Greater(t, len(frozen.Blueprints[0].Blueprint.Packages), 0, "No frozen packages returned") + + var names []string + for _, p := range frozen.Blueprints[0].Blueprint.Packages { + assert.NotContains(t, p.Version, "*") + assert.NotContains(t, p.Version, "?") + names = append(names, p.Name) + } + sort.Strings(names) + t.Log(names) + assert.True(t, common.IsStringInSortedSlice(names, "openssh-clients")) + assert.True(t, common.IsStringInSortedSlice(names, "openssh-server")) + assert.True(t, common.IsStringInSortedSlice(names, "tmux")) + +} + // freeze a non-existent blueprint func TestNonBlueprintFreezeV0(t *testing.T) { resp, api, err := FreezeBlueprintV0(testState.socket, "test-freeze-non-blueprint-v0")