modulepackage
0.0.0-20230525133920-8678bea4dfd7
Repository: https://github.com/ewilde/go-runscope.git
Documentation: pkg.go.dev
# README
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_ID={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
- Fork it ( https://github.com/ewilde/go-runscope/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Make sure that
make build
passes with test running - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
# Packages
No description provided by the author
# Functions
No description provided by the author
No description provided by the author
No description provided by the author
NewClient creates a new client instance.
NewClientAPI Interface initialization.
NewEnvironment creates a new environment.
NewSchedule creates a new schedule struct.
NewTest creates a new test struct.
NewTestStep creates a new test step struct.
No description provided by the author
# Constants
APIURL is the default runscope api uri.
DefaultPageSize is the max number of items fetched in each request.
# Structs
Account represents Runscope account.
No description provided by the author
Assertion allow you to specify success criteria for a given request, Ghost Inspector, subtest, or condition step.
Bucket resources are a simple way to organize your requests and tests.
Client provides access to create, read, update and delete runscope resources.
Contact details.
EmailSettings determining how test failures trigger notifications.
Environment stores details for shared and test-specific environments.
EnvironmentIntegration represents an integration with a third-party.
Integration represents an integration with a third-party.
ListTestsInput represents the input to ListTests func.
LocalMachine used in an environment to represent a remote agent.
People represents a person belonging to a team.
No description provided by the author
Region represents a Runscope region.
Regions represents multiple Runscope regions.
Request represents the result of a request made by a given test.
No description provided by the author
No description provided by the author
No description provided by the author
Schedule determines how often a test is executed.
Script not sure how this is used, currently not documented, but looks like a javascript string that gets evaluated? See See https://www.runscope.com/docs/api/steps.
Team to which buckets belong to.
Test represents the details for a runscope test.
No description provided by the author
TestRun represents the details of the last time the test ran.
TestStep represents each step that makes up part of the test.
No description provided by the author
Variable allow you to extract data from request, subtest, and Ghost Inspector steps for use in subsequent steps in the test.
# Interfaces
ClientAPI interface for mocking data in unit tests.