Code Monkey home page Code Monkey logo

go-runscope's Introduction

Build Status

go-runscope

go-runscope is a go client library for the runscope api

Installation

go get github.com/ewilde/go-runscope

Usage

package main

import (
    "fmt"
    "github.com/ewilde/go-runscope"
)

func createBucket() {
    var accessToken = "{your token}"  // See https://www.runscope.com/applications
    var teamUUID = "{your team uuid}" // See https://www.runscope.com/teams
    var client = runscope.NewClient(runscope.APIURL, accessToken)
    var bucket = &runscope.Bucket{
        Name: "My first bucket",
        Team: &runscope.Team{
            ID: teamUUID,
        },
    }

    bucket, err := client.CreateBucket(bucket)
    if err != nil {
        log.Printf("[ERROR] error creating bucket: %s", err)
    }
}

All Resources and Actions

Complete examples can be found in the examples folder or in the unit tests

Bucket

Client.CreateBucket(bucket *Bucket) (*Bucket, error)
...
    var bucket = &runscope.Bucket{
        Name: "My first bucket",
        Team: &runscope.Team{
            ID: teamUUID,
        },
    }
	bucket, err := client.CreateBucket(&{Bucket{Name: "test", Team}})
Client.ReadBucket(key string) (*Bucket, error)
...
    bucket, err := client.ReadBucket("htqee6p4dhvc")
    if err != nil {
        log.Printf("[ERROR] error creating bucket: %s", err)
    }

    fmt.Printf("Bucket read successfully: %s", bucket.String())
Client.DeleteBucket(key string)
...
    err := client.DeleteBucket("htqee6p4dhvc")
    if err != nil {
        log.Printf("[ERROR] error creating bucket: %s", err)
    }

Environment

Client.CreateSharedEnvironment(environment *Environment, bucket *Bucket) (*Environment, error)
...
environment := &runscope.Environment{
		Name: "tf_environment",
		InitialVariables: map[string]string{
			"VarA" : "ValB",
			"VarB" : "ValB",
		},
		Integrations: []*runscope.Integration {
			{
				ID:              "27e48b0d-ba8e-4fe0-bcaa-dd9de08dc47d",
				IntegrationType: "pagerduty",
			},
			{
				ID:              "574f4560-0f50-41da-a2f7-bdce419ad378",
				IntegrationType: "slack",
			},
		},
	}

environment, err := client.CreateSharedEnvironment(environment, createBucket())
if err != nil {
    log.Printf("[ERROR] error creating environment: %s", err)
}
Client.ReadSharedEnvironment(environment *Environment, bucket *Bucket) (*Environment, error)

Client.ReadTestEnvironment(environment *Environment, test *Test) (*Environment, error)

Client.UpdateSharedEnvironment(environment *Environment, bucket *Bucket) (*Environment, error)

Client.UpdateTestEnvironment(environment *Environment, test *Test) (*Environment, error)

Test

Client.CreateTest(test *Test) (*Test, error) (*Environment, error)
...
    test := &Test{ Name: "tf_test", Description: "This is a tf new test", Bucket: bucket }
	test, err = client.CreateTest(newTest)
	defer client.DeleteTest(newTest)

	if err != nil {
		t.Error(err)
	}

Client.ReadTest(test *Test) (*Test, error)

Client.UpdateTest(test *Test) (*Test, error)

Client.DeleteTest(test *Test) error

Test step

Client.CreateTestStep(testStep *TestStep, bucketKey string, testID string) (*TestStep, error)
...
    step := NewTestStep()
    step.StepType = "request"
    step.URL = "http://example.com"
    step.Method = "GET"
    step.Assertions = [] Assertion {{
        Source: "response_status",
        Comparison : "equal_number",
        Value: 200,
    }}

    step, err = client.CreateTestStep(step, bucket.Key, test.ID)
    if err != nil {
        t.Error(err)
    }

Client.ReadTestStep(testStep *TestStep, bucketKey string, testID string) (*TestStep, error)

Client.UpdateTestStep(testStep *TestStep, bucketKey string, testID string) (*TestStep, error)

Client.DeleteTestStep(testStep *TestStep, bucketKey string, testID string) error

Schedule

Client.CreateSchedule(schedule *Schedule, bucketKey string, testID string) (*Schedule, error)
...
    schedule := NewSchedule()
    schedule.Note = "Daily schedule"
    schedule.Interval = "1d"
    schedule.EnvironmentID = environment.ID

    schedule, err = client.CreateSchedule(schedule, bucket.Key, test.ID)
    if err != nil {
        t.Error(err)
    }

Client.ReadSchedule(schedule *Schedule, bucketKey string, testID string) (*Schedule, error)

Client.UpdateSchedule(schedule *Schedule, bucketKey string, testID string) (*Schedule, error)

Client.DeleteSchedule(schedule *Schedule, bucketKey string, testID string) error

Unit Testing

You can now mock client data:

type MockClient struct {
}

func (client *MockClient) ListBuckets() ([]*runscope.Bucket, error) {
 	bucket1 := &runscope.Bucket{}
 	bucket2 := &runscope.Bucket{}
 	bucket1.Name = "MyBucket"
 	bucket2.Name = "MyNonExistingBucket"
 	return []*runscope.Bucket{bucket1, bucket2}, nil
 }

Then you can use this mockClient in your Unit Test:

func TestReadBucket(t *testing.T) {
	t.Run("Successful return bucket", func(t *testing.T) {
		client := &resources.MockClient{}
		getBucket := ReadBucket("MyBucket", client)

		if getBucket == nil {
			t.Error("Should have returned a bucket")
		}
	})
}

Developing

Running the tests

By default the tests requiring access to the runscope api (most of them) will be skipped. To run the integration tests please set the following environment variables.

Note: you will need at least one integration setup on your account, i.e. slack

RUNSCOPE_ACC=true
RUNSCOPE_ACCESS_TOKEN={your access token}
RUNSCOPE_TEAM_UUID={your team uuid}

Access tokens can be created using the applications section of your runscope account.

Your team url can be found by taking the uuid from https://www.runscope.com/teams

Contributing

  1. Fork it ( https://github.com/ewilde/go-runscope/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Make sure that make build passes with test running
  4. Commit your changes (git commit -am 'Add some feature')
  5. Push to the branch (git push origin my-new-feature)
  6. Create a new Pull Request

go-runscope's People

Contributors

ewilde avatar kevholditch avatar pagnmickie avatar philwhiteuk avatar

Watchers

James Cloos 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.