Skip to content

Commit

Permalink
Merge pull request #4 from eddycharly/ext
Browse files Browse the repository at this point in the history
feat: add ext packages
  • Loading branch information
eddycharly authored Apr 18, 2024
2 parents 24f8421 + f973d94 commit df8add2
Show file tree
Hide file tree
Showing 25 changed files with 1,829 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json

name: Tests

permissions: {}

on:
pull_request:
branches:
- main
push:
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
unit-tests:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Setup Go
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version-file: ext/go.mod
cache-dependency-path: ext/go.sum
- name: Run tests
run: |
set -e
cd ext && make tests
- name: Upload coverage
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
with:
name: ext-coverage.out
path: ext/coverage.out
retention-days: 1
if-no-files-found: error
1 change: 1 addition & 0 deletions ext/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
coverage.out
7 changes: 7 additions & 0 deletions ext/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

.PHONY: tests
tests: ## Run tests
tests:
@echo Running tests... >&2
@go test ./... -race -coverprofile=coverage.out -covermode=atomic
@go tool cover -html=coverage.out
28 changes: 28 additions & 0 deletions ext/file-info/ext.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package fileinfo

import (
"io/fs"

"github.com/kyverno/pkg/ext/file"
)

func IsYaml(info fs.FileInfo) bool {
if info.IsDir() {
return false
}
return file.IsYaml(info.Name())
}

func IsJson(info fs.FileInfo) bool {
if info.IsDir() {
return false
}
return file.IsJson(info.Name())
}

func IsYamlOrJson(info fs.FileInfo) bool {
if info.IsDir() {
return false
}
return file.IsYamlOrJson(info.Name())
}
19 changes: 19 additions & 0 deletions ext/file/ext.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package file

import (
"path/filepath"
)

func IsYaml(path string) bool {
ext := filepath.Ext(path)
return ext == ".yml" || ext == ".yaml"
}

func IsJson(path string) bool {
ext := filepath.Ext(path)
return ext == ".json"
}

func IsYamlOrJson(path string) bool {
return IsYaml(path) || IsJson(path)
}
110 changes: 110 additions & 0 deletions ext/file/ext_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package file

import (
"testing"
)

func TestIsYaml(t *testing.T) {
tests := []struct {
name string
path string
want bool
}{{
name: "empty",
path: "",
want: false,
}, {
name: "yaml",
path: "something.yaml",
want: true,
}, {
name: "yml",
path: "something.yml",
want: true,
}, {
name: "json",
path: "something.json",
want: false,
}, {
name: "pdf",
path: "something.pdf",
want: false,
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := IsYaml(tt.path); got != tt.want {
t.Errorf("IsYaml() = %v, want %v", got, tt.want)
}
})
}
}

func TestIsJson(t *testing.T) {
tests := []struct {
name string
path string
want bool
}{{
name: "empty",
path: "",
want: false,
}, {
name: "yaml",
path: "something.yaml",
want: false,
}, {
name: "yml",
path: "something.yml",
want: false,
}, {
name: "json",
path: "something.json",
want: true,
}, {
name: "pdf",
path: "something.pdf",
want: false,
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := IsJson(tt.path); got != tt.want {
t.Errorf("IsJson() = %v, want %v", got, tt.want)
}
})
}
}

func TestIsYamlOrJson(t *testing.T) {
tests := []struct {
name string
path string
want bool
}{{
name: "empty",
path: "",
want: false,
}, {
name: "yaml",
path: "something.yaml",
want: true,
}, {
name: "yml",
path: "something.yml",
want: true,
}, {
name: "json",
path: "something.json",
want: true,
}, {
name: "pdf",
path: "something.pdf",
want: false,
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := IsYamlOrJson(tt.path); got != tt.want {
t.Errorf("IsYamlOrJson() = %v, want %v", got, tt.want)
}
})
}
}
108 changes: 108 additions & 0 deletions ext/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
module github.com/kyverno/pkg/ext

go 1.21.4

require (
github.com/IGLOU-EU/go-wildcard v1.0.3
github.com/dustinkirkland/golang-petname v0.0.0-20231002161417-6a283f1aaaf2
github.com/fatih/color v1.16.0
github.com/stretchr/testify v1.9.0
k8s.io/apimachinery v0.29.2
k8s.io/client-go v0.29.2
sigs.k8s.io/kubectl-validate v0.0.2-0.20240220161158-e1c86ccfb593
)

require (
github.com/NYTimes/gziphandler v1.1.1 // indirect
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230305170008-8188dc5388df // indirect
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/coreos/go-semver v0.3.1 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/evanphx/json-patch v5.7.0+incompatible // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-logr/logr v1.3.0 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/jsonpointer v0.20.0 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.4 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/cel-go v0.17.7 // indirect
github.com/google/gnostic-models v0.6.9-0.20230804172637-c7be7c783f49 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.4.0 // indirect
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.1-0.20210315223345-82c243799c99 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_golang v1.17.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.45.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/spf13/cobra v1.8.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stoewer/go-strcase v1.3.0 // indirect
go.etcd.io/etcd/api/v3 v3.5.10 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.10 // indirect
go.etcd.io/etcd/client/v3 v3.5.10 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.46.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.45.0 // indirect
go.opentelemetry.io/otel v1.20.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.20.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.20.0 // indirect
go.opentelemetry.io/otel/metric v1.20.0 // indirect
go.opentelemetry.io/otel/sdk v1.20.0 // indirect
go.opentelemetry.io/otel/trace v1.20.0 // indirect
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.26.0 // indirect
golang.org/x/crypto v0.18.0 // indirect
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/oauth2 v0.14.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/term v0.16.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20231016165738-49dd2c1f3d0b // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231016165738-49dd2c1f3d0b // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b // indirect
google.golang.org/grpc v1.59.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.29.2 // indirect
k8s.io/apiextensions-apiserver v0.29.0 // indirect
k8s.io/apiserver v0.29.0 // indirect
k8s.io/component-base v0.29.0 // indirect
k8s.io/klog/v2 v2.110.1 // indirect
k8s.io/kube-openapi v0.0.0-20231113174909-778a5567bc1e // indirect
k8s.io/utils v0.0.0-20231127182322-b307cd553661 // indirect
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.28.1 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)
Loading

0 comments on commit df8add2

Please sign in to comment.