-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Remove `--doNotCorrect` option, I misunderstood some of the docs * Added testing workflow & some tests * Misc configuration management
- Loading branch information
1 parent
4e513eb
commit f977fc7
Showing
10 changed files
with
144 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
lib/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: CI/CD | ||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: {} | ||
jobs: | ||
lint-and-test: | ||
name: Lint and Test | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 19 | ||
cache: npm | ||
- name: Download dependencies | ||
run: npm install | ||
- name: Build | ||
run: npm run build | ||
- name: Lint | ||
run: npm run lint | ||
- name: Test | ||
run: npm run test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ node_modules/ | |
lib/ | ||
.vscode/ | ||
scratch/ | ||
coverage/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Config } from 'jest'; | ||
|
||
export default { | ||
preset: 'ts-jest', | ||
collectCoverage: false, | ||
coverageDirectory: '<rootDir>/coverage', | ||
coverageThreshold: { | ||
global: { | ||
branches: 80, | ||
functions: 80, | ||
lines: 80, | ||
statements: 80, | ||
}, | ||
}, | ||
coverageProvider: 'v8', | ||
testEnvironment: 'node', | ||
modulePathIgnorePatterns: ['<rootDir>/lib'], | ||
} as Config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import fs from 'fs'; | ||
import YAML from 'yaml'; | ||
import convertCrd from './convert'; | ||
|
||
describe('convertCrd', () => { | ||
it('should generate a single document schema', () => { | ||
const crdString = fs.readFileSync('./test_data/simpleCrd.yaml', 'utf-8'); | ||
const crd = YAML.parse(crdString); | ||
const schema = convertCrd(crd); | ||
|
||
if (typeof schema === 'boolean') { | ||
fail('Schema should not be of type boolean (this is just a type assertion)'); | ||
} | ||
|
||
expect(schema.title).toBe('crontabs.stable.example.com'); | ||
expect(schema.type).toBe('object'); | ||
|
||
// Test generated crd properties | ||
|
||
if (typeof schema.properties?.apiVersion === 'boolean') { | ||
fail('Schema should not be of type boolean (this is just a type assertion)'); | ||
} | ||
expect(schema.properties?.apiVersion?.['enum']).toStrictEqual(['stable.example.com/v1']); | ||
|
||
if (typeof schema.properties?.kind === 'boolean') { | ||
fail('Schema should not be of type boolean (this is just a type assertion)'); | ||
} | ||
expect(schema.properties?.kind?.['const']).toBe('CronTab'); | ||
|
||
// Test schema inclusion | ||
|
||
if (schema.allOf?.length !== 1 || typeof schema.allOf[0] === 'boolean') { | ||
fail('Schema should have exactly one generated version that is not of type boolean'); | ||
} | ||
|
||
expect(schema.allOf[0].if).toStrictEqual({ | ||
properties: { | ||
apiVersion: { | ||
const: 'stable.example.com/v1', | ||
}, | ||
}, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# via https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#create-a-customresourcedefinition | ||
apiVersion: apiextensions.k8s.io/v1 | ||
kind: CustomResourceDefinition | ||
metadata: | ||
# name must match the spec fields below, and be in the form: <plural>.<group> | ||
name: crontabs.stable.example.com | ||
spec: | ||
# group name to use for REST API: /apis/<group>/<version> | ||
group: stable.example.com | ||
# list of versions supported by this CustomResourceDefinition | ||
versions: | ||
- name: v1 | ||
# Each version can be enabled/disabled by Served flag. | ||
served: true | ||
# One and only one version must be marked as the storage version. | ||
storage: true | ||
schema: | ||
openAPIV3Schema: | ||
type: object | ||
properties: | ||
spec: | ||
type: object | ||
properties: | ||
cronSpec: | ||
type: string | ||
image: | ||
type: string | ||
replicas: | ||
type: integer | ||
# either Namespaced or Cluster | ||
scope: Namespaced | ||
names: | ||
# plural name to be used in the URL: /apis/<group>/<version>/<plural> | ||
plural: crontabs | ||
# singular name to be used as an alias on the CLI and for display | ||
singular: crontab | ||
# kind is normally the CamelCased singular type. Your resource manifests use this. | ||
kind: CronTab | ||
# shortNames allow shorter string to match your resource on the CLI | ||
shortNames: | ||
- ct |