Skip to content

Commit

Permalink
add back test
Browse files Browse the repository at this point in the history
Signed-off-by: Austin Abro <[email protected]>
  • Loading branch information
AustinAbro321 committed Jul 30, 2024
1 parent fd680fc commit cbc25f2
Showing 1 changed file with 77 additions and 75 deletions.
152 changes: 77 additions & 75 deletions src/pkg/lint/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
package lint

import (
"fmt"
"os"
"testing"

goyaml "github.com/goccy/go-yaml"
"github.com/stretchr/testify/require"
"github.com/zarf-dev/zarf/src/pkg/variables"
"github.com/zarf-dev/zarf/src/types"
)

Expand Down Expand Up @@ -38,81 +40,81 @@ func TestZarfSchema(t *testing.T) {
},
expectedSchemaStrings: nil,
},
// {
// name: "no comp or kind",
// pkg: types.ZarfPackage{
// Metadata: types.ZarfMetadata{
// Name: "no-comp-or-kind",
// },
// Components: []types.ZarfComponent{},
// },
// expectedSchemaStrings: []string{
// "kind: kind must be one of the following: \"ZarfInitConfig\", \"ZarfPackageConfig\"",
// "components: Array must have at least 1 items",
// },
// },
// {
// name: "invalid package",
// pkg: types.ZarfPackage{
// Kind: types.ZarfInitConfig,
// Metadata: types.ZarfMetadata{
// Name: "-invalid-name",
// },
// Components: []types.ZarfComponent{
// {
// Name: "invalid-name",
// Only: types.ZarfComponentOnlyTarget{
// LocalOS: "unsupportedOS",
// },
// Import: types.ZarfComponentImport{
// Path: fmt.Sprintf("start%send", types.ZarfPackageTemplatePrefix),
// URL: fmt.Sprintf("oci://start%send", types.ZarfPackageTemplatePrefix),
// },
// },
// {
// Name: "actions",
// Actions: types.ZarfComponentActions{
// OnCreate: types.ZarfComponentActionSet{
// Before: []types.ZarfComponentAction{
// {
// Cmd: "echo 'invalid setVariable'",
// SetVariables: []variables.Variable{{Name: "not_uppercase"}},
// },
// },
// },
// OnRemove: types.ZarfComponentActionSet{
// OnSuccess: []types.ZarfComponentAction{
// {
// Cmd: "echo 'invalid setVariable'",
// SetVariables: []variables.Variable{{Name: "not_uppercase"}},
// },
// },
// },
// },
// },
// },
// Variables: []variables.InteractiveVariable{
// {
// Variable: variables.Variable{Name: "not_uppercase"},
// },
// },
// Constants: []variables.Constant{
// {
// Name: "not_uppercase",
// },
// },
// },
// expectedSchemaStrings: []string{
// "metadata.name: Does not match pattern '^[a-z0-9][a-z0-9\\-]*$'",
// "variables.0.name: Does not match pattern '^[A-Z0-9_]+$'",
// "constants.0.name: Does not match pattern '^[A-Z0-9_]+$'",
// "components.0.only.localOS: components.0.only.localOS must be one of the following: \"linux\", \"darwin\", \"windows\"",
// "components.1.actions.onCreate.before.0.setVariables.0.name: Does not match pattern '^[A-Z0-9_]+$'",
// "components.1.actions.onRemove.onSuccess.0.setVariables.0.name: Does not match pattern '^[A-Z0-9_]+$'",
// "components.0.import.path: Must not validate the schema (not)",
// "components.0.import.url: Must not validate the schema (not)",
// },
// },
{
name: "no comp or kind",
pkg: types.ZarfPackage{
Metadata: types.ZarfMetadata{
Name: "no-comp-or-kind",
},
Components: []types.ZarfComponent{},
},
expectedSchemaStrings: []string{
"kind: kind must be one of the following: \"ZarfInitConfig\", \"ZarfPackageConfig\"",
"components: Array must have at least 1 items",
},
},
{
name: "invalid package",
pkg: types.ZarfPackage{
Kind: types.ZarfInitConfig,
Metadata: types.ZarfMetadata{
Name: "-invalid-name",
},
Components: []types.ZarfComponent{
{
Name: "invalid-name",
Only: types.ZarfComponentOnlyTarget{
LocalOS: "unsupportedOS",
},
Import: types.ZarfComponentImport{
Path: fmt.Sprintf("start%send", types.ZarfPackageTemplatePrefix),
URL: fmt.Sprintf("oci://start%send", types.ZarfPackageTemplatePrefix),
},
},
{
Name: "actions",
Actions: types.ZarfComponentActions{
OnCreate: types.ZarfComponentActionSet{
Before: []types.ZarfComponentAction{
{
Cmd: "echo 'invalid setVariable'",
SetVariables: []variables.Variable{{Name: "not_uppercase"}},
},
},
},
OnRemove: types.ZarfComponentActionSet{
OnSuccess: []types.ZarfComponentAction{
{
Cmd: "echo 'invalid setVariable'",
SetVariables: []variables.Variable{{Name: "not_uppercase"}},
},
},
},
},
},
},
Variables: []variables.InteractiveVariable{
{
Variable: variables.Variable{Name: "not_uppercase"},
},
},
Constants: []variables.Constant{
{
Name: "not_uppercase",
},
},
},
expectedSchemaStrings: []string{
"metadata.name: Does not match pattern '^[a-z0-9][a-z0-9\\-]*$'",
"variables.0.name: Does not match pattern '^[A-Z0-9_]+$'",
"constants.0.name: Does not match pattern '^[A-Z0-9_]+$'",
"components.0.only.localOS: components.0.only.localOS must be one of the following: \"linux\", \"darwin\", \"windows\"",
"components.1.actions.onCreate.before.0.setVariables.0.name: Does not match pattern '^[A-Z0-9_]+$'",
"components.1.actions.onRemove.onSuccess.0.setVariables.0.name: Does not match pattern '^[A-Z0-9_]+$'",
"components.0.import.path: Must not validate the schema (not)",
"components.0.import.url: Must not validate the schema (not)",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit cbc25f2

Please sign in to comment.