Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Remove dead internal/license/subscription alias package

rcourtman44da863e1a67
diff --git a/internal/license/subscription/state.go b/internal/license/subscription/state.go
deleted file mode 100644
index d1f566abe2..0000000000
--- a/internal/license/subscription/state.go
+++ /dev/null
@@ -1,30 +0,0 @@
-package subscription
-
-import (
- "github.com/rcourtman/pulse-go-rewrite/internal/license"
- pkglicensing "github.com/rcourtman/pulse-go-rewrite/pkg/licensing"
-)
-
-type OperationClass = pkglicensing.OperationClass
-type StateBehavior = pkglicensing.StateBehavior
-
-const (
- OpFull = pkglicensing.OpFull
- OpDegraded = pkglicensing.OpDegraded
- OpLocked = pkglicensing.OpLocked
-)
-
-var StateBehaviors = map[license.SubscriptionState]StateBehavior{
- license.SubStateTrial: pkglicensing.StateBehaviors[pkglicensing.SubStateTrial],
- license.SubStateActive: pkglicensing.StateBehaviors[pkglicensing.SubStateActive],
- license.SubStateGrace: pkglicensing.StateBehaviors[pkglicensing.SubStateGrace],
- license.SubStateExpired: pkglicensing.StateBehaviors[pkglicensing.SubStateExpired],
- license.SubStateSuspended: pkglicensing.StateBehaviors[pkglicensing.SubStateSuspended],
- license.SubStateCanceled: pkglicensing.StateBehaviors[pkglicensing.SubStateCanceled],
-}
-
-// GetBehavior returns the behavior rules for the given state.
-// Returns expired behavior as default for unknown states.
-func GetBehavior(state license.SubscriptionState) StateBehavior {
- return pkglicensing.GetBehavior(state)
-}
diff --git a/internal/license/subscription/state_test.go b/internal/license/subscription/state_test.go
deleted file mode 100644
index db6bed41c6..0000000000
--- a/internal/license/subscription/state_test.go
+++ /dev/null
@@ -1,217 +0,0 @@
-package subscription
-
-import (
- "testing"
-
- "github.com/rcourtman/pulse-go-rewrite/internal/license"
-)
-
-func TestCanTransition_ValidTransitions(t *testing.T) {
- transitions := []Transition{
- {From: license.SubStateTrial, To: license.SubStateActive},
- {From: license.SubStateTrial, To: license.SubStateExpired},
- {From: license.SubStateActive, To: license.SubStateGrace},
- {From: license.SubStateActive, To: license.SubStateSuspended},
- {From: license.SubStateGrace, To: license.SubStateActive},
- {From: license.SubStateGrace, To: license.SubStateExpired},
- {From: license.SubStateExpired, To: license.SubStateActive},
- {From: license.SubStateSuspended, To: license.SubStateActive},
- {From: license.SubStateSuspended, To: license.SubStateExpired},
- }
-
- for _, transition := range transitions {
- transition := transition
- t.Run(string(transition.From)+"_to_"+string(transition.To), func(t *testing.T) {
- if !CanTransition(transition.From, transition.To) {
- t.Fatalf("expected transition %s -> %s to be valid", transition.From, transition.To)
- }
- })
- }
-}
-
-func TestCanTransition_InvalidTransitions(t *testing.T) {
- tests := []struct {
- name string
- from license.SubscriptionState
- to license.SubscriptionState
- }{
- {name: "trial_to_grace", from: license.SubStateTrial, to: license.SubStateGrace},
- {name: "trial_to_suspended", from: license.SubStateTrial, to: license.SubStateSuspended},
- {name: "active_to_trial", from: license.SubStateActive, to: license.SubStateTrial},
- {name: "active_to_expired", from: license.SubStateActive, to: license.SubStateExpired},
- {name: "grace_to_suspended", from: license.SubStateGrace, to: license.SubStateSuspended},
- {name: "grace_to_trial", from: license.SubStateGrace, to: license.SubStateTrial},
- {name: "expired_to_grace", from: license.SubStateExpired, to: license.SubStateGrace},
- {name: "expired_to_trial", from: license.SubStateExpired, to: license.SubStateTrial},
- {name: "expired_to_suspended", from: license.SubStateExpired, to: license.SubStateSuspended},
- {name: "suspended_to_grace", from: license.SubStateSuspended, to: license.SubStateGrace},
- {name: "suspended_to_trial", from: license.SubStateSuspended, to: license.SubStateTrial},
- }
-
- states := []license.SubscriptionState{
- license.SubStateTrial,
- license.SubStateActive,
- license.SubStateGrace,
- license.SubStateExpired,
- license.SubStateSuspended,
- }
- for _, state := range states {
- tests = append(tests, struct {
- name string
- from license.SubscriptionState
- to license.SubscriptionState
- }{
- name: string(state) + "_to_itself",
- from: state,
- to: state,
- })
- }
-
- for _, tt := range tests {
- tt := tt
- t.Run(tt.name, func(t *testing.T) {
- if CanTransition(tt.from, tt.to) {
- t.Fatalf("expected transition %s -> %s to be invalid", tt.from, tt.to)
- }
- })
- }
-}
-
-func TestValidTransitionsFrom(t *testing.T) {
- tests := []struct {
- from license.SubscriptionState
- expected map[license.SubscriptionState]struct{}
- }{
- {
- from: license.SubStateTrial,
- expected: map[license.SubscriptionState]struct{}{
- license.SubStateActive: {},
- license.SubStateExpired: {},
- },
- },
- {
- from: license.SubStateActive,
- expected: map[license.SubscriptionState]struct{}{
- license.SubStateGrace: {},
- license.SubStateSuspended: {},
- },
- },
- {
- from: license.SubStateGrace,
- expected: map[license.SubscriptionState]struct{}{
- license.SubStateActive: {},
- license.SubStateExpired: {},
- },
- },
- {
- from: license.SubStateExpired,
- expected: map[license.SubscriptionState]struct{}{
- license.SubStateActive: {},
- },
- },
- {
- from: license.SubStateSuspended,
- expected: map[license.SubscriptionState]struct{}{
- license.SubStateActive: {},
- license.SubStateExpired: {},
- },
- },
- }
-
- for _, tt := range tests {
- tt := tt
- t.Run(string(tt.from), func(t *testing.T) {
- got := ValidTransitionsFrom(tt.from)
- gotSet := make(map[license.SubscriptionState]struct{}, len(got))
- for _, target := range got {
- gotSet[target] = struct{}{}
- }
-
- if len(gotSet) != len(tt.expected) {
- t.Fatalf("unexpected number of transitions for %s: got=%d want=%d", tt.from, len(gotSet), len(tt.expected))
- }
-
- for expectedTarget := range tt.expected {
- if _, ok := gotSet[expectedTarget]; !ok {
- t.Fatalf("missing expected transition for %s -> %s", tt.from, expectedTarget)
- }
- }
- })
- }
-}
-
-func TestGetBehavior(t *testing.T) {
- tests := []struct {
- state license.SubscriptionState
- operations OperationClass
- featuresAvailable bool
- showWarning bool
- }{
- {
- state: license.SubStateTrial,
- operations: OpFull,
- featuresAvailable: true,
- showWarning: false,
- },
- {
- state: license.SubStateActive,
- operations: OpFull,
- featuresAvailable: true,
- showWarning: false,
- },
- {
- state: license.SubStateGrace,
- operations: OpFull,
- featuresAvailable: true,
- showWarning: true,
- },
- {
- state: license.SubStateExpired,
- operations: OpDegraded,
- featuresAvailable: false,
- showWarning: true,
- },
- {
- state: license.SubStateSuspended,
- operations: OpLocked,
- featuresAvailable: false,
- showWarning: true,
- },
- }
-
- for _, tt := range tests {
- tt := tt
- t.Run(string(tt.state), func(t *testing.T) {
- got := GetBehavior(tt.state)
- if got.State != tt.state {
- t.Fatalf("unexpected state in behavior: got=%s want=%s", got.State, tt.state)
- }
- if got.Operations != tt.operations {
- t.Fatalf("unexpected operations for %s: got=%s want=%s", tt.state, got.Operations, tt.operations)
- }
- if got.FeaturesAvailable != tt.featuresAvailable {
- t.Fatalf("unexpected features flag for %s: got=%t want=%t", tt.state, got.FeaturesAvailable, tt.featuresAvailable)
- }
- if got.ShowWarning != tt.showWarning {
- t.Fatalf("unexpected warning flag for %s: got=%t want=%t", tt.state, got.ShowWarning, tt.showWarning)
- }
- })
- }
-}
-
-func TestGetBehavior_UnknownState(t *testing.T) {
- got := GetBehavior(license.SubscriptionState("unknown_state"))
- expected := StateBehaviors[license.SubStateExpired]
- if got != expected {
- t.Fatalf("expected unknown state fallback to expired behavior: got=%+v want=%+v", got, expected)
- }
-}
-
-func TestDefaultDowngradePolicy(t *testing.T) {
- if DefaultDowngradePolicy.SoftHideGraceDays != 30 {
- t.Fatalf("unexpected SoftHideGraceDays: got=%d want=30", DefaultDowngradePolicy.SoftHideGraceDays)
- }
- if DefaultDowngradePolicy.HardDeleteAfterDays != 60 {
- t.Fatalf("unexpected HardDeleteAfterDays: got=%d want=60", DefaultDowngradePolicy.HardDeleteAfterDays)
- }
-}
diff --git a/internal/license/subscription/transitions.go b/internal/license/subscription/transitions.go
deleted file mode 100644
index 68d9deb7de..0000000000
--- a/internal/license/subscription/transitions.go
+++ /dev/null
@@ -1,22 +0,0 @@
-package subscription
-
-import (
- "github.com/rcourtman/pulse-go-rewrite/internal/license"
- pkglicensing "github.com/rcourtman/pulse-go-rewrite/pkg/licensing"
-)
-
-type Transition = pkglicensing.Transition
-type DowngradePolicy = pkglicensing.DowngradePolicy
-
-// CanTransition checks if a transition from one state to another is valid.
-func CanTransition(from, to license.SubscriptionState) bool {
- return pkglicensing.CanTransition(from, to)
-}
-
-// ValidTransitionsFrom returns all valid target states from the given state.
-func ValidTransitionsFrom(from license.SubscriptionState) []license.SubscriptionState {
- return pkglicensing.ValidTransitionsFrom(from)
-}
-
-// DefaultDowngradePolicy is the default policy for subscription downgrades.
-var DefaultDowngradePolicy = pkglicensing.DefaultDowngradePolicy