Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions toolkit/tools/imagecustomizerapi/previewfeaturetype_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

package imagecustomizerapi

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestPreviewFeature_IsValid(t *testing.T) {
validFeatures := []PreviewFeature{
PreviewFeatureUki,
PreviewFeatureOutputArtifacts,
PreviewFeatureInjectFiles,
PreviewFeaturePackageSnapshotTime,
}

for _, feature := range validFeatures {
err := feature.IsValid()
assert.NoError(t, err, "expected no error for valid feature: %s", feature)
}

invalidFeature := PreviewFeature("invalid-feature")
err := invalidFeature.IsValid()
assert.Error(t, err)
assert.Contains(t, err.Error(), "invalid-feature")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use assert.ErrorContains instead of assert.Error and assert.Contains.


// Test PreviewFeatureReinitializeVerity is not valid (since it's not typed as PreviewFeature)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason why this fails is because PreviewFeatureReinitializeVerity is missing in the PreviewFeature.IsValid() function. Go is happily doing the type-cast without issue.

Also, it looks like the Config.PreviewFeatures field isn't being checked for validity. Hence, why this wasn't causing any problems.

var reinitFeature PreviewFeature = PreviewFeatureReinitializeVerity
err = reinitFeature.IsValid()
assert.Error(t, err)
assert.Contains(t, err.Error(), "reinitialize-verity")
}
Loading