func (s *S) TestAutoScaleSetRuleCmdRun(c *check.C) { var called bool transport := cmdtest.ConditionalTransport{ Transport: cmdtest.Transport{Message: "", Status: http.StatusOK}, CondFunc: func(req *http.Request) bool { called = true err := req.ParseForm() c.Assert(err, check.IsNil) var rule autoScaleRule err = form.DecodeValues(&rule, req.Form) c.Assert(err, check.IsNil) c.Assert(rule, check.DeepEquals, autoScaleRule{ MetadataFilter: "pool1", Enabled: true, MaxContainerCount: 10, MaxMemoryRatio: 1.2342, ScaleDownRatio: 1.33, PreventRebalance: false, }) return req.Method == "POST" && req.URL.Path == "/1.0/docker/autoscale/rules" }, } var buf bytes.Buffer context := cmd.Context{Stdout: &buf} var manager cmd.Manager client := cmd.NewClient(&http.Client{Transport: &transport}, nil, &manager) var command autoScaleSetRuleCmd flags := []string{"-f", "pool1", "-c", "10", "-m", "1.2342", "--enable"} err := command.Flags().Parse(true, flags) c.Assert(err, check.IsNil) err = command.Run(&context, client) c.Assert(err, check.IsNil) c.Assert(called, check.Equals, true) c.Assert(buf.String(), check.Equals, "Rule successfully defined.\n") }
// ExtractPullRequest parses post form and creates new instance of PullRequest, // if insecure is false (by default) then ExtractPullRequest will check that // given mirror origin url is really url. func ExtractPullRequest( values url.Values, insecure bool, ) (*PullRequest, error) { var request PullRequest err := form.DecodeValues(&request, values) if err != nil { return nil, err } if request.Spoof { values.Set("branch", values.Get("branch")) values.Set("tag", values.Get("tag")) } err = validateValues(values) if err != nil { return nil, err } if !insecure && !isURL(request.MirrorOrigin) { return nil, errors.New("field 'origin' has an invalid URL") } return &request, err }
func BenchmarkAJGFormTest1(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { ne := new(BenchAJG) if err := form.DecodeValues(ne, valuesAJGFormT1); err != nil { b.Error(err) } } }
func BenchmarkAJGFormTest2(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { ne := new(BenchFormamSchema) if err := form.DecodeValues(ne, valAJGT2); err != nil { b.Error(err) } } }