{"action":"created","comment":{"url":"https://api.github.com/repos/Azure-Samples/azure-sdk-for-go-samples/pulls/comments/172631036","pull_request_review_id":101681545,"id":172631036,"diff_hunk":"@@ -0,0 +1,113 @@\n+// Copyright (c) Microsoft and contributors.  All rights reserved.\n+//\n+// This source code is licensed under the MIT license found in the\n+// LICENSE file in the root directory of this source tree.\n+package batch\n+\n+import (\n+\t\"context\"\n+\t\"fmt\"\n+\t\"log\"\n+\t\"os\"\n+\t\"strings\"\n+\t\"testing\"\n+\n+\t\"github.com/Azure-Samples/azure-sdk-for-go-samples/helpers\"\n+\t\"github.com/Azure-Samples/azure-sdk-for-go-samples/resources\"\n+)\n+\n+var (\n+\tresourceName string\n+\tclientID     string\n+\tclientSecret string\n+\taccountName  string\n+\tjobID        string\n+\tpoolID       string\n+)\n+\n+func TestMain(m *testing.M) {\n+\terr := parseArgs()\n+\tif err != nil {\n+\t\tlog.Fatalln(\"failed to parse args\")\n+\t}\n+\tos.Exit(m.Run())\n+}\n+\n+func parseArgs() error {\n+\terr := helpers.ParseArgs()\n+\tif err != nil {\n+\t\treturn fmt.Errorf(\"cannot parse args: %v\", err)\n+\t}\n+\n+\taccountName = os.Getenv(\"AZ_BATCH_NAME\")\n+\tif !(len(resourceName) > 0) {\n+\t\taccountName = strings.ToLower(\"b\" + helpers.GetRandomLetterSequence(10))\n+\t}\n+\n+\tjobID = strings.ToLower(\"j\" + helpers.GetRandomLetterSequence(10))\n+\tpoolID = strings.ToLower(\"p\" + helpers.GetRandomLetterSequence(10))\n+\n+\tclientID = os.Getenv(\"AZ_CLIENT_ID\")\n+\tclientSecret = os.Getenv(\"AZ_CLIENT_SECRET\")\n+\n+\treturn nil","path":"batch/batch_test.go","position":53,"original_position":53,"commit_id":"08c4b331736864ca88aaa62f810195625b631b8e","original_commit_id":"08c4b331736864ca88aaa62f810195625b631b8e","user":{"login":"mcardosos","id":18688426,"avatar_url":"https://avatars0.githubusercontent.com/u/18688426?v=4","gravatar_id":"","url":"https://api.github.com/users/mcardosos","html_url":"https://github.com/mcardosos","followers_url":"https://api.github.com/users/mcardosos/followers","following_url":"https://api.github.com/users/mcardosos/following{/other_user}","gists_url":"https://api.github.com/users/mcardosos/gists{/gist_id}","starred_url":"https://api.github.com/users/mcardosos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mcardosos/subscriptions","organizations_url":"https://api.github.com/users/mcardosos/orgs","repos_url":"https://api.github.com/users/mcardosos/repos","events_url":"https://api.github.com/users/mcardosos/events{/privacy}","received_events_url":"https://api.github.com/users/mcardosos/received_events","type":"User","site_admin":false},"body":"What are this used for?","created_at":"2018-03-06T19:24:29Z","updated_at":"2018-03-06T19:24:30Z","html_url":"https://github.com/Azure-Samples/azure-sdk-for-go-samples/pull/129#discussion_r172631036","pull_request_url":"https://api.github.com/repos/Azure-Samples/azure-sdk-for-go-samples/pulls/129","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/Azure-Samples/azure-sdk-for-go-samples/pulls/comments/172631036"},"html":{"href":"https://github.com/Azure-Samples/azure-sdk-for-go-samples/pull/129#discussion_r172631036"},"pull_request":{"href":"https://api.github.com/repos/Azure-Samples/azure-sdk-for-go-samples/pulls/129"}}},"pull_request":{"url":"https://api.github.com/repos/Azure-Samples/azure-sdk-for-go-samples/pulls/129","id":172245319,"html_url":"https://github.com/Azure-Samples/azure-sdk-for-go-samples/pull/129","diff_url":"https://github.com/Azure-Samples/azure-sdk-for-go-samples/pull/129.diff","patch_url":"https://github.com/Azure-Samples/azure-sdk-for-go-samples/pull/129.patch","issue_url":"https://api.github.com/repos/Azure-Samples/azure-sdk-for-go-samples/issues/129","number":129,"state":"open","locked":false,"title":"Added simple Azure batch examples","user":{"login":"lawrencegripper","id":1939288,"avatar_url":"https://avatars2.githubusercontent.com/u/1939288?v=4","gravatar_id":"","url":"https://api.github.com/users/lawrencegripper","html_url":"https://github.com/lawrencegripper","followers_url":"https://api.github.com/users/lawrencegripper/followers","following_url":"https://api.github.com/users/lawrencegripper/following{/other_user}","gists_url":"https://api.github.com/users/lawrencegripper/gists{/gist_id}","starred_url":"https://api.github.com/users/lawrencegripper/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lawrencegripper/subscriptions","organizations_url":"https://api.github.com/users/lawrencegripper/orgs","repos_url":"https://api.github.com/users/lawrencegripper/repos","events_url":"https://api.github.com/users/lawrencegripper/events{/privacy}","received_events_url":"https://api.github.com/users/lawrencegripper/received_events","type":"User","site_admin":false},"body":"Hi, \r\n\r\nI'm currently doing some work using Azure Batch from Golang and thought it would be useful to pull it out as an example for others to use as I couldn't find any existing examples to follow. Would really welcome feedback. cc @alfpark \r\n\r\nThis PR creates a simple example of how to create and then interact with an Azure Batch account through the Azure-sdk-for-go. \r\n\r\nTo use the Azure Batch endpoints I've added an additional `GetBatchToken` call which gets a token scoped to azure batch's endpoint. I wasn't sure if this should be added to the `iam` package or directly in the `batch` package. Let me know your thoughts.\r\n\r\nPs. The work includes a workaround for the issue [here](https://github.com/Azure/azure-sdk-for-go/issues/1159) using a request inspector, hopefully this can be removed in the future. \r\n\r\nExample output:\r\n\r\n```\r\n~/go/src/github.com/Azure-Samples/azure-sdk-for-go-samples/batch$ go test \r\n2018/03/01 13:47:09 creating resource group 'azure-samples-go-CreateBatch-QkYkg' on location: westus2\r\n2018/03/01 13:47:39 created batch account\r\n2018/03/01 13:47:40 created batch pool\r\n2018/03/01 13:47:41 created batch job\r\n2018/03/01 13:47:41 created batch task\r\n2018/03/01 13:50:44 output from task:\r\n2018/03/01 13:50:44 Hello world from the Batch Hello world sample!\r\n\r\n2018/03/01 13:50:44 deleting resources\r\nPASS\r\nok  \tgithub.com/Azure-Samples/azure-sdk-for-go-samples/batch\t219.499s\r\n```\r\n","created_at":"2018-03-01T14:04:59Z","updated_at":"2018-03-06T19:24:30Z","closed_at":null,"merged_at":null,"merge_commit_sha":"266cfdc7bb23204814bebad58005a74d2fbe21f7","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/Azure-Samples/azure-sdk-for-go-samples/pulls/129/commits","review_comments_url":"https://api.github.com/repos/Azure-Samples/azure-sdk-for-go-samples/pulls/129/comments","review_comment_url":"https://api.github.com/repos/Azure-Samples/azure-sdk-for-go-samples/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Azure-Samples/azure-sdk-for-go-samples/issues/129/comments","statuses_url":"https://api.github.com/repos/Azure-Samples/azure-sdk-for-go-samples/statuses/08c4b331736864ca88aaa62f810195625b631b8e","head":{"label":"lawrencegripper:lg-batchexample","ref":"lg-batchexample","sha":"08c4b331736864ca88aaa62f810195625b631b8e","user":{"login":"lawrencegripper","id":1939288,"avatar_url":"https://avatars2.githubusercontent.com/u/1939288?v=4","gravatar_id":"","url":"https://api.github.com/users/lawrencegripper","html_url":"https://github.com/lawrencegripper","followers_url":"https://api.github.com/users/lawrencegripper/followers","following_url":"https://api.github.com/users/lawrencegripper/following{/other_user}","gists_url":"https://api.github.com/users/lawrencegripper/gists{/gist_id}","starred_url":"https://api.github.com/users/lawrencegripper/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lawrencegripper/subscriptions","organizations_url":"https://api.github.com/users/lawrencegripper/orgs","repos_url":"https://api.github.com/users/lawrencegripper/repos","events_url":"https://api.github.com/users/lawrencegripper/events{/privacy}","received_events_url":"https://api.github.com/users/lawrencegripper/received_events","type":"User","site_admin":false},"repo":{"id":123427440,"name":"azure-sdk-for-go-samples","full_name":"lawrencegripper/azure-sdk-for-go-samples","owner":{"login":"lawrencegripper","id":1939288,"avatar_url":"https://avatars2.githubusercontent.com/u/1939288?v=4","gravatar_id":"","url":"https://api.github.com/users/lawrencegripper","html_url":"https://github.com/lawrencegripper","followers_url":"https://api.github.com/users/lawrencegripper/followers","following_url":"https://api.github.com/users/lawrencegripper/following{/other_user}","gists_url":"https://api.github.com/users/lawrencegripper/gists{/gist_id}","starred_url":"https://api.github.com/users/lawrencegripper/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lawrencegripper/subscriptions","organizations_url":"https://api.github.com/users/lawrencegripper/orgs","repos_url":"https://api.github.com/users/lawrencegripper/repos","events_url":"https://api.github.com/users/lawrencegripper/events{/privacy}","received_events_url":"https://api.github.com/users/lawrencegripper/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/lawrencegripper/azure-sdk-for-go-samples","description":"Examples of how to utilize Azure services from Go.","fork":true,"url":"https://api.github.com/repos/lawrencegripper/azure-sdk-for-go-samples","forks_url":"https://api.github.com/repos/lawrencegripper/azure-sdk-for-go-samples/forks","keys_url":"https://api.github.com/repos/lawrencegripper/azure-sdk-for-go-samples/keys{/key_id}","collaborators_url":"https://api.github.com/repos/lawrencegripper/azure-sdk-for-go-samples/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/lawrencegripper/azure-sdk-for-go-samples/teams","hooks_url":"https://api.github.com/repos/lawrencegripper/azure-sdk-for-go-samples/hooks","issue_events_url":"https://api.github.com/repos/lawrencegripper/azure-sdk-for-go-samples/issues/events{/number}","events_url":"https://api.github.com/repos/lawrencegripper/azure-sdk-for-go-samples/events","assignees_url":"https://api.github.com/repos/lawrencegripper/azure-sdk-for-go-samples/assignees{/user}","branches_url":"https://api.github.com/repos/lawrencegripper/azure-sdk-for-go-samples/branches{/branch}","tags_url":"https://api.github.com/repos/lawrencegripper/azure-sdk-for-go-samples/tags","blobs_url":"https://api.github.com/repos/lawrencegripper/azure-sdk-for-go-samples/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/lawrencegripper/azure-sdk-for-go-samples/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/lawrencegripper/azure-sdk-for-go-samples/git/refs{/sha}","trees_url":"https://api.github.com/repos/lawrencegripper/azure-sdk-for-go-samples/git/trees{/sha}","statuses_url":"https://api.github.com/repos/lawrencegripper/azure-sdk-for-go-samples/statuses/{sha}","languages_url":"https://api.github.com/repos/lawrencegripper/azure-sdk-for-go-samples/languages","stargazers_url":"https://api.github.com/repos/lawrencegripper/azure-sdk-for-go-samples/stargazers","contributors_url":"https://api.github.com/repos/lawrencegripper/azure-sdk-for-go-samples/contributors","subscribers_url":"https://api.github.com/repos/lawrencegripper/azure-sdk-for-go-samples/subscribers","subscription_url":"https://api.github.com/repos/lawrencegripper/azure-sdk-for-go-samples/subscription","commits_url":"https://api.github.com/repos/lawrencegripper/azure-sdk-for-go-samples/commits{/sha}","git_commits_url":"https://api.github.com/repos/lawrencegripper/azure-sdk-for-go-samples/git/commits{/sha}","comments_url":"https://api.github.com/repos/lawrencegripper/azure-sdk-for-go-samples/comments{/number}","issue_comment_url":"https://api.github.com/repos/lawrencegripper/azure-sdk-for-go-samples/issues/comments{/number}","contents_url":"https://api.github.com/repos/lawrencegripper/azure-sdk-for-go-samples/contents/{+path}","compare_url":"https://api.github.com/repos/lawrencegripper/azure-sdk-for-go-samples/compare/{base}...{head}","merges_url":"https://api.github.com/repos/lawrencegripper/azure-sdk-for-go-samples/merges","archive_url":"https://api.github.com/repos/lawrencegripper/azure-sdk-for-go-samples/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/lawrencegripper/azure-sdk-for-go-samples/downloads","issues_url":"https://api.github.com/repos/lawrencegripper/azure-sdk-for-go-samples/issues{/number}","pulls_url":"https://api.github.com/repos/lawrencegripper/azure-sdk-for-go-samples/pulls{/number}","milestones_url":"https://api.github.com/repos/lawrencegripper/azure-sdk-for-go-samples/milestones{/number}","notifications_url":"https://api.github.com/repos/lawrencegripper/azure-sdk-for-go-samples/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/lawrencegripper/azure-sdk-for-go-samples/labels{/name}","releases_url":"https://api.github.com/repos/lawrencegripper/azure-sdk-for-go-samples/releases{/id}","deployments_url":"https://api.github.com/repos/lawrencegripper/azure-sdk-for-go-samples/deployments","created_at":"2018-03-01T11:42:15Z","updated_at":"2018-03-01T11:42:18Z","pushed_at":"2018-03-06T18:53:21Z","git_url":"git://github.com/lawrencegripper/azure-sdk-for-go-samples.git","ssh_url":"git@github.com:lawrencegripper/azure-sdk-for-go-samples.git","clone_url":"https://github.com/lawrencegripper/azure-sdk-for-go-samples.git","svn_url":"https://github.com/lawrencegripper/azure-sdk-for-go-samples","homepage":null,"size":237,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"Azure-Samples:master","ref":"master","sha":"e747c7c01a5fae8b16a08246cd36b0a0391c0495","user":{"login":"Azure-Samples","id":1844662,"avatar_url":"https://avatars2.githubusercontent.com/u/1844662?v=4","gravatar_id":"","url":"https://api.github.com/users/Azure-Samples","html_url":"https://github.com/Azure-Samples","followers_url":"https://api.github.com/users/Azure-Samples/followers","following_url":"https://api.github.com/users/Azure-Samples/following{/other_user}","gists_url":"https://api.github.com/users/Azure-Samples/gists{/gist_id}","starred_url":"https://api.github.com/users/Azure-Samples/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Azure-Samples/subscriptions","organizations_url":"https://api.github.com/users/Azure-Samples/orgs","repos_url":"https://api.github.com/users/Azure-Samples/repos","events_url":"https://api.github.com/users/Azure-Samples/events{/privacy}","received_events_url":"https://api.github.com/users/Azure-Samples/received_events","type":"Organization","site_admin":false},"repo":{"id":107476070,"name":"azure-sdk-for-go-samples","full_name":"Azure-Samples/azure-sdk-for-go-samples","owner":{"login":"Azure-Samples","id":1844662,"avatar_url":"https://avatars2.githubusercontent.com/u/1844662?v=4","gravatar_id":"","url":"https://api.github.com/users/Azure-Samples","html_url":"https://github.com/Azure-Samples","followers_url":"https://api.github.com/users/Azure-Samples/followers","following_url":"https://api.github.com/users/Azure-Samples/following{/other_user}","gists_url":"https://api.github.com/users/Azure-Samples/gists{/gist_id}","starred_url":"https://api.github.com/users/Azure-Samples/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Azure-Samples/subscriptions","organizations_url":"https://api.github.com/users/Azure-Samples/orgs","repos_url":"https://api.github.com/users/Azure-Samples/repos","events_url":"https://api.github.com/users/Azure-Samples/events{/privacy}","received_events_url":"https://api.github.com/users/Azure-Samples/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Azure-Samples/azure-sdk-for-go-samples","description":"Examples of how to utilize Azure services from Go.","fork":false,"url":"https://api.github.com/repos/Azure-Samples/azure-sdk-for-go-samples","forks_url":"https://api.github.com/repos/Azure-Samples/azure-sdk-for-go-samples/forks","keys_url":"https://api.github.com/repos/Azure-Samples/azure-sdk-for-go-samples/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Azure-Samples/azure-sdk-for-go-samples/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Azure-Samples/azure-sdk-for-go-samples/teams","hooks_url":"https://api.github.com/repos/Azure-Samples/azure-sdk-for-go-samples/hooks","issue_events_url":"https://api.github.com/repos/Azure-Samples/azure-sdk-for-go-samples/issues/events{/number}","events_url":"https://api.github.com/repos/Azure-Samples/azure-sdk-for-go-samples/events","assignees_url":"https://api.github.com/repos/Azure-Samples/azure-sdk-for-go-samples/assignees{/user}","branches_url":"https://api.github.com/repos/Azure-Samples/azure-sdk-for-go-samples/branches{/branch}","tags_url":"https://api.github.com/repos/Azure-Samples/azure-sdk-for-go-samples/tags","blobs_url":"https://api.github.com/repos/Azure-Samples/azure-sdk-for-go-samples/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Azure-Samples/azure-sdk-for-go-samples/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Azure-Samples/azure-sdk-for-go-samples/git/refs{/sha}","trees_url":"https://api.github.com/repos/Azure-Samples/azure-sdk-for-go-samples/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Azure-Samples/azure-sdk-for-go-samples/statuses/{sha}","languages_url":"https://api.github.com/repos/Azure-Samples/azure-sdk-for-go-samples/languages","stargazers_url":"https://api.github.com/repos/Azure-Samples/azure-sdk-for-go-samples/stargazers","contributors_url":"https://api.github.com/repos/Azure-Samples/azure-sdk-for-go-samples/contributors","subscribers_url":"https://api.github.com/repos/Azure-Samples/azure-sdk-for-go-samples/subscribers","subscription_url":"https://api.github.com/repos/Azure-Samples/azure-sdk-for-go-samples/subscription","commits_url":"https://api.github.com/repos/Azure-Samples/azure-sdk-for-go-samples/commits{/sha}","git_commits_url":"https://api.github.com/repos/Azure-Samples/azure-sdk-for-go-samples/git/commits{/sha}","comments_url":"https://api.github.com/repos/Azure-Samples/azure-sdk-for-go-samples/comments{/number}","issue_comment_url":"https://api.github.com/repos/Azure-Samples/azure-sdk-for-go-samples/issues/comments{/number}","contents_url":"https://api.github.com/repos/Azure-Samples/azure-sdk-for-go-samples/contents/{+path}","compare_url":"https://api.github.com/repos/Azure-Samples/azure-sdk-for-go-samples/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Azure-Samples/azure-sdk-for-go-samples/merges","archive_url":"https://api.github.com/repos/Azure-Samples/azure-sdk-for-go-samples/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Azure-Samples/azure-sdk-for-go-samples/downloads","issues_url":"https://api.github.com/repos/Azure-Samples/azure-sdk-for-go-samples/issues{/number}","pulls_url":"https://api.github.com/repos/Azure-Samples/azure-sdk-for-go-samples/pulls{/number}","milestones_url":"https://api.github.com/repos/Azure-Samples/azure-sdk-for-go-samples/milestones{/number}","notifications_url":"https://api.github.com/repos/Azure-Samples/azure-sdk-for-go-samples/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Azure-Samples/azure-sdk-for-go-samples/labels{/name}","releases_url":"https://api.github.com/repos/Azure-Samples/azure-sdk-for-go-samples/releases{/id}","deployments_url":"https://api.github.com/repos/Azure-Samples/azure-sdk-for-go-samples/deployments","created_at":"2017-10-18T23:55:29Z","updated_at":"2018-03-05T21:25:32Z","pushed_at":"2018-03-06T19:09:04Z","git_url":"git://github.com/Azure-Samples/azure-sdk-for-go-samples.git","ssh_url":"git@github.com:Azure-Samples/azure-sdk-for-go-samples.git","clone_url":"https://github.com/Azure-Samples/azure-sdk-for-go-samples.git","svn_url":"https://github.com/Azure-Samples/azure-sdk-for-go-samples","homepage":null,"size":248,"stargazers_count":22,"watchers_count":22,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":15,"mirror_url":null,"archived":false,"open_issues_count":29,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":15,"open_issues":29,"watchers":22,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Azure-Samples/azure-sdk-for-go-samples/pulls/129"},"html":{"href":"https://github.com/Azure-Samples/azure-sdk-for-go-samples/pull/129"},"issue":{"href":"https://api.github.com/repos/Azure-Samples/azure-sdk-for-go-samples/issues/129"},"comments":{"href":"https://api.github.com/repos/Azure-Samples/azure-sdk-for-go-samples/issues/129/comments"},"review_comments":{"href":"https://api.github.com/repos/Azure-Samples/azure-sdk-for-go-samples/pulls/129/comments"},"review_comment":{"href":"https://api.github.com/repos/Azure-Samples/azure-sdk-for-go-samples/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Azure-Samples/azure-sdk-for-go-samples/pulls/129/commits"},"statuses":{"href":"https://api.github.com/repos/Azure-Samples/azure-sdk-for-go-samples/statuses/08c4b331736864ca88aaa62f810195625b631b8e"}},"author_association":"NONE"}}
{"actor":{"display_login":"mcardosos"}}