Giter Club home page Giter Club logo

gitlabcibuilder's Introduction

What is this

This Java library offers assertions to unit test your GitLab CI configuration. Unit testing your GitLab CI configuration has the following advantages:

  • Avoid regression
  • Quick feedback loop without breaking the rest of the pipeline
  • Run tests as part of the merge request

This allows you to write tests, so you don't have to merge changes only to find that you've broken the build.

The downside is: This is only a superficial implementation of the gitlab ci yaml: https://docs.gitlab.com/ee/ci/yaml/. The focus is on testing the workflow.

API

GitlabCiAssert.assertAllStagesKnown

This assertion checks that all stages used by the jobs are known:

GitlabCiAssert.assertAllStagesKnown(GitlabPipelineFileReader.pipelineInProject());

GitlabCiAssert.assertJobsRunsExactly

This assertion checks that an exact set of jobs will run, given a set of variables. The variables are optional.

GitlabCiAssert.assertJobsRunsExactly(GitlabPipelineFileReader.pipelineInProject(), Set.of("build-job", "test-job2", "deploy-prod",
                "test-job1"));

To check if specific jobs run when a specific variable is set, you can use:

GitlabCiAssert.assertJobsRunsExactly(GitlabPipelineFileReader.pipelineInProject(), Set.of("build-job", "test-job2", "deploy-prod",
                "test-job1"));

GitlabCiAssert.assertNeeds

This assertion checks that all needs are met. i.e., every job that has a need has this need met, given it was resolved in a previous or the current stage (or it's in a default state).

GitlabCiAssert.assertNeeds(GitlabPipelineFileReader.pipelineInProject());

GitlabCiAssert.assertContainsJobs

This assertion checks that a set of jobs will run, given a set of variables. The variables are optional.

GitlabCiAssert.assertContainsJobs(GitlabPipelineFileReader.pipelineInProject(), Set<String> expectedJobs, Variable... variables);

GitlabCiAssert.assertJobsNotRun

This assertion checks that a set of jobs will NOT run, given a set of variables. The variables are optional.

GitlabCiAssert.assertJobsNotRun(GitlabPipelineFileReader.pipelineInProject(), Set<String> expectedJobs, Variable... variables);

Useful functions

A list of predefined variables is available in PredefinedVariables.

If, for whatever reason, your GitLab pipeline is defined in a different location, you can use:

new GitlabPipelineFileReader().read(File file)

Limitations

The gitlab ci specification is huge. This tool loads only a small set of the gitlab ci specification.

The following are supported:

  • Loading job, rules, if conditions, when clauses.
  • Loading the job script, no support to run them.
  • Loading other local .yml files.

gitlabcibuilder's People

Contributors

denshade avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.