From 2e63fd19ab5639e98179bdb6570042e0e507cf3d Mon Sep 17 00:00:00 2001 From: Dmitri Shuralyov Date: Mon, 10 Dec 2018 19:52:01 -0500 Subject: [PATCH] maintner: update TestLineValue to use new lineValueOK In CL 152779, lineValue was modified to return just the value, lineValueRest was added to do the same task as the old lineValue, and a new lineValueOK with a third bool return value was created. This change fixes a test build failure by adapting TestLineValue to use the new lineValueOK function, and renaming it to TestLineValueOK. Also add two test cases to cover the new bool return value. Updates golang/go#28318 Change-Id: I08106cc14f0c418a880ab139310830943a3a1ad9 Reviewed-on: https://go-review.googlesource.com/c/153441 Reviewed-by: Brad Fitzpatrick --- maintner/gerrit_test.go | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/maintner/gerrit_test.go b/maintner/gerrit_test.go index 35b08ca6..ba227fd0 100644 --- a/maintner/gerrit_test.go +++ b/maintner/gerrit_test.go @@ -243,54 +243,78 @@ func TestSubject(t *testing.T) { } } -func TestLineValue(t *testing.T) { +func TestLineValueOK(t *testing.T) { tests := []struct { all, prefix, want, wantRest string + wantOK bool }{ { all: "foo: value ", prefix: "foo:", want: "value", wantRest: "", + wantOK: true, }, { all: "foo: value\n", prefix: "foo:", want: "value", wantRest: "", + wantOK: true, + }, + { + all: "foo:\n", + prefix: "foo:", + want: "", + wantRest: "", + wantOK: true, + }, + { + all: "bar:\n", + prefix: "foo:", + want: "", + wantRest: "", + wantOK: false, }, { all: "bar: other\nfoo: value\n", prefix: "foo:", want: "value", wantRest: "", + wantOK: true, }, { all: "notfoo: other\nfoo: value\n", prefix: "foo:", want: "value", wantRest: "", + wantOK: true, }, { all: "Foo: bar\nLabel: Vote=+1\nLabel: Vote=+2\n", prefix: "Label: ", want: "Vote=+1", wantRest: "Label: Vote=+2\n", + wantOK: true, }, { all: "Label: Vote=+2\n", prefix: "Label: ", want: "Vote=+2", wantRest: "", + wantOK: true, }, } for _, tt := range tests { - got, gotRest := lineValue(tt.all, tt.prefix) + got, gotRest, gotOK := lineValueOK(tt.all, tt.prefix) if got != tt.want { - t.Errorf("lineValue(%q, %q) returned value %q; want %q", tt.all, tt.prefix, got, tt.want) + t.Errorf("lineValueOK(%q, %q) returned value %q; want %q", tt.all, tt.prefix, got, tt.want) } if gotRest != tt.wantRest { - t.Errorf("lineValue(%q, %q) returned rest %q; want %q", tt.all, tt.prefix, gotRest, tt.wantRest) + t.Errorf("lineValueOK(%q, %q) returned rest %q; want %q", tt.all, tt.prefix, gotRest, tt.wantRest) + } + if gotOK != tt.wantOK { + t.Errorf("lineValueOK(%q, %q) returned ok %v; want %v", tt.all, tt.prefix, gotOK, tt.wantOK) } } }