github.com/ActiveState/cli@v0.0.0-20240508170324-6801f60cd051/pkg/platform/model/vcs_test.go (about) 1 package model 2 3 import ( 4 "testing" 5 6 "github.com/ActiveState/cli/internal/testhelpers/suite" 7 gqlModel "github.com/ActiveState/cli/pkg/platform/api/graphql/model" 8 "github.com/ActiveState/cli/pkg/platform/api/mono/mono_models" 9 ) 10 11 type VCSTestSuite struct { 12 suite.Suite 13 } 14 15 func (suite *VCSTestSuite) TestNamespaceMatch() { 16 suite.True(NamespaceMatch("platform", NamespacePlatformMatch)) 17 suite.False(NamespaceMatch(" platform ", NamespacePlatformMatch)) 18 suite.False(NamespaceMatch("not-platform", NamespacePlatformMatch)) 19 20 suite.True(NamespaceMatch("language", NamespaceLanguageMatch)) 21 suite.False(NamespaceMatch(" language ", NamespaceLanguageMatch)) 22 suite.False(NamespaceMatch("not-language", NamespaceLanguageMatch)) 23 24 suite.True(NamespaceMatch("language/foo", NamespacePackageMatch)) 25 suite.False(NamespaceMatch(" language/foo", NamespacePackageMatch)) 26 27 suite.True(NamespaceMatch("bundles/foo", NamespaceBundlesMatch)) 28 suite.False(NamespaceMatch(" bundles/foo", NamespaceBundlesMatch)) 29 30 suite.True(NamespaceMatch("pre-platform-installer", NamespacePrePlatformMatch)) 31 suite.False(NamespaceMatch(" pre-platform-installer ", NamespacePrePlatformMatch)) 32 } 33 34 func (suite *VCSTestSuite) TestChangesetFromRequirements() { 35 tests := []struct { 36 op Operation 37 reqs []*gqlModel.Requirement 38 want Changeset 39 }{ 40 { 41 OperationAdded, 42 []*gqlModel.Requirement{ 43 { 44 Checkpoint: mono_models.Checkpoint{ 45 Namespace: "a-name", 46 Requirement: "a-req", 47 VersionConstraint: "a-vercon", 48 }, 49 }, 50 { 51 Checkpoint: mono_models.Checkpoint{ 52 Namespace: "b-name", 53 Requirement: "b-req", 54 VersionConstraint: "b-vercon", 55 }, 56 }, 57 }, 58 Changeset{ 59 { 60 Operation: string(OperationAdded), 61 Namespace: "a-name", 62 Requirement: "a-req", 63 VersionConstraint: "a-vercon", 64 }, 65 { 66 Operation: string(OperationAdded), 67 Namespace: "b-name", 68 Requirement: "b-req", 69 VersionConstraint: "b-vercon", 70 }, 71 }, 72 }, 73 { 74 OperationRemoved, 75 []*gqlModel.Requirement{ 76 { 77 Checkpoint: mono_models.Checkpoint{ 78 Namespace: "x-name", 79 Requirement: "x-req", 80 VersionConstraint: "x-vercon", 81 }, 82 }, 83 { 84 Checkpoint: mono_models.Checkpoint{ 85 Namespace: "y-name", 86 Requirement: "y-req", 87 VersionConstraint: "y-vercon", 88 }, 89 }, 90 { 91 Checkpoint: mono_models.Checkpoint{ 92 Namespace: "z-name", 93 Requirement: "z-req", 94 VersionConstraint: "z-vercon", 95 }, 96 }, 97 }, 98 Changeset{ 99 { 100 Operation: string(OperationRemoved), 101 Namespace: "x-name", 102 Requirement: "x-req", 103 VersionConstraint: "x-vercon", 104 }, 105 { 106 Operation: string(OperationRemoved), 107 Namespace: "y-name", 108 Requirement: "y-req", 109 VersionConstraint: "y-vercon", 110 }, 111 { 112 Operation: string(OperationRemoved), 113 Namespace: "z-name", 114 Requirement: "z-req", 115 VersionConstraint: "z-vercon", 116 }, 117 }, 118 }, 119 } 120 121 for _, tt := range tests { 122 got := ChangesetFromRequirements(tt.op, tt.reqs) 123 suite.Equal(tt.want, got) 124 } 125 } 126 127 func (suite *VCSTestSuite) TestVersionStringToConstraints() { 128 tests := []struct { 129 version string 130 want []*mono_models.Constraint 131 }{ 132 { 133 "3.10.10", 134 []*mono_models.Constraint{ 135 {Comparator: "eq", Version: "3.10.10"}, 136 }, 137 }, 138 { 139 "3.10.x", 140 []*mono_models.Constraint{ 141 {Comparator: "gte", Version: "3.10"}, 142 {Comparator: "lt", Version: "3.11"}, 143 }, 144 }, 145 { 146 "2.x", 147 []*mono_models.Constraint{ 148 {Comparator: "gte", Version: "2"}, 149 {Comparator: "lt", Version: "3"}, 150 }, 151 }, 152 } 153 154 for _, tt := range tests { 155 got, err := versionStringToConstraints(tt.version) 156 suite.NoError(err) 157 suite.Equal(tt.want, got) 158 } 159 } 160 161 func TestVCSTestSuite(t *testing.T) { 162 suite.Run(t, new(VCSTestSuite)) 163 }