Skip to content

Commit

Permalink
fix: don't consider Syft types round-trippable
Browse files Browse the repository at this point in the history
Signed-off-by: Vlad Klokun <[email protected]>
  • Loading branch information
vladklokun committed Nov 22, 2023
1 parent 209bb0a commit 338f9f4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
17 changes: 15 additions & 2 deletions pkg/apis/softwarecomposition/install/roundtrip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,19 @@ limitations under the License.
package install

import (
"math/rand"
"regexp"
"testing"

"github.com/kubescape/storage/pkg/apis/softwarecomposition"
wardlefuzzer "github.com/kubescape/storage/pkg/apis/softwarecomposition/fuzzer"

"k8s.io/apimachinery/pkg/api/apitesting/fuzzer"
"k8s.io/apimachinery/pkg/api/apitesting/roundtrip"
metafuzzer "k8s.io/apimachinery/pkg/apis/meta/fuzzer"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer"
"math/rand"
)

func TestRoundTripTypes(t *testing.T) {
Expand All @@ -42,6 +45,16 @@ func TestRoundTripTypes(t *testing.T) {
rand.NewSource(rand.Int63()),
codecFactory,
)
f.NumElements(1, 2)
f.NilChance(0)

nonRoundTrippableTypes := map[schema.GroupVersionKind]bool{
// Syft types use custom JSON unmarshaling, so they are not round-trippable by definition
softwarecomposition.SchemeGroupVersion.WithKind("SBOMSyft"): true,
softwarecomposition.SchemeGroupVersion.WithKind("SBOMSyftList"): true,
softwarecomposition.SchemeGroupVersion.WithKind("SBOMSyftFiltered"): true,
softwarecomposition.SchemeGroupVersion.WithKind("SBOMSyftFilteredList"): true,
}

skippedFields := []string{
"SnippetAttributionTexts",
Expand All @@ -61,5 +74,5 @@ func TestRoundTripTypes(t *testing.T) {
f.SkipFieldsWithPattern(skipPattern)
}

roundtrip.RoundTripTypesWithoutProtobuf(t, scheme, codecFactory, f, nil)
roundtrip.RoundTripTypesWithoutProtobuf(t, scheme, codecFactory, f, nonRoundTrippableTypes)
}
16 changes: 13 additions & 3 deletions pkg/apiserver/scheme_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,18 @@ limitations under the License.
package apiserver

import (
"math/rand"
"regexp"
"testing"

"github.com/kubescape/storage/pkg/apis/softwarecomposition"
wardlefuzzer "github.com/kubescape/storage/pkg/apis/softwarecomposition/fuzzer"

"k8s.io/apimachinery/pkg/api/apitesting/fuzzer"
"k8s.io/apimachinery/pkg/api/apitesting/roundtrip"
metafuzzer "k8s.io/apimachinery/pkg/apis/meta/fuzzer"
"k8s.io/apimachinery/pkg/runtime/schema"
runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer"
"math/rand"
)

func TestRoundTripTypes(t *testing.T) {
Expand All @@ -38,10 +41,17 @@ func TestRoundTripTypes(t *testing.T) {
rand.NewSource(rand.Int63()),
codecFactory,
)

f.NumElements(1, 2)
f.NilChance(0)

nonRoundTrippableTypes := map[schema.GroupVersionKind]bool{
// Syft types use custom JSON unmarshaling, so they are not round-trippable by definition
softwarecomposition.SchemeGroupVersion.WithKind("SBOMSyft"): true,
softwarecomposition.SchemeGroupVersion.WithKind("SBOMSyftList"): true,
softwarecomposition.SchemeGroupVersion.WithKind("SBOMSyftFiltered"): true,
softwarecomposition.SchemeGroupVersion.WithKind("SBOMSyftFilteredList"): true,
}

skippedFields := []string{
"SnippetAttributionTexts",
"SpecialID",
Expand All @@ -60,5 +70,5 @@ func TestRoundTripTypes(t *testing.T) {
f.SkipFieldsWithPattern(skipPattern)
}

roundtrip.RoundTripTypesWithoutProtobuf(t, scheme, codecFactory, f, nil)
roundtrip.RoundTripTypesWithoutProtobuf(t, scheme, codecFactory, f, nonRoundTrippableTypes)
}

0 comments on commit 338f9f4

Please sign in to comment.