harness-drone/handler/api/ccmenu/cc_test.go

147 lines
3.2 KiB
Go
Raw Normal View History

2019-02-19 23:56:41 +00:00
// Copyright 2019 Drone.IO Inc. All rights reserved.
// Use of this source code is governed by the Drone Non-Commercial License
// that can be found in the LICENSE file.
2019-02-28 20:49:04 +00:00
// +build !oss
2019-02-19 23:56:41 +00:00
package ccmenu
import (
"encoding/xml"
"testing"
"github.com/drone/drone/core"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
)
var ignore = cmpopts.IgnoreFields(CCProjects{}, "Project.LastBuildTime")
func TestNew(t *testing.T) {
repo := &core.Repository{
Namespace: "octocat",
Name: "hello-world",
Slug: "octocat/hello-world",
}
build := &core.Build{
Number: 1,
Status: core.StatusRunning,
Started: 1524251054,
}
link := "https://drone.company.com"
want := &CCProjects{
XMLName: xml.Name{},
Project: &CCProject{
XMLName: xml.Name{},
Name: "octocat/hello-world",
Activity: "Building",
LastBuildStatus: "Unknown",
LastBuildLabel: "Unknown",
LastBuildTime: "",
WebURL: "https://drone.company.com",
},
}
got := New(repo, build, link)
if diff := cmp.Diff(got, want); len(diff) > 0 {
t.Errorf(diff)
}
}
func TestNew_Success(t *testing.T) {
repo := &core.Repository{
Namespace: "octocat",
Name: "hello-world",
Slug: "octocat/hello-world",
}
build := &core.Build{
Number: 1,
Status: core.StatusPassing,
Started: 1524251054,
}
link := "https://drone.company.com"
want := &CCProjects{
XMLName: xml.Name{},
Project: &CCProject{
XMLName: xml.Name{},
Name: "octocat/hello-world",
Activity: "Sleeping",
LastBuildStatus: "Success",
LastBuildLabel: "1",
LastBuildTime: "2018-04-20T12:04:14-07:00",
WebURL: "https://drone.company.com",
},
}
got := New(repo, build, link)
if diff := cmp.Diff(got, want, ignore); len(diff) > 0 {
t.Errorf(diff)
}
}
func TestNew_Failure(t *testing.T) {
repo := &core.Repository{
Namespace: "octocat",
Name: "hello-world",
Slug: "octocat/hello-world",
}
build := &core.Build{
Number: 1,
Status: core.StatusFailing,
Started: 1524251054,
}
link := "https://drone.company.com"
want := &CCProjects{
XMLName: xml.Name{},
Project: &CCProject{
XMLName: xml.Name{},
Name: "octocat/hello-world",
Activity: "Sleeping",
LastBuildStatus: "Failure",
LastBuildLabel: "1",
LastBuildTime: "2018-04-20T12:04:14-07:00",
WebURL: "https://drone.company.com",
},
}
got := New(repo, build, link)
if diff := cmp.Diff(got, want, ignore); len(diff) > 0 {
t.Errorf(diff)
}
}
func TestNew_Error(t *testing.T) {
repo := &core.Repository{
Namespace: "octocat",
Name: "hello-world",
Slug: "octocat/hello-world",
}
build := &core.Build{
Number: 1,
Status: core.StatusError,
Started: 1524251054,
}
link := "https://drone.company.com"
want := &CCProjects{
XMLName: xml.Name{},
Project: &CCProject{
XMLName: xml.Name{},
Name: "octocat/hello-world",
Activity: "Sleeping",
LastBuildStatus: "Exception",
LastBuildLabel: "1",
LastBuildTime: "2018-04-20T12:04:14-07:00",
WebURL: "https://drone.company.com",
},
}
got := New(repo, build, link)
if diff := cmp.Diff(got, want, ignore); len(diff) > 0 {
t.Errorf(diff)
}
}