Skip to content

Commit

Permalink
feat: add basic support of v2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rbretecher committed Dec 3, 2019
1 parent 86eb0bd commit 0bfa15f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
17 changes: 13 additions & 4 deletions collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ import (
"io"
)

const version = "v2.1.0"
type version string

const (
// V210 : v2.1.0
V210 version = "v2.1.0"
// V200 : v2.0.0
V200 version = "v2.0.0"
)

// Info stores data about the collection.
type Info struct {
Expand All @@ -18,19 +25,21 @@ type Info struct {

// Collection represents a Postman Collection.
type Collection struct {
version version
Info Info `json:"info"`
Items []*Items `json:"item"`
Variables []*Variable `json:"variable,omitempty"`
}

// CreateCollection returns a new Collection.
func CreateCollection(name string, desc string) *Collection {
func CreateCollection(name string, desc string, v version) *Collection {
return &Collection{
version: v,
Info: Info{
Name: name,
Version: version,
Version: string(v),
Description: desc,
Schema: fmt.Sprintf("https://schema.getpostman.com/json/collection/%s/", version),
Schema: fmt.Sprintf("https://schema.getpostman.com/json/collection/%s/collection.json", string(v)),
},
}
}
Expand Down
9 changes: 5 additions & 4 deletions collection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ type CollectionTestSuite struct {
}

func (suite *CollectionTestSuite) SetupTest() {
suite.Collection = CreateCollection("a-name", "a-desc")
suite.Collection = CreateCollection("a-name", "a-desc", V210)
suite.BasicCollection = &Collection{
Info: Info{
Name: "Go Collection",
Description: "Awesome description",
Version: "v2.1.0",
Schema: "https://schema.getpostman.com/json/collection/v2.1.0/",
Schema: "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
},
Items: []*Items{
&Items{
Expand Down Expand Up @@ -109,16 +109,17 @@ func TestCollectionTestSuite(t *testing.T) {
}

func TestCreateCollection(t *testing.T) {
c := CreateCollection("a-name", "a-desc")
c := CreateCollection("a-name", "a-desc", V210)

assert.Equal(
t,
&Collection{
version: V210,
Info: Info{
Name: "a-name",
Description: "a-desc",
Version: "v2.1.0",
Schema: "https://schema.getpostman.com/json/collection/v2.1.0/",
Schema: "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
},
},
c,
Expand Down
2 changes: 1 addition & 1 deletion testdata/basic_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "Go Collection",
"description": "Awesome description",
"version": "v2.1.0",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/"
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
Expand Down

0 comments on commit 0bfa15f

Please sign in to comment.