{"id":46829214,"url":"https://github.com/gdt-dev/core","last_synced_at":"2026-03-10T09:47:05.637Z","repository":{"id":314599948,"uuid":"1056116213","full_name":"gdt-dev/core","owner":"gdt-dev","description":"Core API and specification","archived":false,"fork":false,"pushed_at":"2025-12-05T20:08:47.000Z","size":138,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-12-08T21:42:28.379Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gdt-dev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-09-13T12:24:40.000Z","updated_at":"2025-12-05T11:54:21.000Z","dependencies_parsed_at":"2025-09-13T14:52:06.043Z","dependency_job_id":"7cae522a-6a1d-42c3-94e1-006f852040a9","html_url":"https://github.com/gdt-dev/core","commit_stats":null,"previous_names":["gdt-dev/core"],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/gdt-dev/core","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gdt-dev%2Fcore","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gdt-dev%2Fcore/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gdt-dev%2Fcore/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gdt-dev%2Fcore/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gdt-dev","download_url":"https://codeload.github.com/gdt-dev/core/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gdt-dev%2Fcore/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30329154,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-10T05:25:20.737Z","status":"ssl_error","status_checked_at":"2026-03-10T05:25:17.430Z","response_time":106,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-03-10T09:47:05.480Z","updated_at":"2026-03-10T09:47:05.624Z","avatar_url":"https://github.com/gdt-dev.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Core `gdt` library and specification\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/gdt-dev/core.svg)](https://pkg.go.dev/github.com/gdt-dev/core)\n[![Go Report Card](https://goreportcard.com/badge/github.com/gdt-dev/core)](https://goreportcard.com/report/github.com/gdt-dev/core)\n[![Build Status](https://github.com/gdt-dev/core/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/gdt-dev/core/actions)\n[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](CODE_OF_CONDUCT.md)\n\n`gdt` is a testing library that allows test authors to cleanly describe tests\nin a YAML file. `gdt` reads YAML files that describe a test's assertions and\nthen builds a set of structures that can be run by either the `gdt`\ncommand-line interface or the standard Go\n[`testing`](https://golang.org/pkg/testing/) `go test` tool.\n\n\n## `gdt` test scenario structure\n\nA `gdt` test scenario (or just \"scenario\") is simply a YAML file.\n\nAll `gdt` scenarios have the following fields:\n\n* `name`: (optional) string describing the contents of the test file. If\n  missing or empty, the filename is used as the name\n* `description`: (optional) string with longer description of the test file\n  contents\n* `defaults`: (optional) is a map of default options and configuration values\n* `fixtures`: (optional) list of strings indicating named fixtures that will be\n  started before any of the tests in the file are run\n* `depends`: (optional) list of [`Dependency`][dependency] objects that\n  describe a program binary that should be available in the host's `PATH`\n  that the test scenario depends on.\n* `depends.name`: string name of the program the test scenario depends on.\n* `depends.when`: (optional) object describing any constraints/conditions that\n  should apply to the evaluation of the dependency.\n* `depends.when.os`: (optional) string operating system. if set, the dependency\n  is only checked for that OS.\n* `depends.version`: (optional) struct containing version constraint and\n  selector instructions.\n* `depends.version.constraint`: optional string version constraint. if set, the\n  program or package must be available on the host `PATH` and must satisfy the\n  version constraint.\n* `depends.version.selector`: (optional) struct containing selector\n  instructions for gdt to determine the version of a dependent binary.\n* `depends.version.selector.args`: (optional) set of string arguments to call\n  the dependency binary with in order to get the program's version information.\n  If empty, we default to []string{`-v`}.\n* `depends.version.selector.filter`: (optional) regular expression to run\n  against the returned output from executing the dependency binary with the\n  `selector.args` arguments. If empty, we use a loose semver matching regex.\n* `skip-if`: (optional) list of [`Spec`][basespec] specializations that will be\n  evaluated *before* running any test in the scenario. If any of these\n  conditions evaluates successfully, the test scenario will be skipped.\n* `tests`: list of [`Spec`][basespec] specializations that represent the\n  runnable test units in the test scenario.\n\n[basespec]: https://github.com/gdt-dev/core/blob/ecee17249e1fa10147cf9191be0358923da44094/types/spec.go#L30\n[dependency]: https://github.com/gdt-dev/core/blob/e83cb2bcac4fbb73205c58851b22a8b0a6cc51b5/api/dependency.go\n\nThe scenario's `tests` field is the most important and the [`Spec`][basespec]\nobjects that it contains are the meat of a test scenario.\n\n### `gdt` test spec structure\n\nA spec represents a single *action* that is taken and zero or more\n*assertions* that represent what you expect to see resulting from that action.\n\n`gdt` plugins each define a specialized subclass of the base [`Spec`][basespec]\nthat contains fields that are specific to that type of test.\n\nFor example, there is an [`exec`][exec-plugin] plugin that allows you to\nexecute arbitrary commands and assert expected result codes and output. There\nis an [`http`][http-plugin] that allows you to call an HTTP URL and assert that\nthe response looks like what you expect. There is a [`kube`][kube-plugin]\nplugin that allows you to interact with a Kubernetes API, etc.\n\n`gdt` examines the YAML file that defines your test scenario and uses these\nplugins to parse individual test specs.\n\nAll test specs have the following fields:\n\n* `name`: (optional) string describing the test unit.\n* `description`: (optional) string with longer description of the test unit.\n* `timeout`: (optional) a string duration of time the test unit is expected to\n  complete within.\n* `retry`: (optional) an object containing retry configurationu for the test\n  unit. Some plugins will automatically attempt to retry the test action when\n  an assertion fails. This field allows you to control this retry behaviour for\n  each individual test.\n* `retry.interval`: (optional) a string duration of time that the test plugin\n  will retry the test action in the event assertions fail. The default interval\n  for retries is plugin-dependent.\n* `retry.attempts`: (optional) an integer indicating the number of times that a\n  plugin will retry the test action in the event assertions fail. The default\n  number of attempts for retries is plugin-dependent.\n* `retry.exponential`: (optional) a boolean indicating an exponential backoff\n  should be applied to the retry interval. The default is is plugin-dependent.\n* `wait` (optional) an object containing [wait information][wait] for the test\n  unit.\n* `wait.before`: a string duration of time that gdt should wait before\n  executing the test unit's action.\n* `wait.after`: a string duration of time that gdt should wait after executing\n  the test unit's action.\n* `on`: (optional) an object describing actions to take upon certain\n  conditions.\n* `on.fail`: (optional) an object describing an action to take when any\n  assertion fails for the test action.\n* `on.fail.exec`: a string with the exact command to execute upon test\n  assertion failure. You may execute more than one command but must include the\n  `on.fail.shell` field to indicate that the command should be run in a shell.\n* `on.fail.shell`: (optional) a string with the specific shell to use in executing the\n  command to run upon test assertion failure. If empty (the default), no shell\n  is used to execute the command and instead the operating system's `exec` family\n  of calls is used.\n\n[exec-plugin]: https://github.com/gdt-dev/core/tree/ecee17249e1fa10147cf9191be0358923da44094/plugin/exec\n[http-plugin]: https://github.com/gdt-dev/http\n[kube-plugin]: https://github.com/gdt-dev/kube\n[wait]: https://github.com/gdt-dev/core/blob/2791e11105fd3c36d1f11a7d111e089be7cdc84c/types/wait.go#L11-L25\n\n#### `exec` test spec structure\n\nThe `exec` plugin's test spec allows test authors to execute arbitrary commands and\nassert that the command results in an expected result code or output.\n\nIn addition to all the base `Spec` fields listed above, the `exec` plugin's\ntest spec also contains these fields:\n\n* `exec`: a string with the exact command to execute. You may execute more than\n  one command but must include the `shell` field to indicate that the command\n  should be run in a shell. It is best practice, however, to simply use\n  multiple `exec` specs instead of executing multiple commands in a single\n  shell call.\n* `shell`: (optional) a string with the specific shell to use in executing the\n  command. If empty (the default), no shell is used to execute the command and\n  instead the operating system's `exec` family of calls is used.\n* `var-stdout`: (optional) a string with the name of a variable to save the\n  contents of the test spec's `stdout` stream. This named variable can then be\n  referred from subsequent test specs. Note: this is a shortcut for the\n  longer-form `var:{VAR_NAME}:from:stdout`\n* `var-stderr`: (optional) a string with the name of a variable to save the\n  contents of the test spec's `stderr` stream. This named variable can then be\n  referred from subsequent test specs. Note: this is a shortcut for the\n  longer-form `var:{VAR_NAME}:from:stderr`\n* `var-rc`: (optional) a string with the name of a variable to save the\n  contents of the test spec's return/exitcode value. This named variable can\n  then be referred from subsequent test specs. Note: this is a shortcut for the\n  longer-form `var:{VAR_NAME}:from:returncode`\n* `var`: (optional) an object describing variables that can have values saved\n  and referred to by subsequent test specs. Each key in the `var` object is the\n  name of the variable to define. The `var.from` field contains a string\n  describing where the value for the variable should be sourced.\n* `var.$VARIABLE_NAME.from`: (required) a string describing where the variable\n  with name `$VARIABLE_NAME` should source its value. The strings `stdout`,\n  `stderr` and `returncode` refer to the corresponding stdout, stderr\n  and return/exitcode values. All other string values for `var.from` indicate\n  the name of the environment variable to read into the named variable.\n* `assert`: (optional) an object describing the conditions that will be\n  asserted about the test action.\n* `assert.require`: (optional) a boolean indicating whether a failed assertion\n  will cause the test scenario's execution to stop. The default behaviour of\n  `gdt` is to continue execution of subsequent test specs in a test scenario when\n  an assertion fails.\n* `assert.exit-code`: (optional) an integer with the expected exit code from the\n  executed command. The default successful exit code is 0 and therefore you do\n  not need to specify this if you expect a successful exit code.\n* `assert.out`: (optional) a [`PipeExpect`][pipeexpect] object containing\n  assertions about content in `stdout`.\n* `assert.out.is`: (optional) a string with the exact contents of `stdout` you expect\n  to get.\n* `assert.out.all`: (optional) a string or list of strings that *all* must be\n  present in `stdout`.\n* `assert.out.any`: (optional) a string or list of strings of which *at\n  least one* must be present in `stdout`.\n* `assert.out.none`: (optional) a string or list of strings of which *none\n  should be present* in `stdout`.\n* `assert.err`: (optional) a [`PipeAssertions`][pipeexpect] object containing\n  assertions about content in `stderr`.\n* `assert.err.is`: (optional) a string with the exact contents of `stderr` you expect\n  to get.\n* `assert.err.all`: (optional) a string or list of strings that *all* must be\n  present in `stderr`.\n* `assert.err.any`: (optional) a string or list of strings of which *at\n  least one* must be present in `stderr`.\n* `assert.err.none`: (optional) a string or list of strings of which *none\n  should be present* in `stderr`.\n\n[execspec]: https://github.com/gdt-dev/core/blob/2791e11105fd3c36d1f11a7d111e089be7cdc84c/exec/spec.go#L11-L34\n[pipeexpect]: https://github.com/gdt-dev/core/blob/2791e11105fd3c36d1f11a7d111e089be7cdc84c/exec/assertions.go#L15-L26\n\n### Marking a program or package dependency for a test scenario\n\nOften when creating `gdt` test scenarios, you will want to declare that the\nscenario requires a particular application be available in the host's `PATH`.\n\nUse the `depends` field to tell `gdt` about these requirements:\n\n```yaml\nname: scenario requiring `myapp` binary be available to execute\n\ndepends:\n - name: myapp\n\ntests:\n - name: start-myapp\n   exec: myapp start\n```\n\nRunning the above test scenario when `myapp` is not available to execute\nresults in a runtime error:\n\n```\n$ gdt run myapp.yaml\nError: runtime error: dependency not satisfied: myapp\n```\n\nYou can specify that a dependency only be applicable on a specific operating\nsystem using the `depends.when.os` field:\n\n```yaml\nname: scenario requiring `myapp` binary be available to execute\n\ndepends:\n - name: myapp\n   when:\n     os: linux\n\ntests:\n - name: start-myapp\n   exec: myapp start\n```\n\nRunning the above scenario on Linux yields the same runtime error:\n\n```\n$ gdt run myapp.yaml\nError: runtime error: dependency not satisfied: myapp (OS:linux)\n```\n\nHowever changing the `depends.when.os` to `windows`:\n\n```yaml\nname: scenario requiring `myapp` binary be available to execute\n\ndepends:\n - name: myapp\n   when:\n     os: windows\n\ntests:\n - name: start-myapp\n   exec: myapp start\n```\n\nRunning the scenario will show a different runtime error that is dependent on\nthe operating system:\n\n```\n$ gdt run myapp.yaml\nError: runtime error: exec: \"myapp\": executable file not found in $PATH\n```\n\nYou may also specify a particular version constraint that must pass for a\ndependent binary with the `depends.version.constraint` field. For example,\nlet's assume I want to declare my test scenario requires that at least version\n`1.2.3` of `myapp` must be present on the host machine, I would do this:\n\n```yaml\ndepends:\n - name: myapp\n   version:\n     constraint: \"\u003e=1.2.3\"\n```\n\nThe `depends.version.constraint` field should be a valid Semantic Versioning\nconstraint. Read more about [Semantic Version constraints][semver-constraints].\n\nBy default to determine a binary's version, we pass a `-v` flag to the binary\nitself. If you know that a binary uses a different way of returning its version\ninformation, you can use the `depends.version.selector.args` field. As an\nexample, the `ls` command line utility on Linux returns its version information\nwhen you pass the `--version` CLI flag, as shown here:\n\n```\n\u003e ls --version\nls (GNU coreutils) 9.4\nCopyright (C) 2023 Free Software Foundation, Inc.\nLicense GPLv3+: GNU GPL version 3 or later \u003chttps://gnu.org/licenses/gpl.html\u003e.\nThis is free software: you are free to change and redistribute it.\nThere is NO WARRANTY, to the extent permitted by law.\n\nWritten by Richard M. Stallman and David MacKenzie.\n```\n\nIf you wanted to require that, say, version 9.1 and later of the `ls`\ncommand-line utility was present on the host machine, you would do the\nfollowing:\n\n```yaml\ndepends:\n - name: ls\n   version:\n     constraint: \"\u003e=9.1\"\n     selector:\n       args:\n        - \"--version\"\n```\n\n[semver-constraints]: https://github.com/Masterminds/semver/blob/master/README.md#checking-version-constraints\n\n### Passing variables to subsequent test specs\n\nA `gdt` test scenario is comprised of a list of test specs. These test specs\nare executed in sequential order. If you want to have one test spec be able to\nuse some output or value calculated or asserted in a previous step, you can use\nthe `gdt` variable system.\n\nHere's an test scenario that shows how to define variables in a test spec and\nhow to use those variables in later test specs.\n\nfile: `plugin/exec/testdata/var-save-restore.yaml`:\n\n```yaml\nname: var-save-restore\ndescription: a scenario that tests variable save/restore across multiple test specs\ntests:\n  - exec: echo 42\n    var-stdout: VAR_STDOUT\n\n  - exec: echo $$VAR_STDOUT\n    var-rc: VAR_RC\n    assert:\n      out:\n        is: 42\n\n  - exec: echo $$VAR_RC\n    assert:\n      out:\n        is: 0\n\n  - exec: echo 42\n    assert:\n      out:\n        is: $$VAR_STDOUT\n```\n\nIn the first test spec, we specify that we want to store the value of the\n`stdout` stream in a variable called `VAR_STDOUT`:\n\n```yaml\n  - exec: echo 42\n    var-stdout: VAR_STDOUT\n```\n\nIn the second test spec, we refer to the `VAR_STDOUT` variable using the\ndouble-dollar-sign notation in the `exec` field and also specify a `VAR_RC`\nvariable to contain the value of the return/exitcode from the executed\nstatement (`echo 42`):\n\n```yaml\n  - exec: echo $$VAR_STDOUT\n    var-rc: VAR_RC\n    assert:\n      out:\n        is: 42\n```\n\n\u003e **NOTE**: We use the double-dollar-sign notation because by default, `gdt`\n\u003e replaces all single-dollar-sign notations with environment variables *BEFORE*\n\u003e executing the test specs in a test scenario. Using the double-dollar-sign\n\u003e notation means that environment variable substitution does not impact the\n\u003e referencing of `gdt` variables referenced in a test spec.\n\nIn the third test spec, we simply echo out the value of that `VAR_RC` variable\nand assert that the stdout stream contains the string \"0\" (since `echo 42`\nreturns 0.):\n\n```yaml\n  - exec: echo $$VAR_RC\n    assert:\n      out:\n        is: 0\n```\n\nFinally, in the fourth step, we demonstrate that we can refer to the\n`VAR_STDOUT` variable defined in the very first test spec from the\n`assert.out.is` field. This shows the flexibility of the `gdt` variable system.\nYou can define variables using a simple declarative syntax and then refer to\nthe value of those variables using the double-dollar-sign notation in any\nsubsequent test spec.\n\n### Timeouts and retrying assertions\n\nWhen evaluating assertions for a test spec, `gdt` inspects the test's\n`timeout` value to determine how long to retry the `get` call and recheck\nthe assertions.\n\nIf a test's `timeout` is empty, `gdt` inspects the scenario's\n`defaults.timeout` value. If both of those values are empty, `gdt` will look\nfor any default `timeout` value that the plugin uses.\n\nIf you're interested in seeing the individual results of `gdt`'s\nassertion-checks for a single `get` call, you can use the `gdt.WithDebug()`\nfunction, like this test function demonstrates:\n\nfile: `testdata/matches.yaml`:\n\n```yaml\nname: matches\ndescription: create a deployment and check the matches condition succeeds\nfixtures:\n  - kind\ntests:\n  - name: create-deployment\n    kube:\n      create: testdata/manifests/nginx-deployment.yaml\n  - name: deployment-exists\n    kube:\n      get: deployments/nginx\n    assert:\n      matches:\n        spec:\n          replicas: 2\n          template:\n            metadata:\n              labels:\n                app: nginx\n        status:\n          readyReplicas: 2\n  - name: delete-deployment\n    kube:\n      delete: deployments/nginx\n```\n\nfile: `matches_test.go`\n\n```go\nimport (\n    \"github.com/gdt-dev/core\"\n    _ \"github.com/gdt-dev/kube\"\n    kindfix \"github.com/gdt-dev/kube/fixture/kind\"\n)\n\nfunc TestMatches(t *testing.T) {\n\tfp := filepath.Join(\"testdata\", \"matches.yaml\")\n\n\tkfix := kindfix.New()\n\n\ts, err := gdt.From(fp)\n\n\tctx := gdt.NewContext(gdt.WithDebug())\n\tctx = gdt.RegisterFixture(ctx, \"kind\", kfix)\n\ts.Run(ctx, t)\n}\n```\n\nHere's what running `go test -v matches_test.go` would look like:\n\n```\n$ go test -v matches_test.go\n=== RUN   TestMatches\n=== RUN   TestMatches/matches\n=== RUN   TestMatches/matches/create-deployment\n=== RUN   TestMatches/matches/deployment-exists\ndeployment-exists (try 1 after 1.303µs) ok: false, terminal: false\ndeployment-exists (try 1 after 1.303µs) failure: assertion failed: match field not equal: $.status.readyReplicas not present in subject\ndeployment-exists (try 2 after 595.62786ms) ok: false, terminal: false\ndeployment-exists (try 2 after 595.62786ms) failure: assertion failed: match field not equal: $.status.readyReplicas not present in subject\ndeployment-exists (try 3 after 1.020003807s) ok: false, terminal: false\ndeployment-exists (try 3 after 1.020003807s) failure: assertion failed: match field not equal: $.status.readyReplicas not present in subject\ndeployment-exists (try 4 after 1.760006109s) ok: false, terminal: false\ndeployment-exists (try 4 after 1.760006109s) failure: assertion failed: match field not equal: $.status.readyReplicas had different values. expected 2 but found 1\ndeployment-exists (try 5 after 2.772416449s) ok: true, terminal: false\n=== RUN   TestMatches/matches/delete-deployment\n--- PASS: TestMatches (3.32s)\n    --- PASS: TestMatches/matches (3.30s)\n        --- PASS: TestMatches/matches/create-deployment (0.01s)\n        --- PASS: TestMatches/matches/deployment-exists (2.78s)\n        --- PASS: TestMatches/matches/delete-deployment (0.02s)\nPASS\nok  \tcommand-line-arguments\t3.683s\n```\n\nYou can see from the debug output above that `gdt` created the Deployment and\nthen did a `kube.get` for the `deployments/nginx` Deployment. Initially\n(attempt 1), the `assert.matches` assertion failed because the\n`status.readyReplicas` field was not present in the returned resource. `gdt`\nretried the `kube.get` call 4 more times (attempts 2-5), with attempts 2 and 3\nfailed the existence check for the `status.readyReplicas` field and attempt 4\nfailing the *value* check for the `status.readyReplicas` field being `1`\ninstead of the expected `2`. Finally, when the Deployment was completely rolled\nout, attempt 5 succeeded in all the `assert.matches` assertions.\n\n## Contributing and acknowledgements\n\n`gdt` was inspired by [Gabbi](https://github.com/cdent/gabbi), the excellent\nPython declarative testing framework. `gdt` tries to bring the same clear,\nconcise test definitions to the world of Go functional testing.\n\nThe Go gopher logo, from which gdt's logo was derived, was created by Renee\nFrench.\n\nContributions to `gdt` are welcomed! Feel free to open a Github issue or submit\na pull request.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgdt-dev%2Fcore","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgdt-dev%2Fcore","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgdt-dev%2Fcore/lists"}