@@ -4,23 +4,32 @@ import (
44 "encoding/base64"
55 "encoding/json"
66 "fmt"
7+ "os"
78 "testing"
89
910 ecv1beta1 "github.com/replicatedhq/embedded-cluster/kinds/apis/v1beta1"
1011 "github.com/replicatedhq/embedded-cluster/pkg/release"
1112 kotsv1beta1 "github.com/replicatedhq/kotskinds/apis/kots/v1beta1"
13+ kotsv1beta2 "github.com/replicatedhq/kotskinds/apis/kots/v1beta2"
1214 "github.com/replicatedhq/kotskinds/pkg/licensewrapper"
1315 "github.com/stretchr/testify/assert"
1416 "github.com/stretchr/testify/require"
1517)
1618
17- // Helper function to wrap old-style license in LicenseWrapper for testing
19+ // Helper function to wrap v1beta1 license in LicenseWrapper for testing
1820func wrapLicense (license * kotsv1beta1.License ) * licensewrapper.LicenseWrapper {
1921 return & licensewrapper.LicenseWrapper {
2022 V1 : license ,
2123 }
2224}
2325
26+ // Helper function to wrap v1beta2 license in LicenseWrapper for testing
27+ func wrapLicenseV2 (license * kotsv1beta2.License ) * licensewrapper.LicenseWrapper {
28+ return & licensewrapper.LicenseWrapper {
29+ V2 : license ,
30+ }
31+ }
32+
2433func TestEngine_LicenseFieldValue (t * testing.T ) {
2534 license := & kotsv1beta1.License {
2635 Spec : kotsv1beta1.LicenseSpec {
@@ -175,8 +184,8 @@ func TestEngine_LicenseFieldValue_Endpoint(t *testing.T) {
175184}
176185
177186func TestEngine_LicenseFieldValue_EndpointWithoutReleaseData (t * testing.T ) {
178- license := & kotsv1beta1 .License {
179- Spec : kotsv1beta1 .LicenseSpec {
187+ license := & kotsv1beta2 .License {
188+ Spec : kotsv1beta2 .LicenseSpec {
180189 CustomerName : "Acme Corp" ,
181190 LicenseID : "license-123" ,
182191 },
@@ -188,7 +197,7 @@ func TestEngine_LicenseFieldValue_EndpointWithoutReleaseData(t *testing.T) {
188197 },
189198 }
190199
191- engine := NewEngine (config , WithLicense (wrapLicense (license )))
200+ engine := NewEngine (config , WithLicense (wrapLicenseV2 (license )))
192201
193202 err := engine .Parse ("{{repl LicenseFieldValue \" endpoint\" }}" )
194203 require .NoError (t , err )
@@ -606,113 +615,3 @@ func TestEngine_ChannelName_ChannelNotFound(t *testing.T) {
606615 assert .Error (t , err )
607616 assert .Contains (t , err .Error (), "channel unknown-channel-id not found in license" )
608617}
609-
610- func TestEngine_LicenseWrapper (t * testing.T ) {
611- licenseV1Beta1 := `apiVersion: kots.io/v1beta1
612- kind: License
613- metadata:
614- name: test-license
615- spec:
616- appSlug: embedded-cluster-test
617- licenseID: test-license-id-v1
618- licenseType: dev
619- customerName: Test Customer V1
620- 621- endpoint: https://replicated.app
622- channelID: test-channel-id
623- channelName: Stable
624- licenseSequence: 1
625- isAirgapSupported: true
626- isGitOpsSupported: false
627- isIdentityServiceSupported: false
628- isGeoaxisSupported: false
629- isSnapshotSupported: true
630- isSupportBundleUploadSupported: true
631- isSemverRequired: true
632- isDisasterRecoverySupported: true
633- isEmbeddedClusterDownloadEnabled: true
634- isEmbeddedClusterMultiNodeEnabled: true
635- replicatedProxyDomain: proxy.replicated.com
636- entitlements:
637- expires_at:
638- title: Expiration
639- description: License Expiration
640- value: ""
641- valueType: String
642- signature: {}
643- channels: []
644- signature: dGVzdC1saWNlbnNlLXNpZ25hdHVyZQ==
645- `
646-
647- licenseV1Beta2 := `apiVersion: kots.io/v1beta2
648- kind: License
649- metadata:
650- name: test-license
651- spec:
652- appSlug: embedded-cluster-test
653- licenseID: test-license-id-v2
654- licenseType: dev
655- customerName: Test Customer V2
656- 657- endpoint: https://replicated.app
658- channelID: test-channel-id
659- channelName: Stable
660- licenseSequence: 1
661- isAirgapSupported: true
662- isGitOpsSupported: false
663- isIdentityServiceSupported: false
664- isGeoaxisSupported: false
665- isSnapshotSupported: true
666- isSupportBundleUploadSupported: true
667- isSemverRequired: true
668- isDisasterRecoverySupported: true
669- isEmbeddedClusterDownloadEnabled: true
670- isEmbeddedClusterMultiNodeEnabled: true
671- replicatedProxyDomain: proxy.replicated.com
672- entitlements:
673- expires_at:
674- title: Expiration
675- description: License Expiration
676- value: ""
677- valueType: String
678- signature: {}
679- channels: []
680- signature: dGVzdC1saWNlbnNlLXNpZ25hdHVyZQ==
681- `
682-
683- tests := []struct {
684- name string
685- licenseData string
686- wantAppSlug string
687- wantLicenseID string
688- wantECEnabled bool
689- }{
690- {
691- name : "v1beta1 license" ,
692- licenseData : licenseV1Beta1 ,
693- wantAppSlug : "embedded-cluster-test" ,
694- wantLicenseID : "test-license-id-v1" ,
695- wantECEnabled : true ,
696- },
697- {
698- name : "v1beta2 license" ,
699- licenseData : licenseV1Beta2 ,
700- wantAppSlug : "embedded-cluster-test" ,
701- wantLicenseID : "test-license-id-v2" ,
702- wantECEnabled : true ,
703- },
704- }
705-
706- for _ , tt := range tests {
707- t .Run (tt .name , func (t * testing.T ) {
708- wrapper , err := licensewrapper .LoadLicenseFromBytes ([]byte (tt .licenseData ))
709- require .NoError (t , err )
710-
711- engine := NewEngine (nil , WithLicense (& wrapper ))
712-
713- assert .Equal (t , tt .wantAppSlug , engine .LicenseAppSlug ())
714- assert .Equal (t , tt .wantLicenseID , engine .LicenseID ())
715- assert .Equal (t , tt .wantECEnabled , engine .LicenseIsEmbeddedClusterDownloadEnabled ())
716- })
717- }
718- }
0 commit comments