Preview affected orgs by position source and require keep or migrate for default-sourced positions. Commit deletion, renumbering, and holder reconciliation atomically while preserving other-source delivery.
148 lines
4.2 KiB
Go
148 lines
4.2 KiB
Go
package integration
|
|
|
|
import "testing"
|
|
|
|
func TestValidateManifest(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
m Manifest
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "valid provisioning provider",
|
|
m: Manifest{
|
|
Slug: "example",
|
|
Kind: KindProvisioning,
|
|
DisplayName: "Example",
|
|
Operations: []Operation{OpCreate, OpDelete, OpList},
|
|
ResourceKeys: []string{"example_sites"},
|
|
},
|
|
},
|
|
{
|
|
name: "valid payment provider with no ops or keys",
|
|
m: Manifest{Slug: "stripe", Kind: KindPayment, DisplayName: "Stripe"},
|
|
},
|
|
{
|
|
name: "slug with underscore is rejected",
|
|
m: Manifest{Slug: "next_cloud", Kind: KindProvisioning, DisplayName: "NextCloud"},
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "slug with uppercase is rejected",
|
|
m: Manifest{Slug: "Example", Kind: KindProvisioning, DisplayName: "Example"},
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "unknown kind is rejected",
|
|
m: Manifest{Slug: "example", Kind: ProviderKind("storage"), DisplayName: "Example"},
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "unknown operation is rejected",
|
|
m: Manifest{Slug: "example", Kind: KindProvisioning, DisplayName: "Example", Operations: []Operation{"archive"}},
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "resource key not prefixed with slug is rejected",
|
|
m: Manifest{Slug: "example", Kind: KindProvisioning, DisplayName: "Example", ResourceKeys: []string{"sites"}},
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "resource key prefixed by a different provider is rejected",
|
|
m: Manifest{Slug: "example", Kind: KindProvisioning, DisplayName: "Example", ResourceKeys: []string{"nextcloud_files"}},
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "set_status with active plus a non-active state is valid",
|
|
m: Manifest{
|
|
Slug: "example", Kind: KindProvisioning, DisplayName: "Example",
|
|
Operations: []Operation{OpCreate, OpSetStatus, OpDelete, OpList},
|
|
States: []State{StateActive, StateReadonly, StateArchived},
|
|
},
|
|
},
|
|
{
|
|
name: "set_status without a non-active state is rejected",
|
|
m: Manifest{
|
|
Slug: "example", Kind: KindProvisioning, DisplayName: "Example",
|
|
Operations: []Operation{OpSetStatus, OpList},
|
|
States: []State{StateActive},
|
|
},
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "set_status without the active state is rejected",
|
|
m: Manifest{
|
|
Slug: "example", Kind: KindProvisioning, DisplayName: "Example",
|
|
Operations: []Operation{OpSetStatus, OpList},
|
|
States: []State{StateReadonly},
|
|
},
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "states declared without set_status are rejected",
|
|
m: Manifest{
|
|
Slug: "example", Kind: KindProvisioning, DisplayName: "Example",
|
|
Operations: []Operation{OpCreate, OpList},
|
|
States: []State{StateActive, StateReadonly},
|
|
},
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "malformed state value is rejected",
|
|
m: Manifest{
|
|
Slug: "example", Kind: KindProvisioning, DisplayName: "Example",
|
|
Operations: []Operation{OpSetStatus, OpList},
|
|
States: []State{StateActive, "Read-Only"},
|
|
},
|
|
wantErr: true,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
err := validateManifest(tt.m)
|
|
if (err != nil) != tt.wantErr {
|
|
t.Fatalf("validateManifest() error = %v, wantErr %v", err, tt.wantErr)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestCheckSlugNesting(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
slugs []string
|
|
platformKeys []string
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "no collision",
|
|
slugs: []string{"example", "nextcloud"},
|
|
platformKeys: []string{"storage_bytes", "seats"},
|
|
},
|
|
{
|
|
name: "slug equals a platform key leading token",
|
|
slugs: []string{"storage"},
|
|
platformKeys: []string{"storage_bytes"},
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "slug equals a single-token platform key",
|
|
slugs: []string{"seats"},
|
|
platformKeys: []string{"seats"},
|
|
wantErr: true,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
set := make(map[string]bool, len(tt.slugs))
|
|
for _, s := range tt.slugs {
|
|
set[s] = true
|
|
}
|
|
err := checkSlugNesting(set, tt.platformKeys)
|
|
if (err != nil) != tt.wantErr {
|
|
t.Fatalf("checkSlugNesting() error = %v, wantErr %v", err, tt.wantErr)
|
|
}
|
|
})
|
|
}
|
|
}
|