1 Star 0 Fork 0

mamh-mixed/go-jira2

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
metaissue_test.go 28.00 KB
一键复制 编辑 原始数据 按行查看 历史
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078
package jira
import (
"fmt"
"net/http"
"net/url"
"testing"
)
func TestIssueService_GetCreateMeta_Success(t *testing.T) {
setup()
defer teardown()
testAPIEndpoint := "/rest/api/2/issue/createmeta"
testMux.HandleFunc(testAPIEndpoint, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testRequestURL(t, r, testAPIEndpoint)
fmt.Fprint(w, `{
"expand": "projects",
"projects": [{
"expand": "issuetypes",
"self": "https://my.jira.com/rest/api/2/project/11300",
"id": "11300",
"key": "SPN",
"name": "Super Project Name",
"avatarUrls": {
"48x48": "https://my.jira.com/secure/projectavatar?pid=11300&avatarId=14405",
"24x24": "https://my.jira.com/secure/projectavatar?size=small&pid=11300&avatarId=14405",
"16x16": "https://my.jira.com/secure/projectavatar?size=xsmall&pid=11300&avatarId=14405",
"32x32": "https://my.jira.com/secure/projectavatar?size=medium&pid=11300&avatarId=14405"
},
"issuetypes": [{
"self": "https://my.jira.com/rest/api/2/issuetype/6",
"id": "6",
"description": "An issue which ideally should be able to be completed in one step",
"iconUrl": "https://my.jira.com/secure/viewavatar?size=xsmall&avatarId=14006&avatarType=issuetype",
"name": "Request",
"subtask": false,
"expand": "fields",
"fields": {
"summary": {
"required": true,
"schema": {
"type": "string",
"system": "summary"
},
"name": "Summary",
"hasDefaultValue": false,
"operations": [
"set"
]
},
"issuetype": {
"required": true,
"schema": {
"type": "issuetype",
"system": "issuetype"
},
"name": "Issue Type",
"hasDefaultValue": false,
"operations": [
],
"allowedValues": [{
"self": "https://my.jira.com/rest/api/2/issuetype/6",
"id": "6",
"description": "An issue which ideally should be able to be completed in one step",
"iconUrl": "https://my.jira.com/secure/viewavatar?size=xsmall&avatarId=14006&avatarType=issuetype",
"name": "Request",
"subtask": false,
"avatarId": 14006
}]
},
"components": {
"required": true,
"schema": {
"type": "array",
"items": "component",
"system": "components"
},
"name": "Component/s",
"hasDefaultValue": false,
"operations": [
"add",
"set",
"remove"
],
"allowedValues": [{
"self": "https://my.jira.com/rest/api/2/component/14144",
"id": "14144",
"name": "Build automation",
"description": "Jenkins, webhooks, etc."
}, {
"self": "https://my.jira.com/rest/api/2/component/14149",
"id": "14149",
"name": "Caches and noSQL",
"description": "Cassandra, Memcached, Redis, Twemproxy, Xcache"
}, {
"self": "https://my.jira.com/rest/api/2/component/14152",
"id": "14152",
"name": "Cloud services",
"description": "AWS and similar services"
}, {
"self": "https://my.jira.com/rest/api/2/component/14147",
"id": "14147",
"name": "Code quality tools",
"description": "Code sniffer, Sonar"
}, {
"self": "https://my.jira.com/rest/api/2/component/14156",
"id": "14156",
"name": "Configuration management and provisioning",
"description": "Apache/PHP modules, Consul, Salt"
}, {
"self": "https://my.jira.com/rest/api/2/component/13606",
"id": "13606",
"name": "Cronjobs",
"description": "Cronjobs in general"
}, {
"self": "https://my.jira.com/rest/api/2/component/14150",
"id": "14150",
"name": "Data pipelines and queues",
"description": "Kafka, RabbitMq"
}, {
"self": "https://my.jira.com/rest/api/2/component/14159",
"id": "14159",
"name": "Database",
"description": "MySQL related problems"
}, {
"self": "https://my.jira.com/rest/api/2/component/14314",
"id": "14314",
"name": "Documentation"
}, {
"self": "https://my.jira.com/rest/api/2/component/14151",
"id": "14151",
"name": "Git",
"description": "Bitbucket, GitHub, GitLab, Git in general"
}, {
"self": "https://my.jira.com/rest/api/2/component/14155",
"id": "14155",
"name": "HTTP services",
"description": "CDN, HaProxy, HTTP, Varnish"
}, {
"self": "https://my.jira.com/rest/api/2/component/14154",
"id": "14154",
"name": "Job and service scheduling",
"description": "Chronos, Docker, Marathon, Mesos"
}, {
"self": "https://my.jira.com/rest/api/2/component/14158",
"id": "14158",
"name": "Legacy",
"description": "Everything related to legacy"
}, {
"self": "https://my.jira.com/rest/api/2/component/14157",
"id": "14157",
"name": "Monitoring",
"description": "Collectd, Nagios, Monitoring in general"
}, {
"self": "https://my.jira.com/rest/api/2/component/14148",
"id": "14148",
"name": "Other services"
}, {
"self": "https://my.jira.com/rest/api/2/component/13602",
"id": "13602",
"name": "Package management",
"description": "Composer, Medusa, Satis"
}, {
"self": "https://my.jira.com/rest/api/2/component/14145",
"id": "14145",
"name": "Release",
"description": "Directory config, release queries, rewrite rules"
}, {
"self": "https://my.jira.com/rest/api/2/component/14146",
"id": "14146",
"name": "Staging systems and VMs",
"description": "Stage, QA machines, KVMs,Vagrant"
}, {
"self": "https://my.jira.com/rest/api/2/component/14153",
"id": "14153",
"name": "Blog"
}, {
"self": "https://my.jira.com/rest/api/2/component/14143",
"id": "14143",
"name": "Test automation",
"description": "Testing infrastructure in general"
}, {
"self": "https://my.jira.com/rest/api/2/component/14221",
"id": "14221",
"name": "Internal Infrastructure"
}]
},
"attachment": {
"required": false,
"schema": {
"type": "array",
"items": "attachment",
"system": "attachment"
},
"name": "Attachment",
"hasDefaultValue": false,
"operations": [
]
},
"duedate": {
"required": false,
"schema": {
"type": "date",
"system": "duedate"
},
"name": "Due Date",
"hasDefaultValue": false,
"operations": [
"set"
]
},
"description": {
"required": false,
"schema": {
"type": "string",
"system": "description"
},
"name": "Description",
"hasDefaultValue": false,
"operations": [
"set"
]
},
"customfield_10806": {
"required": false,
"schema": {
"type": "any",
"custom": "com.pyxis.greenhopper.jira:gh-epic-link",
"customId": 10806
},
"name": "Epic Link",
"hasDefaultValue": false,
"operations": [
"set"
]
},
"project": {
"required": true,
"schema": {
"type": "project",
"system": "project"
},
"name": "Project",
"hasDefaultValue": false,
"operations": [
"set"
],
"allowedValues": [{
"self": "https://my.jira.com/rest/api/2/project/11300",
"id": "11300",
"key": "SPN",
"name": "Super Project Name",
"avatarUrls": {
"48x48": "https://my.jira.com/secure/projectavatar?pid=11300&avatarId=14405",
"24x24": "https://my.jira.com/secure/projectavatar?size=small&pid=11300&avatarId=14405",
"16x16": "https://my.jira.com/secure/projectavatar?size=xsmall&pid=11300&avatarId=14405",
"32x32": "https://my.jira.com/secure/projectavatar?size=medium&pid=11300&avatarId=14405"
},
"projectCategory": {
"self": "https://my.jira.com/rest/api/2/projectCategory/10100",
"id": "10100",
"description": "",
"name": "Product & Development"
}
}]
},
"assignee": {
"required": true,
"schema": {
"type": "user",
"system": "assignee"
},
"name": "Assignee",
"autoCompleteUrl": "https://my.jira.com/rest/api/latest/user/assignable/search?issueKey=null&username=",
"hasDefaultValue": true,
"operations": [
"set"
]
},
"priority": {
"required": false,
"schema": {
"type": "priority",
"system": "priority"
},
"name": "Priority",
"hasDefaultValue": true,
"operations": [
"set"
],
"allowedValues": [{
"self": "https://my.jira.com/rest/api/2/priority/1",
"iconUrl": "https://my.jira.com/images/icons/priorities/blocker.svg",
"name": "Immediate",
"id": "1"
}, {
"self": "https://my.jira.com/rest/api/2/priority/2",
"iconUrl": "https://my.jira.com/images/icons/priorities/critical.svg",
"name": "Urgent",
"id": "2"
}, {
"self": "https://my.jira.com/rest/api/2/priority/3",
"iconUrl": "https://my.jira.com/images/icons/priorities/major.svg",
"name": "High",
"id": "3"
}, {
"self": "https://my.jira.com/rest/api/2/priority/6",
"iconUrl": "https://my.jira.com/images/icons/priorities/moderate.svg",
"name": "Moderate",
"id": "6"
}, {
"self": "https://my.jira.com/rest/api/2/priority/4",
"iconUrl": "https://my.jira.com/images/icons/priorities/minor.svg",
"name": "Normal",
"id": "4"
}, {
"self": "https://my.jira.com/rest/api/2/priority/5",
"iconUrl": "https://my.jira.com/images/icons/priorities/trivial.svg",
"name": "Low",
"id": "5"
}]
},
"labels": {
"required": false,
"schema": {
"type": "array",
"items": "string",
"system": "labels"
},
"name": "Labels",
"autoCompleteUrl": "https://my.jira.com/rest/api/1.0/labels/suggest?query=",
"hasDefaultValue": false,
"operations": [
"add",
"set",
"remove"
]
}
}
}]
}]
}`)
})
issue, _, err := testClient.Issue.GetCreateMeta("SPN")
if err != nil {
t.Errorf("Expected nil error but got %s", err)
}
if len(issue.Projects) != 1 {
t.Errorf("Expected 1 project, got %d", len(issue.Projects))
}
for _, project := range issue.Projects {
if len(project.IssueTypes) != 1 {
t.Errorf("Expected 1 issueTypes, got %d", len(project.IssueTypes))
}
for _, issueTypes := range project.IssueTypes {
requiredFields := 0
fields := issueTypes.Fields
for _, value := range fields {
for key, value := range value.(map[string]interface{}) {
if key == "required" && value == true {
requiredFields = requiredFields + 1
}
}
}
if requiredFields != 5 {
t.Errorf("Expected 5 required fields from Create Meta information, got %d", requiredFields)
}
}
}
}
func TestIssueService_GetEditMeta_Success(t *testing.T) {
setup()
defer teardown()
testAPIEndpoint := "/rest/api/2/issue/PROJ-9001/editmeta"
testMux.HandleFunc(testAPIEndpoint, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testRequestURL(t, r, testAPIEndpoint)
fmt.Fprint(w, `{
"fields": {
"summary": {
"required": true,
"schema": {
"type": "string",
"system": "summary"
},
"name": "Summary",
"hasDefaultValue": false,
"operations": [
"set"
]
},
"attachment": {
"required": false,
"schema": {
"type": "array",
"items": "attachment",
"system": "attachment"
},
"name": "Attachment",
"hasDefaultValue": false,
"operations": [
]
}
}
}`)
})
editMeta, _, err := testClient.Issue.GetEditMeta(&Issue{Key: "PROJ-9001"})
if err != nil {
t.Errorf("Expected nil error but got %s", err)
}
requiredFields := 0
fields := editMeta.Fields
for _, value := range fields {
for key, value := range value.(map[string]interface{}) {
if key == "required" && value == true {
requiredFields = requiredFields + 1
}
}
}
summary := fields["summary"].(map[string]interface{})
attachment := fields["attachment"].(map[string]interface{})
if summary["required"] != true {
t.Error("Expected summary to be required")
}
if attachment["required"] != false {
t.Error("Expected attachment to not be required")
}
}
func TestIssueService_GetEditMeta_Fail(t *testing.T) {
_, _, err := testClient.Issue.GetEditMeta(&Issue{Key: "PROJ-9001"})
if err == nil {
t.Error("Expected to receive an error, received nil instead")
}
if _, ok := err.(*url.Error); !ok {
t.Errorf("Expected to receive an *url.Error, got %T instead", err)
}
}
func TestMetaIssueType_GetCreateMetaWithOptions(t *testing.T) {
setup()
defer teardown()
testAPIEndpoint := "/rest/api/2/issue/createmeta"
testMux.HandleFunc(testAPIEndpoint, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testRequestURL(t, r, testAPIEndpoint)
fmt.Fprint(w, `{
"expand": "projects",
"projects": [{
"expand": "issuetypes",
"self": "https://my.jira.com/rest/api/2/project/11300",
"id": "11300",
"key": "SPN",
"name": "Super Project Name",
"avatarUrls": {
"48x48": "https://my.jira.com/secure/projectavatar?pid=11300&avatarId=14405",
"24x24": "https://my.jira.com/secure/projectavatar?size=small&pid=11300&avatarId=14405",
"16x16": "https://my.jira.com/secure/projectavatar?size=xsmall&pid=11300&avatarId=14405",
"32x32": "https://my.jira.com/secure/projectavatar?size=medium&pid=11300&avatarId=14405"
},
"issuetypes": [{
"self": "https://my.jira.com/rest/api/2/issuetype/6",
"id": "6",
"description": "An issue which ideally should be able to be completed in one step",
"iconUrl": "https://my.jira.com/secure/viewavatar?size=xsmall&avatarId=14006&avatarType=issuetype",
"name": "Request",
"subtask": false,
"expand": "fields",
"fields": {
"summary": {
"required": true,
"schema": {
"type": "string",
"system": "summary"
},
"name": "Summary",
"hasDefaultValue": false,
"operations": [
"set"
]
},
"issuetype": {
"required": true,
"schema": {
"type": "issuetype",
"system": "issuetype"
},
"name": "Issue Type",
"hasDefaultValue": false,
"operations": [
],
"allowedValues": [{
"self": "https://my.jira.com/rest/api/2/issuetype/6",
"id": "6",
"description": "An issue which ideally should be able to be completed in one step",
"iconUrl": "https://my.jira.com/secure/viewavatar?size=xsmall&avatarId=14006&avatarType=issuetype",
"name": "Request",
"subtask": false,
"avatarId": 14006
}]
},
"components": {
"required": true,
"schema": {
"type": "array",
"items": "component",
"system": "components"
},
"name": "Component/s",
"hasDefaultValue": false,
"operations": [
"add",
"set",
"remove"
],
"allowedValues": [{
"self": "https://my.jira.com/rest/api/2/component/14144",
"id": "14144",
"name": "Build automation",
"description": "Jenkins, webhooks, etc."
}, {
"self": "https://my.jira.com/rest/api/2/component/14149",
"id": "14149",
"name": "Caches and noSQL",
"description": "Cassandra, Memcached, Redis, Twemproxy, Xcache"
}, {
"self": "https://my.jira.com/rest/api/2/component/14152",
"id": "14152",
"name": "Cloud services",
"description": "AWS and similar services"
}, {
"self": "https://my.jira.com/rest/api/2/component/14147",
"id": "14147",
"name": "Code quality tools",
"description": "Code sniffer, Sonar"
}, {
"self": "https://my.jira.com/rest/api/2/component/14156",
"id": "14156",
"name": "Configuration management and provisioning",
"description": "Apache/PHP modules, Consul, Salt"
}, {
"self": "https://my.jira.com/rest/api/2/component/13606",
"id": "13606",
"name": "Cronjobs",
"description": "Cronjobs in general"
}, {
"self": "https://my.jira.com/rest/api/2/component/14150",
"id": "14150",
"name": "Data pipelines and queues",
"description": "Kafka, RabbitMq"
}, {
"self": "https://my.jira.com/rest/api/2/component/14159",
"id": "14159",
"name": "Database",
"description": "MySQL related problems"
}, {
"self": "https://my.jira.com/rest/api/2/component/14314",
"id": "14314",
"name": "Documentation"
}, {
"self": "https://my.jira.com/rest/api/2/component/14151",
"id": "14151",
"name": "Git",
"description": "Bitbucket, GitHub, GitLab, Git in general"
}, {
"self": "https://my.jira.com/rest/api/2/component/14155",
"id": "14155",
"name": "HTTP services",
"description": "CDN, HaProxy, HTTP, Varnish"
}, {
"self": "https://my.jira.com/rest/api/2/component/14154",
"id": "14154",
"name": "Job and service scheduling",
"description": "Chronos, Docker, Marathon, Mesos"
}, {
"self": "https://my.jira.com/rest/api/2/component/14158",
"id": "14158",
"name": "Legacy",
"description": "Everything related to legacy"
}, {
"self": "https://my.jira.com/rest/api/2/component/14157",
"id": "14157",
"name": "Monitoring",
"description": "Collectd, Nagios, Monitoring in general"
}, {
"self": "https://my.jira.com/rest/api/2/component/14148",
"id": "14148",
"name": "Other services"
}, {
"self": "https://my.jira.com/rest/api/2/component/13602",
"id": "13602",
"name": "Package management",
"description": "Composer, Medusa, Satis"
}, {
"self": "https://my.jira.com/rest/api/2/component/14145",
"id": "14145",
"name": "Release",
"description": "Directory config, release queries, rewrite rules"
}, {
"self": "https://my.jira.com/rest/api/2/component/14146",
"id": "14146",
"name": "Staging systems and VMs",
"description": "Stage, QA machines, KVMs,Vagrant"
}, {
"self": "https://my.jira.com/rest/api/2/component/14153",
"id": "14153",
"name": "Blog"
}, {
"self": "https://my.jira.com/rest/api/2/component/14143",
"id": "14143",
"name": "Test automation",
"description": "Testing infrastructure in general"
}, {
"self": "https://my.jira.com/rest/api/2/component/14221",
"id": "14221",
"name": "Internal Infrastructure"
}]
},
"attachment": {
"required": false,
"schema": {
"type": "array",
"items": "attachment",
"system": "attachment"
},
"name": "Attachment",
"hasDefaultValue": false,
"operations": [
]
},
"duedate": {
"required": false,
"schema": {
"type": "date",
"system": "duedate"
},
"name": "Due Date",
"hasDefaultValue": false,
"operations": [
"set"
]
},
"description": {
"required": false,
"schema": {
"type": "string",
"system": "description"
},
"name": "Description",
"hasDefaultValue": false,
"operations": [
"set"
]
},
"customfield_10806": {
"required": false,
"schema": {
"type": "any",
"custom": "com.pyxis.greenhopper.jira:gh-epic-link",
"customId": 10806
},
"name": "Epic Link",
"hasDefaultValue": false,
"operations": [
"set"
]
},
"project": {
"required": true,
"schema": {
"type": "project",
"system": "project"
},
"name": "Project",
"hasDefaultValue": false,
"operations": [
"set"
],
"allowedValues": [{
"self": "https://my.jira.com/rest/api/2/project/11300",
"id": "11300",
"key": "SPN",
"name": "Super Project Name",
"avatarUrls": {
"48x48": "https://my.jira.com/secure/projectavatar?pid=11300&avatarId=14405",
"24x24": "https://my.jira.com/secure/projectavatar?size=small&pid=11300&avatarId=14405",
"16x16": "https://my.jira.com/secure/projectavatar?size=xsmall&pid=11300&avatarId=14405",
"32x32": "https://my.jira.com/secure/projectavatar?size=medium&pid=11300&avatarId=14405"
},
"projectCategory": {
"self": "https://my.jira.com/rest/api/2/projectCategory/10100",
"id": "10100",
"description": "",
"name": "Product & Development"
}
}]
},
"assignee": {
"required": true,
"schema": {
"type": "user",
"system": "assignee"
},
"name": "Assignee",
"autoCompleteUrl": "https://my.jira.com/rest/api/latest/user/assignable/search?issueKey=null&username=",
"hasDefaultValue": true,
"operations": [
"set"
]
},
"priority": {
"required": false,
"schema": {
"type": "priority",
"system": "priority"
},
"name": "Priority",
"hasDefaultValue": true,
"operations": [
"set"
],
"allowedValues": [{
"self": "https://my.jira.com/rest/api/2/priority/1",
"iconUrl": "https://my.jira.com/images/icons/priorities/blocker.svg",
"name": "Immediate",
"id": "1"
}, {
"self": "https://my.jira.com/rest/api/2/priority/2",
"iconUrl": "https://my.jira.com/images/icons/priorities/critical.svg",
"name": "Urgent",
"id": "2"
}, {
"self": "https://my.jira.com/rest/api/2/priority/3",
"iconUrl": "https://my.jira.com/images/icons/priorities/major.svg",
"name": "High",
"id": "3"
}, {
"self": "https://my.jira.com/rest/api/2/priority/6",
"iconUrl": "https://my.jira.com/images/icons/priorities/moderate.svg",
"name": "Moderate",
"id": "6"
}, {
"self": "https://my.jira.com/rest/api/2/priority/4",
"iconUrl": "https://my.jira.com/images/icons/priorities/minor.svg",
"name": "Normal",
"id": "4"
}, {
"self": "https://my.jira.com/rest/api/2/priority/5",
"iconUrl": "https://my.jira.com/images/icons/priorities/trivial.svg",
"name": "Low",
"id": "5"
}]
},
"labels": {
"required": false,
"schema": {
"type": "array",
"items": "string",
"system": "labels"
},
"name": "Labels",
"autoCompleteUrl": "https://my.jira.com/rest/api/1.0/labels/suggest?query=",
"hasDefaultValue": false,
"operations": [
"add",
"set",
"remove"
]
}
}
}]
}]
}`)
})
issue, _, err := testClient.Issue.GetCreateMetaWithOptions(&GetQueryOptions{Expand: "projects.issuetypes.fields"})
if err != nil {
t.Errorf("Expected nil error but got %s", err)
}
if len(issue.Projects) != 1 {
t.Errorf("Expected 1 project, got %d", len(issue.Projects))
}
for _, project := range issue.Projects {
if len(project.IssueTypes) != 1 {
t.Errorf("Expected 1 issueTypes, got %d", len(project.IssueTypes))
}
for _, issueTypes := range project.IssueTypes {
requiredFields := 0
fields := issueTypes.Fields
for _, value := range fields {
for key, value := range value.(map[string]interface{}) {
if key == "required" && value == true {
requiredFields = requiredFields + 1
}
}
}
if requiredFields != 5 {
t.Errorf("Expected 5 required fields from Create Meta information, got %d", requiredFields)
}
}
}
}
func TestMetaIssueType_GetMandatoryFields(t *testing.T) {
data := make(map[string]interface{})
data["summary"] = map[string]interface{}{
"required": true,
"name": "Summary",
}
data["components"] = map[string]interface{}{
"required": true,
"name": "Components",
}
data["epicLink"] = map[string]interface{}{
"required": false,
"name": "Epic Link",
}
m := new(MetaIssueType)
m.Fields = data
mandatory, err := m.GetMandatoryFields()
if err != nil {
t.Errorf("Expected nil error, received %s", err)
}
if len(mandatory) != 2 {
t.Errorf("Expected 2 received %+v", mandatory)
}
}
func TestMetaIssueType_GetMandatoryFields_NonExistentRequiredKey_Fail(t *testing.T) {
data := make(map[string]interface{})
data["summary"] = map[string]interface{}{
"name": "Summary",
}
m := new(MetaIssueType)
m.Fields = data
_, err := m.GetMandatoryFields()
if err == nil {
t.Error("Expected non nil errpr, received nil")
}
}
func TestMetaIssueType_GetMandatoryFields_NonExistentNameKey_Fail(t *testing.T) {
data := make(map[string]interface{})
data["summary"] = map[string]interface{}{
"required": true,
}
m := new(MetaIssueType)
m.Fields = data
_, err := m.GetMandatoryFields()
if err == nil {
t.Error("Expected non nil errpr, received nil")
}
}
func TestMetaIssueType_GetAllFields(t *testing.T) {
data := make(map[string]interface{})
data["summary"] = map[string]interface{}{
"required": true,
"name": "Summary",
}
data["components"] = map[string]interface{}{
"required": true,
"name": "Components",
}
data["epicLink"] = map[string]interface{}{
"required": false,
"name": "Epic Link",
}
m := new(MetaIssueType)
m.Fields = data
mandatory, err := m.GetAllFields()
if err != nil {
t.Errorf("Expected nil err, received %s", err)
}
if len(mandatory) != 3 {
t.Errorf("Expected 3 received %+v", mandatory)
}
}
func TestMetaIssueType_GetAllFields_NonExistingNameKey_Fail(t *testing.T) {
data := make(map[string]interface{})
data["summary"] = map[string]interface{}{
"required": true,
}
m := new(MetaIssueType)
m.Fields = data
_, err := m.GetAllFields()
if err == nil {
t.Error("Expected non nil error, received nil")
}
}
func TestMetaIssueType_CheckCompleteAndAvailable_MandatoryMissing(t *testing.T) {
data := make(map[string]interface{})
data["summary"] = map[string]interface{}{
"required": true,
"name": "Summary",
}
data["someKey"] = map[string]interface{}{
"required": false,
"name": "SomeKey",
}
config := map[string]string{
"SomeKey": "somevalue",
}
m := new(MetaIssueType)
m.Fields = data
ok, err := m.CheckCompleteAndAvailable(config)
if err == nil {
t.Error("Expected non nil error. Received nil")
}
if ok != false {
t.Error("Expected false, got true")
}
}
func TestMetaIssueType_CheckCompleteAndAvailable_NotAvailable(t *testing.T) {
data := make(map[string]interface{})
data["summary"] = map[string]interface{}{
"required": true,
"name": "Summary",
}
config := map[string]string{
"Summary": "Issue Summary",
"SomeKey": "somevalue",
}
m := new(MetaIssueType)
m.Fields = data
ok, err := m.CheckCompleteAndAvailable(config)
if err == nil {
t.Error("Expected non nil error. Received nil")
}
if ok != false {
t.Error("Expected false, got true")
}
}
func TestMetaIssueType_CheckCompleteAndAvailable_Success(t *testing.T) {
data := make(map[string]interface{})
data["summary"] = map[string]interface{}{
"required": true,
"name": "Summary",
}
data["someKey"] = map[string]interface{}{
"required": false,
"name": "SomeKey",
}
config := map[string]string{
"SomeKey": "somevalue",
"Summary": "Issue summary",
}
m := new(MetaIssueType)
m.Fields = data
ok, err := m.CheckCompleteAndAvailable(config)
if err != nil {
t.Errorf("Expected nil error. Received %s", err)
}
if ok != true {
t.Error("Expected true, got false")
}
}
func TestCreateMetaInfo_GetProjectWithName_Success(t *testing.T) {
metainfo := new(CreateMetaInfo)
metainfo.Projects = append(metainfo.Projects, &MetaProject{
Name: "SPN",
})
project := metainfo.GetProjectWithName("SPN")
if project == nil {
t.Errorf("Expected non nil value, received nil")
}
}
func TestMetaProject_GetIssueTypeWithName_CaseMismatch_Success(t *testing.T) {
m := new(MetaProject)
m.IssueTypes = append(m.IssueTypes, &MetaIssueType{
Name: "Bug",
})
issuetype := m.GetIssueTypeWithName("BUG")
if issuetype == nil {
t.Errorf("Expected non nil value, received nil")
}
}
func TestCreateMetaInfo_GetProjectWithKey_Success(t *testing.T) {
metainfo := new(CreateMetaInfo)
metainfo.Projects = append(metainfo.Projects, &MetaProject{
Key: "SPNKEY",
})
project := metainfo.GetProjectWithKey("SPNKEY")
if project == nil {
t.Errorf("Expected non nil value, received nil")
}
}
func TestCreateMetaInfo_GetProjectWithKey_NilForNonExistent(t *testing.T) {
metainfo := new(CreateMetaInfo)
metainfo.Projects = append(metainfo.Projects, &MetaProject{
Key: "SPNKEY",
})
project := metainfo.GetProjectWithKey("SPN")
if project != nil {
t.Errorf("Expected nil, received value")
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mamh-mixed/go-jira2.git
git@gitee.com:mamh-mixed/go-jira2.git
mamh-mixed
go-jira2
go-jira2
master

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385