mirror of
https://github.com/pomerium/pomerium.git
synced 2025-08-03 16:59:22 +02:00
integration: add single-cluster integration tests (#2516)
* integration: add single-cluster integration tests * remove kind load
This commit is contained in:
parent
f5a558d4a0
commit
48cd10d46b
53 changed files with 7455 additions and 31 deletions
93
integration/cmd/pomerium-integration-tests/main.go
Normal file
93
integration/cmd/pomerium-integration-tests/main.go
Normal file
|
@ -0,0 +1,93 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
|
||||
"github.com/google/go-jsonnet"
|
||||
"github.com/peterbourgon/ff/v3/ffcli"
|
||||
"github.com/rs/zerolog/log"
|
||||
"sigs.k8s.io/yaml"
|
||||
)
|
||||
|
||||
func main() {
|
||||
generateCmd := &ffcli.Command{
|
||||
Name: "generate-configuration",
|
||||
Exec: func(ctx context.Context, args []string) error {
|
||||
return runGenerateConfiguration(ctx)
|
||||
},
|
||||
}
|
||||
rootCmd := &ffcli.Command{
|
||||
Subcommands: []*ffcli.Command{generateCmd},
|
||||
Exec: func(ctx context.Context, args []string) error {
|
||||
return flag.ErrHelp
|
||||
},
|
||||
}
|
||||
err := rootCmd.ParseAndRun(context.Background(), os.Args[1:])
|
||||
if err != nil && !errors.Is(err, flag.ErrHelp) {
|
||||
log.Fatal().Err(err).Send()
|
||||
}
|
||||
}
|
||||
|
||||
func runGenerateConfiguration(ctx context.Context) error {
|
||||
log.Info().Msg("generating configuration")
|
||||
|
||||
root := filepath.Join(".", "integration")
|
||||
if _, err := os.Stat(root); err != nil {
|
||||
return fmt.Errorf("expected integration subfolder in cwd")
|
||||
}
|
||||
tplRoot := filepath.Join(root, "tpl")
|
||||
|
||||
var allSrcPaths []string
|
||||
err := filepath.WalkDir(tplRoot, func(srcPath string, d fs.DirEntry, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if d.IsDir() {
|
||||
return nil
|
||||
}
|
||||
|
||||
allSrcPaths = append(allSrcPaths, srcPath)
|
||||
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
sort.Strings(allSrcPaths)
|
||||
|
||||
vm := jsonnet.MakeVM()
|
||||
vm.Importer(&jsonnet.FileImporter{JPaths: allSrcPaths})
|
||||
for _, srcPath := range allSrcPaths {
|
||||
if filepath.Ext(srcPath) != ".jsonnet" {
|
||||
continue
|
||||
}
|
||||
|
||||
dstPath := filepath.Join(root, srcPath[len(tplRoot)+1:])
|
||||
dstPath = dstPath[:len(dstPath)-len(filepath.Ext(dstPath))]
|
||||
|
||||
contents, err := vm.EvaluateFile(srcPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error evaluating jsonnet (path=%s): %w", srcPath, err)
|
||||
}
|
||||
asYAML, _ := yaml.JSONToYAML([]byte(contents))
|
||||
|
||||
err = os.MkdirAll(filepath.Dir(dstPath), 0755)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error creating directory (path=%s): %w", dstPath, err)
|
||||
}
|
||||
|
||||
err = os.WriteFile(dstPath, asYAML, 0600)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error writing file (path=%s): %w", dstPath, err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue