From c5a98b0c3a9a74e53e8929ca3d62c81bf7ea40b4 Mon Sep 17 00:00:00 2001 From: Will Norris Date: Thu, 22 Aug 2013 14:03:17 -0700 Subject: [PATCH] add tests for String() funcs on data types --- github/strings_test.go | 48 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/github/strings_test.go b/github/strings_test.go index ffeee28..262fe0c 100644 --- a/github/strings_test.go +++ b/github/strings_test.go @@ -6,6 +6,7 @@ package github import ( + "fmt" "testing" "time" ) @@ -77,3 +78,50 @@ func TestStringify(t *testing.T) { } } } + +// Directly test the String() methods on various GitHub types. We don't do an +// exaustive test of all the various field types, since TestStringify() above +// takes care of that. Rather, we just make sure that Stringify() is being +// used to build the strings, which we do by verifying that pointers are +// stringified as their underlying value. +func TestString(t *testing.T) { + var tests = []struct { + in interface{} + out string + }{ + {Event{ID: String("1")}, `github.Event{ID:"1"}`}, + {PushEvent{PushID: Int(1)}, `github.PushEvent{PushID:1}`}, + {PushEventCommit{SHA: String("s")}, `github.PushEventCommit{SHA:"s"}`}, + {Gist{ID: String("1")}, `github.Gist{ID:"1", Files:map[]}`}, + {GistFile{Size: Int(1)}, `github.GistFile{Size:1}`}, + {GistComment{ID: Int(1)}, `github.GistComment{ID:1}`}, + {Commit{SHA: String("s")}, `github.Commit{SHA:"s"}`}, + {CommitAuthor{Name: String("n")}, `github.CommitAuthor{Name:"n"}`}, + {Tree{SHA: String("s")}, `github.Tree{SHA:"s"}`}, + {TreeEntry{SHA: String("s")}, `github.TreeEntry{SHA:"s"}`}, + {Issue{Number: Int(1)}, `github.Issue{Number:1}`}, + {IssueComment{ID: Int(1)}, `github.IssueComment{ID:1}`}, + {Label{Name: String("l")}, "l"}, + {Organization{ID: Int(1)}, `github.Organization{ID:1}`}, + {Team{ID: Int(1)}, `github.Team{ID:1}`}, + {PullRequest{Number: Int(1)}, `github.PullRequest{Number:1}`}, + {PullRequestComment{ID: Int(1)}, `github.PullRequestComment{ID:1}`}, + {Repository{ID: Int(1)}, `github.Repository{ID:1}`}, + {RepositoryComment{ID: Int(1)}, `github.RepositoryComment{ID:1}`}, + {WebHookPayload{Ref: String("r")}, `github.WebHookPayload{Ref:"r"}`}, + {WebHookCommit{ID: String("1")}, `github.WebHookCommit{ID:"1"}`}, + {WebHookAuthor{Name: String("n")}, `github.WebHookAuthor{Name:"n"}`}, + {Hook{ID: Int(1)}, `github.Hook{Config:map[], ID:1}`}, + {RepoStatus{ID: Int(1)}, `github.RepoStatus{ID:1}`}, + {CodeResult{Name: String("n")}, `github.CodeResult{Name:"n"}`}, + {User{ID: Int(1)}, `github.User{ID:1}`}, + {Key{ID: Int(1)}, `github.Key{ID:1}`}, + } + + for i, tt := range tests { + s := tt.in.(fmt.Stringer).String() + if s != tt.out { + t.Errorf("%d. String() => %q, want %q", i, tt.in, tt.out) + } + } +}