Coder Social home page Coder Social logo

cyfyifanchen / docs-sdk-go Goto Github PK

View Code? Open in Web Editor NEW

This project forked from couchbase/docs-sdk-go

0.0 0.0 0.0 2.12 MB

The Go SDK documentation source files used in the new Couchbase Docs site.

Home Page: https://docs.couchbase.com

Shell 10.81% Go 87.04% Makefile 1.36% Dockerfile 0.79%

docs-sdk-go's Introduction

badge.svg?branch=release%2F2 badge.svg?branch=release%2F2

Couchbase Go SDK Documentation

This repository hosts the documentation source for the Couchbase Go SDK.

Contributing

Check out our contributing guide to learn how to:

  • submit a bug or feedback issue

  • set up your documentation workspace

  • build the documentation

  • submit a pull request

Thank you for helping to make the documentation better.

Docs Component Configuration

This repository contains an Antora docs component. Keep in mind these key repository features:

  • Component name, version, and start page are configured in each branch’s antora.yml file.

  • The navigation for all of the modules is stored in the ROOT module’s nav.adoc file.

  • Production branches use the release/X.Y naming pattern (e.g., release/5.5, release/6.0).

    • The docs site playbook instructs Antora to automatically aggregate any branch names that start with release/.

Documentation Site Toolchain

The documentation source files are marked up with AsciiDoc. Once merged into a version branch, the source files and their assets are aggregated, converted to HTML, and published by Antora to our staging and production sites. The docs components and site UI are orchestrated by the docs site playbook. See the contributing guide to learn more.

Documentation Code Sample Testing

To ensure that the code samples included in the documentation are correct and produce the results we expect, we have setup scripts that build and test each example file.

For testing we use the bats-core automation framework to run the code and bats-assert assertion library to make assertions on the output where necessary.

The tests run against the latest Couchbase Server docker image with the relevant SDK (Go in this case) provided alongside it.

To facilitate running the tests there is a Makefile in the /modules directory of the project.

There you will find all the relevant commands needed to execute the docker container and the test/build scripts.

Running a test

Before you can run the tests you will need to ensure you have Docker and npm available on your machine.

To run the example tests you will need to build the testing Docker image, run the container and execute your tests.

Tip
After your first build of the docker image you won’t need to build it every time you want to run the tests.

Here are the steps required to achieve this:

  • cd into the /modules directory and run make cb-build to build a local image of Couchbase Server + Go SDK.

  • Once that has completed succesfully you can run make cb-start to run the docker container.

Note that this can take some time as it will configure couchbase server with all the required test data (e.g. travel-sample bucket) for the examples to run successfully.

  • If you run docker ps in a separate shell you should see a container called cb-test running.

CONTAINER ID   IMAGE                        COMMAND                  CREATED          STATUS          PORTS                                                                           NAMES
ed861cf827ec   couchbase:cb7-sdk3-go-ub20   "/entrypoint.sh couc…"   51 minutes ago   Up 51 minutes   11207/tcp, 11210-11211/tcp, 0.0.0.0:8091-8096->8091-8096/tcp, 18091-18096/tcp   cb-test
  • Once the container is up you can run make TEST_NAME="startusing.go" single-test to run an individual test.

  • You should expect to see the following output in your shell:

 ✓ [hello-world] - startusing.go [539]

1 test, 0 failures in 1 seconds
  • If you want to run all the code sample tests you can also execute make tests.

  • To stop the docker container you can simply run make cb-stop, this will stop and remove the docker container, but will keep the local image should you need to start it up again.

Tip
Because we mount the /modules directory in the cb-test container, you will see your local code changes reflected in the container instantly, so there is no need to stop and start the container when debugging your code.

Creating a new test

If you look at the /modules/test directory you will find files with the .bats extension, which are essentially our test files.

Depending on where your code sample is going to be located (e.g. /modules/devguide), you will see a corresponding test file in the test directory. This is mainly to keep the tests organised and easy to find.

Here is an example test case:

@test "[devguide] - your-example-file.go" {
    runExample <your-example-file-name.go>
    assert_success
    assert_output --partial "some assertion substring"
}

runExample is simply a helper function provided in test_helper.bash, which takes care of invoking your go run command. The idea is that any generic test functions can be placed there to be used across any test.

assert_success is a helper function provied by the bats-assert library and checks whether your command has successfully exited with a status of 0. If not, it will fail the test.

assert_output --partial is another bats-assert helper that checks if the output of your code sample contains the substring provided. The assertion will fail if the string is not found.

Note that it will not always be necessary to assert the output of your code sample, in those cases just using assert_success will be enough.

CI - Github Actions

When submitting a PR, the code sample tests will run against your changes in the same manner as your local machine using Github Actions.

You can see the workflow definitions in the .github folder.

docs-sdk-go's People

Contributors

richardsmedley avatar chvck avatar maria-robobug avatar osfameron avatar tom-rosewell avatar brett19 avatar cb-docs-robot avatar tonyjhillman avatar demetrischr avatar aarongreenlee avatar ayys avatar hamedbrd avatar ingenthr avatar westwooo 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.