Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1414 from timofurrer/feature/environments-alignment
Browse files Browse the repository at this point in the history
environments: Implement missing `created_at` and `updated_at` fields
  • Loading branch information
svanharmelen authored Mar 16, 2022
2 parents bbf334f + f0f40a3 commit fb5e477
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
3 changes: 3 additions & 0 deletions environments.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package gitlab
import (
"fmt"
"net/http"
"time"
)

// EnvironmentsService handles communication with the environment related methods
Expand All @@ -39,6 +40,8 @@ type Environment struct {
State string `json:"state"`
ExternalURL string `json:"external_url"`
Project *Project `json:"project"`
CreatedAt *time.Time `json:"created_at"`
UpdatedAt *time.Time `json:"updated_at"`
LastDeployment *Deployment `json:"last_deployment"`
}

Expand Down
47 changes: 43 additions & 4 deletions environments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"net/http"
"reflect"
"testing"
"time"

"github.com/stretchr/testify/assert"
)
Expand All @@ -34,15 +35,35 @@ func TestListEnvironments(t *testing.T) {
mux.HandleFunc("/api/v4/projects/1/environments", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
testURL(t, r, "/api/v4/projects/1/environments?name=review%2Ffix-foo&page=1&per_page=10")
fmt.Fprint(w, `[{"id": 1,"name": "review/fix-foo", "slug": "review-fix-foo-dfjre3", "external_url": "https://review-fix-foo-dfjre3.example.gitlab.com"}]`)
fmt.Fprint(w, `[
{
"id": 1,
"name": "review/fix-foo",
"slug": "review-fix-foo-dfjre3",
"external_url": "https://review-fix-foo-dfjre3.example.gitlab.com",
"state": "stopped",
"created_at": "2013-10-02T10:12:29Z",
"updated_at": "2013-12-02T10:12:29Z"
}
]`)
})

envs, _, err := client.Environments.ListEnvironments(1, &ListEnvironmentsOptions{Name: String("review/fix-foo"), ListOptions: ListOptions{Page: 1, PerPage: 10}})
if err != nil {
log.Fatal(err)
}

want := []*Environment{{ID: 1, Name: "review/fix-foo", Slug: "review-fix-foo-dfjre3", ExternalURL: "https://review-fix-foo-dfjre3.example.gitlab.com"}}
createdAtWant, _ := time.Parse(timeLayout, "2013-10-02T10:12:29Z")
updatedAtWant, _ := time.Parse(timeLayout, "2013-12-02T10:12:29Z")
want := []*Environment{{
ID: 1,
Name: "review/fix-foo",
Slug: "review-fix-foo-dfjre3",
ExternalURL: "https://review-fix-foo-dfjre3.example.gitlab.com",
State: "stopped",
CreatedAt: &createdAtWant,
UpdatedAt: &updatedAtWant,
}}
if !reflect.DeepEqual(want, envs) {
t.Errorf("Environments.ListEnvironments returned %+v, want %+v", envs, want)
}
Expand All @@ -54,15 +75,33 @@ func TestGetEnvironment(t *testing.T) {

mux.HandleFunc("/api/v4/projects/1/environments/5949167", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{"id":1,"name":"test/test"}`)
fmt.Fprint(w, `{
"id": 1,
"name": "review/fix-foo",
"slug": "review-fix-foo-dfjre3",
"external_url": "https://review-fix-foo-dfjre3.example.gitlab.com",
"state": "stopped",
"created_at": "2013-10-02T10:12:29Z",
"updated_at": "2013-12-02T10:12:29Z"
}`)
})

env, _, err := client.Environments.GetEnvironment(1, 5949167)
if err != nil {
t.Errorf("Environemtns.GetEnvironment returned error: %v", err)
}

want := &Environment{ID: 1, Name: "test/test"}
createdAtWant, _ := time.Parse(timeLayout, "2013-10-02T10:12:29Z")
updatedAtWant, _ := time.Parse(timeLayout, "2013-12-02T10:12:29Z")
want := &Environment{
ID: 1,
Name: "review/fix-foo",
Slug: "review-fix-foo-dfjre3",
ExternalURL: "https://review-fix-foo-dfjre3.example.gitlab.com",
State: "stopped",
CreatedAt: &createdAtWant,
UpdatedAt: &updatedAtWant,
}
if !reflect.DeepEqual(want, env) {
t.Errorf("Environments.GetEnvironment returned %+v, want %+v", env, want)
}
Expand Down

0 comments on commit fb5e477

Please sign in to comment.